Digital जीवन

Free Online Education for India...

Full width home advertisement

Computer Basic

C Programming

Engineering Graphics

Post Page Advertisement [Top]

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);
               printf ("Input second subject marks: ");
               scanf ("%d", &subject_2);
               printf ("Input third subject marks: ");
               scanf ("%d", &subject_3);
               printf ("Input forth subject marks: ");
               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);

               return 0;
};

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 %



No comments:

Post a Comment

Please do not post spam links.

Bottom Ad [Post Page]

| Designed by Colorlib