100% JNTUK SET 4:9b arrays vs structure getting same output

#include <stdio.h>
void main()
{
    int i, roll_no[2];
    float mean[2];
    /*roll_no & mean are 2 arrays in which data of 2 students is stored.
    As we declare 2 arrays ..one for roll nos and other for mean values,
    the relation among them is not apparent in arrays. the problem is
    overcome by using structures*/
   
    struct student
    {
      int rno;
      float avg;
    }s[2];  // s[0].rno and s[1].rno contains rollnumbers of 2 students whose averages are s[1].avg and s[1].avg
   
    //   data entry into arrays begin
    printf("\n Enter the two roll nos:");
    scanf("%d%d",&roll_no[0],&roll_no[1]);
    printf("\n Enter the mean values of the two candidates in exam:");
    scanf("%f%f",&mean[0],&mean[1]);
   
    //   data entry into struct variable begins
    for(i=0;i<2;i++)
    {
        printf("\n Enter the rno & avg:");
        scanf("%d%f",&s[i].rno,&s[i].avg);
    }
   
    //printing back data from arrays begin
     printf("\n roll_no:%d and mean=%f", roll_no[0],mean[0]);
     printf("\n roll_no:%d and mean=%f", roll_no[1],mean[1]);
     
    //printing back data from struture begins
    for(i=0;i<2;i++)
    {
      printf("\n rno:%d and mean=%f", s[i].rno,s[i].avg);
    }
}


 Enter the two roll nos:506 579

 Enter the mean values of the two candidates in exam:69 71

 Enter the rno & avg:506 69

 Enter the rno & avg:579 71

 roll_no:506 and mean=69.000000
 roll_no:579 and mean=71.000000
 rno:506 and mean=69.000000
 rno:579 and mean=71.000000

కామెంట్‌లు

ఈ బ్లాగ్ నుండి ప్రసిద్ధ పోస్ట్‌లు

100% C prog to write content into a file and then read it back onto the console

Spic macay

శ్రీరస్తు.. రామలింగ 18-1-24 (సూరసాని వారి ఆహ్వానము)