C Program to Find Percentage of given Subjects Marks using Array

Ex: Write a C program to find percentage of given subjects marks using array. How to write a C program to print percentages of given marks. C program to find percentage of given subjects marks.


Input from user:


Enter limit of subjects: 5


Enter marks of subject[1]:71

Enter marks of subject[2]:65
Enter marks of subject[3]:61
Enter marks of subject[4]:81
Enter marks of subject[5]:77

Expected output:


Percentage= 71.0000






  Step by step logic of the given program:


1. First declare array arr[size] and all variables we needed for this program like i, no, total=0 and per to store percentages.

2. Accept limit of subjects from user store it in variable no.

3. Use for loop to accept marks one by one. Store it in arr[i] (it store marks an array of position i).
for(i=0;i<no;i++)
{
printf("Enter marks of subject[%d]:",i+1);
scanf("%d",&arr[i]);

}

4. After that use one more for loop to print  total of that marks:
for(i=0;i<no;i++)
{
total=total+arr[i];

}

5. After that find percentage using: 
per=total/no;

6. Print this on output screen.





  C Program to Find Percentage of given Subjects Marks using Array:


#include<stdio.h>
void main()
{
int arr[100],i,no,total=0;
float per;

printf("Enter limit of subjects: ");
scanf("%d",&no);

printf("\n");
for(i=0;i<no;i++)
{
printf("Enter marks of subject[%d]:",i+1);
scanf("%d",&arr[i]);
}

for(i=0;i<no;i++)
{
total=total+arr[i];
}

per=total/no;
printf("\npercentage=%f",per);
}


Above program shows the following output:


C Program to Find Percentage of given Subjects Marks using Array

No comments:

Post a Comment

If you have any doubts, please discuss here...👇