Nested for loops in C programming

label Computer Science
account_circle Unassigned
schedule 1 Day
account_balance_wallet $5

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

Thank you for the opportunity to help you with your question!

Thank you for the opportunity to help you with your question!

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 

Please let me know if you need any clarification. I'm always happy to answer your questions.Please let me know if you need any clarification. I'm always happy to answer your questions.
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

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
Dec 4th, 2015
...
Dec 4th, 2015
Jun 23rd, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer