C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf

#include int main(){ int n, sum=0; printf("Enter any number to find it is prime or not \n"); scanf("%d", &n); printf("Following are the prime numbers between 1 to n \n"); for(int i=1; i<n; i++){ int c=0; for(int j=2; j<i; j++){ if(i%j==0){ c++; break; }

} if(c==0 && i!=1){ sum=sum+i; printf("%d \n", i); } } printf("Sum of prime numbers between 1 and n is %d", sum); }

## 10 comments:

Nice Qusation...But I not minded.......

Print all the prime numbers which are below the given number separated by comma

used very much tq......

is this type of algorithm consider as series of prime numbers

Print all the Armstrong number upto n

Why is there num/2 ?

Don't add break; after count++....then it is running properly

It worked thanks

How can I find also their total Sum of Prime numbers between 1 to n?

#include

int main(){

int n, sum=0;

printf("Enter any number to find it is prime or not \n");

scanf("%d", &n);

printf("Following are the prime numbers between 1 to n \n");

for(int i=1; i<n; i++){

int c=0;

for(int j=2; j<i; j++){

if(i%j==0){

c++;

break;

}

}

if(c==0 && i!=1){

sum=sum+i;

printf("%d \n", i);

}

}

printf("Sum of prime numbers between 1 and n is %d", sum);

}

Post a Comment