POINTERS-9

Description:

Write a program to input 10 values in an array. Categorize each value as prime or composite using pointers. Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Test Case 1 Input (stdin) 10 3 4 5 6 7 8 9 10 11 12 Expected Output 3 is a prime number 4 is a composite number 5 is a prime number 6 is a composite number 7 is a prime number 8 is a composite number 9 is a composite number 10 is a composite number 11 is a prime number 12 is a composite number Test Case 2 Input (stdin) 0 Expected Output 0

Program :

#include <stdio.h>

int isprime(int x)

{

  int i,f=1;

  for(i=2;i<x;i++)

    if(x%i==0)

      f=0;

  return f;

}

int main()

{

  int n;

  scanf("%d",&n);

  int i,a[n];

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

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

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

  {

    if(isprime(a[i]))

       printf("%d is a prime number\n",a[i]);

    else

       printf("%d is a composite number\n",a[i]);

  }

 


return 0;

}