##### Nested for loops in C programming

 Computer Science Tutor: None Selected Time limit: 1 Day

printf("\nEnter the Math score: ");

scanf("%d",&stud[i].mscore);

printf("\nEnter the English Score: ");

scanf("%d",&stud[i].escore);

stud[i].avg =(stud[i].mscore+stud[i].escore)/2;

}

}

void top (void){

int a=1;

for(i=0;i<n-1;i++)

{

for(j=i+1;j<n;j++)

{

if(stud[i].avg<stud[j].avg)

{

t=stud[i]; ***********

stud[i]=stud[j];  *********

stud[j]=t; *********

}

Can somebody please explain what is happening in the lines with the asterick? Let me know if you need the entire program

Dec 4th, 2015

First the programe tries  to evaluate whether  t is average by first checking whether is equal to what is stored in array  stud i and if it is equal it goes further and evaluate whether array stud i is equal to array stud j

Thus  t results is equal to arry stud j and thus  they  have been able to know t is average

Dec 4th, 2015

Why is it that it had to do:

T=stud[i] and stud [i] = stud[j]

Couldn't it have just gone to stud[j] = t assuming that the if statement is true?

Dec 4th, 2015

...
Dec 4th, 2015
...
Dec 4th, 2015
Dec 3rd, 2016
check_circle