What is going to be the output of the following program incl

What is going to be the output of the following program: #include int main(void){int a = 0, b = 0; struct department{int did; int gst; int ugst;}; struct university{int state_rank; char name[10]; struct department ndpt[3];}NDSU; NDSU = {1, {\'N\', \'D\', \'S\', \'U\'}, {1, 10, 200, 2, 20, 300, 3, 30, 400}}; for(int i = 0; i

Solution

There is an error in the program. NDSU is a data type(user defined), and therefore cannot be initialized.

But after a minute modifications, the output is explained in the comments part:

#include <stdio.h>
int main(void)
{
int a = 0, b = 0;
struct department       //Declares a structure department.
{
int did;
int gst;
int ugst;
};
struct university       //Declares a structure university.
{
int state_rank;
char name[10];
struct department ndpt[3];
}NDSU = {1, {\'N\', \'D\', \'S\', \'U\'}, {1, 10, 200, 2, 20, 300, 3, 30, 400}};   //Initializes the university structure.
//State_rank = 1.
//name = \"NDSU\".
//With 3 departments.
//Department 1: did = 1, gst = 10, ugst = 200.
//Department 2: did = 2, gst = 20, ugst = 300.
//Department 3: did = 3, gst = 30, ugst = 400.
for(int i = 0; i < 3; i++)   //For each department value.
{  
a = a + NDSU.ndpt[i].gst;   //Sum up the gst values to a.   10 + 20 + 30
b = a + NDSU.ndpt[i].ugst;    //Sum of a and ugst value is overwritten to b.   First time its, 10 + 200. Second time its, 30 + 300. Finally its 60 + 400 = 460 is stored.
}
printf(\"%d and %d\ \", a/3, b/3);   //Prints the average gst, and ugst values: 20, and 153.
return 0;
}

 What is going to be the output of the following program: #include int main(void){int a = 0, b = 0; struct department{int did; int gst; int ugst;}; struct unive

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site