Computer Science, asked by kingrahul23, 8 months ago

write a program to store 1st 25 prime number in an erray and display it ​

Answers

Answered by akanksha2614
5

Explanation:

#include<stdio.h>

int main()

{

int a[10],n,i,j,c=0,prime[10],t=0;

printf("/*How Many Numbers You Want\nTo Add in Array*/\n\nEnter Limit : ");

scanf("%d",&n);

printf("\nEnter %d Numbers in Array:\n\n",n);

for(i=0;i<n;i++)

scanf("%d",&a[i]);

for(i=0;i<n;i++)

{

c=0;

for(j=2;j<a[i];j++)

{

if(a[i]%j==0)

{

c=1;

break;

}

}

if(c==0)

{

prime[t]=a[i];

t++;

}

}

printf("\nPrime Numbers in Above Array:\n\n");

for(i=0;i<t;i++)

{

printf(" %d ",prime[i]);

}

return 0;

}

Answered by prajeevan
1

Explanation:

Store prime numbers in array & display - C

Home > C Programs > C Array programs

« Previous

Next »

Programs

C Array Programs

Find max & min array elements

Count frequency of each element

Decimal into Octal conversion

Armstrong number in an array

Separate out +ve, -ve and 0s

Reverse the array elements

Sum of 10 integers

Compare sum of given elements

Sum of even numbers in array

Print odd numbers in array

Find sum and average

Print max & min array element

Search a number in an array

Sort array in ascending order

Count occurrences of numbers

Store & display prime number

Sort array in descending order

Reverse an array

Print largest sum

Print two dimensional array

Count zeroes in a matrix

Sum of two matrices

Sum of all elements in matrix

Sum of diagonal elements

Find transpose of matrix

Sum of middle row & column

Find product of matrices

Find difference of two matrices

Sum of lower triangular elements

Sum of upper triangular elements

Write a C program to accept 'n' numbers and store all prime numbers in an array and display.

Solution:

#include<stdio.h>

int main()

{

     int a[10],n,i,j,c=0,prime[10],t=0;

     printf("/*How Many Numbers You Want\nTo Add in Array*/\n\nEnter Limit : ");

     scanf("%d",&n);

     printf("\nEnter %d Numbers in Array:\n\n",n);

     for(i=0;i<n;i++)

          scanf("%d",&a[i]);

     for(i=0;i<n;i++)

     {

          c=0;

          for(j=2;j<a[i];j++)

          {

               if(a[i]%j==0)

               {

                    c=1;

                    break;

               }

          }

          if(c==0)

          {

               prime[t]=a[i];

               t++;

          }

     }

     printf("\nPrime Numbers in Above Array:\n\n");

     for(i=0;i<t;i++)

     {

          printf(" %d ",prime[i]);

     }

     return 0;

}

Similar questions