Wednesday 6 February 2013

Write a c program to accept n numbers & store all prime numbers in an array & display this result



#include<stdio.h>
#include<conio.h>
  void main()
{
  int a[10],i,n;
  clrscr();
  printf("\nEnter the n number: ");
  scanf("%d",&n);
  printf("\nEnter the numbers: ");
  for(i=0;i<=n;i++)
{
  scanf("%d",&a[i]);
}
  printf("\nThe Prime Number is: ");
  for(i=1;i<=n;i++)
{
  if(a[i]%2==1)
{
  printf("\t%d",a[i]);
}
}
  getch();
}

//OUTPUT:
//Enter the n number: 4

//Enter the numbers: 1
//2
//3
//4
//5

//The Prime Number is: 3 5

2 comments: