Make a mark sheet of a student who is enrolled in five subjects. Marks of each subject should be defined by the user. The Output should contain the percentage obtained in each subject, Total marks obtained, Total Marks and percentage attained by the student.
/*
C program mark sheet for student enrolled for 5 subjects
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//Constant for the number of subjects
#define ARRAY_LENGTH 5
int main(int argc, char *argv[]) {
//Initialize array pointer variables to hold the mark scored in each subject and
//Total expected score on the subject e.g if the student scored all the points in a
//60 total score exam then he/she would enter 60 for mark and 60 for the total expected score
int *mark = (int*) malloc (sizeof(int) * ARRAY_LENGTH);
int *total = (int*) malloc (sizeof(int) * ARRAY_LENGTH);
//Use array to loop to ask the user for the marks for the five subjects
for(int i = 0; i < ARRAY_LENGTH; i++)
{
printf("Enter mark for subject %d:", i+1);
scanf("%d", &mark[i]);
printf("Enter total expected score e.g 100 for x/100 %d :", i + 1);
scanf("%d", &total[i]);
}
Loop through the array and display score sheet with mark, total expected score and the percentage score
//Percentage score is type cast to double and displayed in two decimal places.
for (int i = 0; i <= ARRAY_LENGTH; i++)
{
//Calculate percentage of the mark
printf("Subject %d score is %d / %d and percent score is %.2f %\n", i+1, mark[i], total[i], (double)mark[i]/(double)total[i] * 100);
}
return(0);
}
Comments
Leave a comment