Print sum of prime numbers | C-program
Sum of Prime Number:
Tips:
1.Use nested loop.
2.Don't forget to give block(" { } ");
2.Don't forget to give block(" { } ");
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int p,i,j,y=0;
printf("Enter the range:\n");
scanf("%d",&p);
for(i=1;i<=p;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
break;
}
if(i==j)
{
y=y+i;
printf("%d\t",i);
}
}
printf("\nThe sum is : %d",y);
getch();
}
Output:
Please comment for feedback!
Comments
Post a Comment
Give your feedback!
DO NOT SPAM !!
NO THIRD PARTY PROMOTIONAL LINK !!!! (else comment will be deleted.)