Hi,
there are many ways to solve this problem..
ok, let me explain one way for this..
1. Take an array of structures, lets say of size for example 10...
structure should consists of two fields a. "year" to which the student belongs to
b. "marks" he got..
2. Now print a message,
saying "do you want to add one more record -- y/n".
keep in a while loop, such that, every time the loop goes, you give 'y' or 'n'
if the read character is "y", then continue the loop, else come out of the loop.
each time the loop goes, maintain a loop varible that increments one by one.
each time after you read the option, if the option is "y",
print " enter the year to which student belongs to "
scan it in a variable year,
and assign array_of_structs[loop_variable].year=year;
immediately print "the marks he scored"
read and assign it to array_of_structs[loop_variable].marks=marks.
3. you will come out of this loop once you give option "n".
4. now, go though the whole array -- for each array variable,
check the conditions...
for(i=0; i<loop_var; i++)
{
if(array_of_structs==1)
{
no_of_students_1++;
marks_year_1=marks_year_1+array_of_structs.marks.
}
like the same for four years............
}
5. make sure that, the varibles no_of_students_1,2,3,4 are set to zero before enter the for loop and the same for marks_year_1,2,3,4 also set to zero..
6. after coming out of the loop,
no_of_students_1 gives the no of students in the first year.
marks_year_1 gives the total marks of first year.
like for 2,3,4, also...
7. do division -- avg_year_1 = marks_year_1 / no_of_students_1..
same for 2,3,4, also...
8. print the averages..
9. for better utilization of the array, go for dynamic allocation using malloc() if you know it, by which you can allocate the array size dynamically..
10. i think, it is useful to u, if not reply me, i will write the c code, and will send it to you...
bye