Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define NUM_STUDENTS 25
- #define NUM_TESTS 10
- int get_highest(int a[][NUM_TESTS], int row, int col);
- int *p;
- union {
- int u_i;
- }var;
- /* Define a type point to be a struct with integer members hi, fa */
- typedef struct {
- int hi;
- int fa;
- } score;
- int factorial(int f);
- typedef enum
- { Poor,
- Average,
- Good
- } myenum;
- int main()
- {
- char* test[]={"Poor","Average", "Good"};
- int grades[NUM_STUDENTS][NUM_TESTS] = { {5, 6, 4},
- {8, 9, 7} };
- int num_students = 2;
- int num_tests = 3;
- int high_test;
- int grade;
- score student; //define a variable student of type score
- p = &var.u_i; /* initialise pointer */
- high_test = get_highest( grades, num_students, num_tests);
- *p = factorial(high_test); //use the pointer to change the value of highest_test
- //store variables inside the structure
- student.hi=high_test;
- student.fa=var.u_i;
- myenum value=Average;
- char tmp[0]={0x0};
- printf("The highest score is %d.\n", student.hi);
- printf("This has a factorial of %d.\n",student.fa);
- if(student.hi>0 && student.hi<=4) {grade=0;}
- else if(student.hi>4 && student.hi<=6) {grade=1;}
- else {grade=2;}
- strcpy(tmp,test[grade]); //grade score of student here
- printf("Final Grading is %s.\n",tmp);
- return 0;
- }
- int get_highest(int a[][NUM_TESTS], int row, int col)
- /* Assumes that there is at least one element */
- {
- int i, j;
- int highest = a[0][0];
- for( i = 0; i < row; i++)
- for( j = 0; j < col; j++)
- if ( a[i][j] > highest)
- highest = a[i][j];
- return highest;
- }
- int factorial(int number)
- {
- if (number < 0)
- {
- printf("\nError - negative argument to factorial\n");
- exit(1);
- }
- else if (number == 0)
- return 1;
- else
- return (number * factorial(number - 1));
- }
Advertisement
Add Comment
Please, Sign In to add comment