Untitled

 avatar
unknown
plain_text
4 years ago
2.1 kB
11
Indexable
#include <stdio.h>

#define MAXCRS 3
#define MAXCAMPUS 2

/*function declaration*/
void ders_kayitStudents(int arr[MAXCRS][MAXCAMPUS][4]);
void displayNoStudentsInEachCourse(const int arr[MAXCRS][MAXCAMPUS][4]);
void displayNoStudentsInEachCampus(const int arr[MAXCRS][MAXCAMPUS][4]);

int main()
{
int ders_kayit[MAXCRS][MAXCAMPUS][4];
ders_kayitStudents(ders_kayit);
displayNoStudentsInEachCourse(ders_kayit);
displayNoStudentsInEachCampus(ders_kayit);

return 0;
}

/* function to load the array*/
void ders_kayitStudents(int arr[MAXCRS][MAXCAMPUS][4])
{
int i,j,k;
/*there will be three for loops to iterate through course, campus and years*/
for(i=0;i<MAXCRS;i++)
{
printf("Processing course number %d:\n",i);
for(j=0; j<MAXCAMPUS; j++)
{
printf(" Campus %d:\n",j);
for(k=0;k<4;k++)
{
switch(k){
case 0: printf(" Enter number of Freshman >");break;
case 1: printf(" Enter number of Sophomores >");break;
case 2: printf(" Enter number of Juniors >");break;
case 3: printf(" Enter number of Seniors >");break;
}
scanf("%d",&arr[i][j][k]);/*read number ofd students*/
}
}
}
}

/*function to get and display total student in each course*/
void displayNoStudentsInEachCourse(const int arr[MAXCRS][MAXCAMPUS][4])
{
int courseIndex,campusIndex,yearIndex,totalStudent;
for(courseIndex=0;courseIndex<MAXCRS;courseIndex++)
{
totalStudent = 0;
for(campusIndex=0; campusIndex<MAXCAMPUS; campusIndex++)
{
for(yearIndex=0;yearIndex<4;yearIndex++)
{
totalStudent += arr[courseIndex][campusIndex][yearIndex];
}
}
printf("\nNumber of students in course %d is %d",courseIndex,totalStudent);
}
}

/*function to get and display total student in each campus*/
void displayNoStudentsInEachCampus(const int arr[MAXCRS][MAXCAMPUS][4])
{
int campusIndex,courseIndex,yearIndex,totalStudent;
for(campusIndex=0;campusIndex<MAXCAMPUS;campusIndex++)
{
totalStudent = 0;
for(courseIndex=0; courseIndex<MAXCRS; courseIndex++)
{
for(yearIndex=0;yearIndex<4;yearIndex++)
{
totalStudent += arr[courseIndex][campusIndex][yearIndex];
}
}
printf("\nNumber of students in campus %d is %d",campusIndex,totalStudent);
}
}
Editor is loading...