Sunday, May 12, 2019

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
  • 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
  • Program
  • #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;
    }

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...