Write a c program to accept n numbers from user & store all prime numbers in an array and display the array

#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],i=0,j=0;
int n,f=0;
clrscr();
printf("\n enter the limit =");
scanf("%d",&n);
printf("\n enter the elements \n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
f=0;
if(a[i]<=0)
break;
else
{
for(j=2;j<=a[i]/2;j++)
{
if(a[i]%j==0)
{
f=1;break;
}
}
if(f==0)
printf("prime number=%d",a[i]);
}
}
getch();
}

Comments

  1. sir, i am a b.sc physics student. i am doing a dual major course with computer science. i am not expert in c program. so i have one doubt in c program. will you please help to write the following program.
    write a program to read n integers and store them into a file.

    ReplyDelete

Post a Comment