Labels

Thursday, December 17, 2015

Array of Prime number;

A C program to print array of prime numbers;

#include <stdio.h>
int main()
{
int n;
int arr[100];
printf("Enter the value of n: ");
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
if(i%2==0)
{
for(int j=0;j=i;j++)
{
arr[j]=i;
printf("Array: %d \n",arr[j]);
break;
}
}
}
return 0;
}

Array of prime numbers
Array of Prime numbers

To compile this program in Linux:
  1. Save this file with extension .c
  2. g++ compiler come pre installed in linux. Type this in terminal g++ array.c -o array. Here, I have assumed that the file name is array.c. -o array will provide me with an output file with extension exe file and name array.
  3. Now, run this file typing ./array and press enter.
To compile this program using cmd:
  1. Save this file with extension.c
  2. Type this in the cmd g++ array.c -o array.
  3. To run type array and press enter.
Note: To use g++ compiler in windows user has to install these compiler by itself as g++ compiler does not come per installed in windows operating system.


No comments:

Post a Comment