Monday, August 20, 2018

STUDENT DIRECTORY

  • Problem Description

    Write a program to create a directory of students with roll numbers.The program
    should display the roll number for a specified name and vice-versa

    Refer Sample Input and Output:
    1. The total number of inputs from the user
    2. The user should get the input of registration number and name for the number of inputs in Step 1
    3. The third input corresponds to the registration number
  • CODING ARENA::
  • #include <stdio.h>
    int main()
    {
      int n;
      scanf("%d",&n);
      int i,a[n];
      char b[n][100];
      for(i=0;i<n;i++)
      {
        scanf("%d%s",&a[i],b[i]);
      }
      int k;
      scanf("%d",&k);
      for(i=0;i<n;i++)
      {
        if(a[i]==k)
        {k=i;break;}
      }
      printf("Name=%s\nregno=%d",b[k],a[k]);

    return 0;
    }
  • Test Case 1

    Input (stdin)
    5
    
    101 Rajesh
    
    102 Suresh
    
    103 Mahesh
    
    104 Sharma
    
    105 Rohit
    
    102
    
    
    Expected Output
    Name=Suresh
    
    regno=102
  • Test Case 2

    Input (stdin)
    3
    
    101 Rajesh
    
    102 Suresh
    
    103 Mahesh
    
    103
    
    
    Expected Output
    Name=Mahesh
    
    regno=103

No comments:

Post a Comment