Write a program to count values in array and get percentage.
#include<iostream.h>
#include<conio.h>
#define MAX 10
void main(){
clrscr();
int Array[MAX];
int n=0,i=0,total=0;
float t_marks=0,temp=0,percent=0;
cout<<"Enter the Number of Subjects Max is 10 : ";
cin>>n;
cout<<"Enter the Total Marks ";
cin>>t_marks;
if(n>MAX){
cout<<" Sorry Max Subjects Allow is 10 ";
}else{
//Reading Values
for(i=1;i<=n;i++){
cout<<" Enter The Subject "<<i<<" Marks : ";
cin>>temp;
if(temp>100){
cout<<"*--Sorry Marks is Not Greater Than 100--*\n";
i=i-1;
}else{
Array[i]=temp;
}
}
//Display Values
cout<<" Total Marks : "<<t_marks;
for(i=1;i<=n;i++){
cout<<"\nSubject "<<i<<" Marks : "<<Array[i];
total = total + Array[i];
}
}
temp = total/t_marks;
percent = temp * 100;
cout<<"\nAverage : "<<percent<<"%";
getch();
}Program Output

(Visited 169 times, 1 visits today)
Written by: