Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 5 June 2016

PROBLEM 14:

Write a C Program to print all first N elements of prime 

numbers series.

For N = 4, output is 2, 3, 5, 7


For N = 6, output is 2, 3, 5, 7, 11, 13

code:


#include<stdio.h>
main()
{
int i=2;
int f=0;
int a=7;
int b=0;
int n=0,j=1;
printf("enter no:");
scanf("%d",&n);
do{
if(b%i==0)
{
f=1;
}
else{
f=0;
}
if(f==0 && j<=n)
{
j++;
if(b==9)
{
if(b%i!=0)
{
f=1;
}
}
else{
printf("%d ",b);
}
}
b++;
}while(b<100);
return 0;
}

Program Output:









For more problems click here

No comments:

Post a Comment