- C Programming Examples
- C Programming Examples
- C Print Hello World
- C Get Input from User
- C Print Integer
- C Add Two Numbers
- C Check Even or Odd
- C Check Prime or Not
- C Check Alphabet or Not
- C Check Vowel or Not
- C Check Leap Year or Not
- C Check Reverse equal Original
- C Add Subtract Multiply Divide
- C Make Calculator
- C Add Digits of Number
- C Calculate Average, Percentage
- C Calculate Arithmetic Mean
- C Calculate Student Grade
- C Print Table of Number
- C Print Prime Numbers
- C Add n Numbers
- C Interchange Numbers
- C Reverse a Number
- C Swap Two Numbers
- C Count Positive Negative Zero
- C Find Largest of Two Numbers
- C Find Largest of Three Numbers
- C Find Factorial of Number
- C Find LCM & HCF
- C Find LCM of n Numbers
- C Find HCF of n Numbers
- C Area & Perimeter of Square
- C Area & Perimeter of Rectangle
- C Area & Circumference of Circle
- C Convert Fahrenheit to Celsius
- C Convert Celsius to Fahrenheit
- C Print ASCII Value
- C Print Fibonacci Series
- C Check Palindrome or Not
- C Check Armstrong or Not
- C Generate Armstrong Numbers
- C Find nCr and nPr
- C Convert Decimal to Binary
- C Convert Decimal to Octal
- C Convert Decimal to Hexadecimal
- C Convert Binary to Decimal
- C Convert Binary to Octal
- C Convert Binary to Hexadecimal
- C Convert Octal to Decimal
- C Convert Octal to Binary
- C Convert Octal to Hexadecimal
- C Convert Hexadecimal to Decimal
- C Convert Hexadecimal to Binary
- C Convert Hexadecimal to Octal
- C Pattern Printing Programs
- C Print Diamond Pattern
- C Print Floyd's Triangle
- C Print Pascal's Triangle
- C Print Smiling face
- C 1D Array Programs
- C Linear Search
- C Binary Search
- C Add Two Numbers using Pointer
- C Find Largest Element in Array
- C Find Smallest Element in Array
- C Reverse an Array
- C Insert Element in Array
- C Delete Element from Array
- C Merge Two Arrays
- C Bubble Sort
- C Selection Sort
- C Insertion Sort
- C 2D Array Programs
- C Add Two Matrices
- C Subtract Two Matrices
- C Transpose a Matrix
- C Multiply Two Matrices
- C 3D Array Programs
- C Print String
- C Find Length of String
- C Compare Two String
- C Copy a String
- C Concatenate String
- C Reverse a String
- C Delete Vowels from String
- C Delete Word from String
- C Find Frequency of Character
- C Count Word in String
- C Remove Spaces from String
- C Sort a String
- C Uppercase to Lowercase
- C Lowercase to Uppercase
- C Swap Two Strings
- C Check Anagram or Not
- C Generate Random Numbers
- C Read a File
- C Write Content to File
- C Read & Display File
- C Copy a File
- C Merge Two Files
- C List Files in Directory
- C Delete a File
- C Encrypt & Decrypt a File
- C Print Date
- C Get IP Address
- C Shutdown Computer
- C More Programs
- C Check Palindrome String
- C Inches to Centimetres
- C Kilogram to Gram
- C Count Even Odd
- C Count Vowels Consonants
- C Find Profit Loss
- C Sum All Matrix Elements
- C First & Last Digit Sum
- C Largest Element in Matrix
- C Pass Array to Function
- C Address of Variable
- C Array Element at Even
- C Array Element at Odd
- C Print Even Array Elements
- C Print Odd Array Elements
- C Reverse File
- C Print Message with Time
- C Print Number in Words
- C Print Successive Character
- C Sum of their Square
- C Replace Vowel in String
- C Sort Words in Ascending
- C Sort Words in Descending
- C Sort String in Alphabetical
- C Programming Tutorial
- C Tutorial
- C Programming Library
- C Standard Library
- C Programming Test
- C Programming Test
- Give Online Test
- All Test List

In this article, you will learn and get code about how to create a program that finds average and percentage marks. The last program given here is the complete version of finding average and percentage marks of a student. In that program, number of subject and maximum marks is also decided by user.

The question is, **write a program in C, that asks from user to enter marks obtained in 5 subjects and prints average
mark as output**. So the answer to this question is given below:

// Find Average Marks of Students in C // ------codescracker.com------- #include<stdio.h> #include<conio.h> int main() { int i; float mark, sum=0, avg; printf("Enter Marks obtained in 5 Subjects: "); for(i=0; i<5; i++) { scanf("%f", &mark); sum = sum+mark; } avg = sum/5; printf("\nAverage Mark = %0.2f", avg); getch(); return 0; }

This program was compiled and executed in **Code::Blocks** IDE. This is the first snapshot of sample run:

Now supply marks obtained in 5 subjects as input say **76, 87, 98, 70, 82** and press **ENTER** key to see the
average mark of student as shown in the second snapshot of sample run given below:

