Sunday, July 26, 2009

Write a Program in "C "to find sum of Prime Numbers?

Computer Programming of C / C++.

Write a Program in "C "to find sum of Prime Numbers?
#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;





void main()


{


int n,i,j,sum=0;


clrscr();





printf("Enter number: ");


scanf("%d",%26amp;n);





for(i=2;i%26lt;=n;i++)


{


for(j=2;j%26lt;i;j++)


{


if(i%j==0)


break;


else


continue;


}


if(j==i)


sum = sum + i;


}





printf("\n\nThe sum of prime numbers upto %d is %d",n,sum);





getch();


}
Reply:pretty simple thing to do but I don't know why you would do as such but here basic example :


#include %26lt;conio.h%26gt;


#include%26lt;studio.h%26gt;


#include%26lt;math.h%26gt;





int main (void)


{


float a,b,c,d;


Cout%26lt;%26lt;"Please enter Number to summed into Prime Number";


Cinn%26gt;%26gt;a;


}


return 0;


Dang it I forgot the formula....but you get the picture...


No comments:

Post a Comment