Write C Program to find sum of all prime numbers between 1 to n -99webcode

Write C Program to find sum of all prime numbers between 1 to n -99webcode

Print prime number between  to n number using c programming and find sum of all prime number between n number in c programming




#include <stdio.h>

int main()

{

int n ,i ,j , sum;

printf("enter a number");

scanf("%d",&n);

for(i=2;i<=n;i++)

{

for(j=2;j<=n;j++)

{

if(i%j==0)

break;

}

if(i==j)

{

printf("%d ",i); 

sum=sum+i;

}   

}

 printf("\n sum is prime no between %d is  %d",n,sum);

}


output

enter a number 25

2 3 5 7 11 13 17 19 23                                                                                                                                                                       

sum of prime no between 25 is  100









      

Post a Comment (0)
Previous Post Next Post