Here are some of the main steps used in above program:

- Declare a variable say
**i**of**int**type to work with it in loop - Declare another three variables say
**mark, sum**, and**avg**of type**float** - Here these three variables are declared as float, because to hold any value that contains decimal
- Initialize 0 to the variable
**sum**in declaration part - Now here we have applied a
**for**loop that runs 5 times - In each run, program scans mark value and adds it to
**sum**variable - So after exiting from the loop, we have a
**sum**variable that holds sum of all the 5 marks entered by user at run-time - Just divide
**sum**with 5, to find average mark of given 5 numbers - Print the value of
**avg**as output. That it

To learn about **loop** (used in previous program) in detail, refer to for loop in C
tutorial. Let's move on to next program.

The question is, **write a program in C, that asks from user to enter marks obtained in 5 subjects (out of 100)
and find the percentage marks of student**. The answer to this question is given below:

To calculate percentage marks of a student in C programming, you have to ask from user to enter marks obtained in some
number of subjects (5 subjects here, i.e Physics, Chemistry, Maths, CS, and English). Place summation of 5 marks in a variable
say **sum** and place **sum/5** in a variable say **avg**. Simply print **avg** as the result on output.

// Find Percentage Marks of Students in C // ------codescracker.com------- #include<stdio.h> #include<conio.h> int main() { int i; float mark, sum=0, perc; printf("Enter Marks obtained in 5 Subjects (Out of 100): "); for(i=0; i<5; i++) { scanf("%f", &mark); sum = sum+mark; } perc = (sum/500)*100; printf("\nPercentage Mark = %0.2f%c", perc, 37); getch(); return 0; }

This program will produce the output as shown in the snapshot given below:

Most of the code written in this program is almost same as of previous program except, here we have used **%c** format
specifier with 37 as its value. Because, **%c** format specifier is used to print character, and the ASCII value of
**%** character is 37. So to print **%** sign on output screen after the percentage value, we have used its ASCII
value as shown in the above output.

The question is, **write a program in C that asks from user to enter marks obtained and find average and percentage mark
value. Here subject count and maximum marks must be entered by user.** The answer to this question is given below.

This is the complete version of calculating average and percentage marks program in C. Here the number of subject and maximum mark is decided by user. Let's have a look at it:

// Find Average and Percentage Mark in C // ------codescracker.com------- #include<stdio.h> #include<conio.h> int main() { int i, n, max; float mark, sum=0, avg, perc; printf("How many Subject runs in your Institute ? "); scanf("%d", &n); printf("\nEnter Maximum Mark of Subject: "); scanf("%d", &max); printf("\nEnter Marks obtained in %d Subjects (Out of %d): ", n, max); for(i=0; i<n; i++) { scanf("%f", &mark); sum = sum+mark; } avg = sum/n; perc = (sum/(n*max))*100; printf("\nAverage Mark = %0.2f", avg); printf("\nPercentage Mark = %0.2f%c", perc, 37); getch(); return 0; }

The snapshot given below shows the initial output of this program:

And the snapshot given below shows the final output of this program after supplying total number of subject runs in institute, maximum marks, and marks obtained in all subject.

Let's understand the above program (with its output) by the example given below:

- User enters
**6**as first question, that is**How many Subject runs in your Institute ?**. So**n**holds its value as 6 - User enters
**50**as second question. So the variable**max**has its value as**50** - Now user enters marks obtained in 6 subjects one by one. And the summation operation performed on each scan
like this:
- On first scan, user enters
**42**, so**sum+mark**or**0+42**(0 is initial value of**sum**) gets initialized to**sum** - Now
**sum**contains 42 as its value - On second scan, user enters
**46**, so**42+46**or**88**gets initialized to**sum** - Now
**sum**contains 88 as its value - On third scan, user enters
**40**, so**88+40**gets initialized to**sum** - Now
**sum**contains**128**as its value - On fourth scan, user enters
**38**, so**128+38**or**166**gets initialized to**sum** - Now
**sum**contains**166**as its value - On fifth scan, user enters
**41**, so**166+41**or**207**gets initialized to**sum** - Now
**sum**contains**207**as its value - On sixth scan, user enters
**39**, so**207+39**or**246**gets initialized to**sum** - Now
**sum**contains**246**as its value

- On first scan, user enters
- As of now,
**sum**contains**246**,**n**contains 6, and**max**contains**50** - So,
**sum/n**or**246/6**or**41**gets initialized to**avg**variable - And,
**(sum/(n*max))*100**or**(246/(6*50))*100**or**(246/300)*100**or**82**gets initialized to**perc**variable - Now simply print the value of
**avg**and**perc**variable as output of**Average Mark**and**Percentage Mark** **%0.2f**is used to print value upto 2 decimal places only. And**%c**with 37, is used to print**%**sign. Because**37**is the ASCII value of**%**sign. Thats it

- C++ Calculate Average and Percentage Marks
- Java Calculate Average and Percentage Marks
- Python Calculate Average and Percentage Marks