Dr. A.P.J. Abdul Kalam Technical University, Lucknow
KCS101 / KCS201 Programming for Problem Solving - Using C Language
Lab Exercises
1. Write a program that accepts the marks of 5 subjects and finds the sum and percentage of marks obtained by the students.
/*
File: Prgrm01.c
Author: Aditya Saini
Date: Sept 05, 2019
Description: Program to find the sum and percentage of 5 subjects marks input by keyboard.
*/
#include <stdio.h>
int main (void)
{
int subject_1, subject_2, subject_3, subject_4, subject_5;
int sum;
float percentage;
//Input 5 subjects marks.
printf ("Input first subject marks: ");
scanf ("%d", &subject_1);
int sum;
float percentage;
//Input 5 subjects marks.
printf ("Input first subject marks: ");
scanf ("%d", &subject_1);
printf ("Input second subject marks: ");
scanf ("%d", &subject_2);
scanf ("%d", &subject_2);
printf ("Input third subject marks: ");
scanf ("%d", &subject_3);
scanf ("%d", &subject_3);
printf ("Input forth subject marks: ");
scanf ("%d", &subject_4);
scanf ("%d", &subject_4);
printf ("Input fifth subject marks: ");
scanf ("%d", &subject_5);
//Calculate the sum and percentage.
sum = subject_1 + subject_2 + subject_3 + subject_4 + subject_5;
percentage = sum / 5.0;
//Output the result.
printf ("Total marks: %d\n", sum);
printf ("Percentage: %.2f %", percentage);
scanf ("%d", &subject_5);
//Calculate the sum and percentage.
sum = subject_1 + subject_2 + subject_3 + subject_4 + subject_5;
percentage = sum / 5.0;
//Output the result.
printf ("Total marks: %d\n", sum);
printf ("Percentage: %.2f %", percentage);
};
Output
Input first subject marks: 82
Input second subject marks: 79
Input third subject marks: 84
Input forth subject marks: 93
Input fifth subject marks: 88
Total marks: 426
Percentage: 85.20 %
Input second subject marks: 79
Input third subject marks: 84
Input forth subject marks: 93
Input fifth subject marks: 88
Total marks: 426
Percentage: 85.20 %
No comments:
Post a Comment
Please do not post spam links.