Computer Science, asked by Sudhalatwal9418, 1 month ago

Write a program in c to accept 10 numbers and find prime numbers among these numbers

Answers

Answered by anindyaadhikari13
3

\texttt{\textsf{\large{\underline{Solution}:}}}

The given program is written in C.

#include <stdio.h>

int main() {

   int n=10,i,j;

   int arr[n];

   printf("Enter 10 numbers.\n");

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

       printf("> ");

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

   }

   printf("Prime numbes are as follows -\n");

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

       int c=0;

       for(j=1;j<=arr[i];j++){

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

               c++;

       }

       if(c==2)

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

   }

   return 0;

}

\texttt{\textsf{\large{\underline{Logic}:}}}

  • Accept the numbers and store them in array.
  • Transverse through array elements. If the number is prime display it or else display none.

See the attachment for output.

Attachments:
Similar questions