Thursday, September 13, 2018

POINTERS -9

  • Problem 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.
  • CODING ARENA
  • #include <stdio.h>
    int prco(int n)
    {
      int i,c=0;
      //scanf("%d",&n);
        for(i=1;i<=n;i++)
      {
         if(n%i==0)
          c=c+1;
      }
      if(c==2)
        printf("%d is a prime number\n",n);
      else
        printf("%d is a composite number\n",n);
      return 0;
    }
    int main()
    {
      int n; scanf("%d",&n);
      int a[n];
      int i;
      for(i=0;i<n;i++)
      {
        scanf("%d",&a[i]);
        prco(a[i]);
      }
      return 0;
    }
        
        
        
  • 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

No comments:

Post a Comment