Print sum of prime numbers | C-program

Sum of Prime Number:

Tips:

1.Use nested loop.
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

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :