Filled Under: ,

C Program to Print Prime Numbers upto a given Number

C Program to Print Prime Numbers upto a given Number

C Program to Print Prime Numbers upto a given Number

 In this program, I have discussed about the C program to print prime numbers upto a given number or range.


#include<stdio.h>
int main()
{ int a,i,j,b,sum;
printf("Enter a number:");
scanf("%d",&a);
for(i=2;i<=a;i++)
{
sum=0;
b=i/2;
for(j=2;j<=b;j++)
{
if(i%j==0)
{
sum++;
}
}
if(sum==0)
printf("%d ",i);
}
}

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.

0 comments:

Post a Comment

 

Copyright 2020 Programming in C All Right Reserved