Sunday, August 19, 2018

POINTERS-5

  • Problem Description

    Write a program to find Largest of three integer values 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.

    Mandatory:

    Use pointers concepts
  • CODING ARENA::
  • #include <stdio.h>
    int main()
    {
      int a[100],i,j,n,t,*b;
     
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
        scanf("%d",&a[i]);
        b=&a[i];
      }
      for(i=0;i<n;i++)
      {
        for(j=i+1;j<n;j++)
        {
          if(a[i]>a[j])
          {
            t=a[i];
            a[i]=a[j];
            a[j]=t;
          }
        }
      }
      b=&a[n-1];
      printf("%d is largest",*b);

            
      

    return 0;
    }
  • Test Case 1

    Input (stdin)
    3
    
    4 3 1
    
    
    Expected Output
    4 is largest
  • Test Case 2

    Input (stdin)
    3
    
    723 4444 123
    
    
    Expected Output
    4444 is largest

No comments:

Post a Comment