Friday, May 3, 2019

Pointer - 7

  • Problem Description

    Write a program to input 10 values in an array. Categorize each value as positive ,negative or equal to zero using pointer.

    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 3 4 1 -5 6 7 8 9 10

    Expected Output
    3=Positive

    3=Positive

    4=Positive

    1=Positive

    -5=Negative

    6=Positive

    7=Positive

    8=Positive

    9=Positive

    10=Positive
  • Test Case 2

    Input (stdin)
    10

    1 -1 2 -2 -3 3 4 -4 0 0

    Expected Output
    1=Positive

    -1=Negative

    2=Positive

    -2=Negative

    -3=Negative

    3=Positive

    4=Positive

    -4=Negative

    0=Zero

    0=Zero
Solution

#include<stdio.h>

int main()
{
      int array[30], count, limit;
      scanf("%d", &limit);
      for(count = 0; count < limit; count++)
      {
            scanf("%d", &array[count]);
      }
      
      for(count = 0; count < limit; count++)
      {
      }
      for(count = 0; count < limit; count++)
      {
            if(array[count] < 0)
            {
                  printf("%d=Negative\n", array[count]);
            }
            else if(array[count] > 0)
            {
                  printf("%d=Positive\n", array[count]);
            }
            else
            {
                  printf("%d=Zero\n", array[count]);
            }
      }
      return 0;
}

No comments:

Post a Comment

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...