Monday, 7 March 2016

C Program For Calculate Percentage Of 5 Subjects

Problem :- C Program For Calculate Total Marks Of 5 Subjects And percentage.means yo have to given a variable size of subject like 2,3,5 and more subject as user wants and you need to calculate percentage of marks and also print the marks of each subject.

Logic :- First we will ask for total subject of student then we will enter marks of all those subject after that we will calculate a percentage of marks then we will print a student marks ,percentage and Grade of Student .Percentage formula are given Below. 

Percentage of Marks = (all subject marks sum) / Total Subject *100 .

For This Problem I Am Taking 5 Subject.

See Also :- C++ Program For Calculate Percentage Of 5 Subjects

Solution :- 

Method 1 :- 

#include<stdio.h>

int main()
{
    /* Program By Ghanendra Yadav
    Visit http://www.programmingwithbasics.com/
    */
   int sub,marks,n,i,sum=0,tmp=0,arr[10],Percentage;

   printf("\nEnter number of subject : \n");
   scanf("%d", &n);
   
   tmp=n*100;
   
   printf("\nEnter The Marks: \n");
   for(i=0;i<n;i++)
   {
    scanf("%d", &arr[i]);
   }
   for(i=0;i<n;i++)
   {
    sum=sum+arr[i];
   } 
   
   Percentage = ( sum * 100 ) / tmp;
   
   printf("\nPercentage Of Student : %d\n", Percentage);

   return (0);

}

Method 2 :- 

#include<stdio.h>

int main()
{
    /* Program By Ghanendra Yadav
    Visit http://www.programmingwithbasics.com/
    */
   int s1, s2, s3, s4, s5, sum, total = 500;
   float per;

   printf("\nEnter marks of 5 subjects : ");
   scanf("%d %d %d %d %d", &s1, &s2, &s3, &s4, &s5);

   sum = s1 + s2 + s3 + s4 + s5;
   printf("\nSum : %d", sum);

   per = (sum * 100) / total;
   printf("\nPercentage : %f", per);

   return (0);

}


See Also :- Java Program For Calculate Percentage Of 5 Subjects

Output:- 


C Program For Calculate Percentage Of 5 Subjects



C Program For Calculate Percentage Of 5 Subjects

No comments:
Write comments

Recommended Posts × +