How to fix this zeros?? Here's the code! #include struct student //Defining structure { int id; char name[20]; float percentage; }; void main(){ //Program execution starts int n, passedCount = 0; //Variable for user input output float highestGrade = 0; //variable for output highest score printf("Enter Number of Records: "); scanf("%d",&n); //user input number of students struct student record[n]; //defining array of size n for (int i = 0; i < n; i++){ //running loop n times printf("\nRecords of STUDENT: %d\n",i+1); printf("ID: "); scanf("%d",&record[i].id); //user input student id printf("\nName: "); scanf("%s",record[i].name); //user input student name printf("\nPercentage: "); scanf("%f",&record[i].percentage); //user input student percentage //comparing entered percentage with already stored highest if (record[i].percentage > highestGrade) highestGrade = record[i].percentage; //checking whether the student passed if (record[i].percentage > 70 && record[i].percentage <= 100) passedCount++; } //Displaying output printf("\n\nHighest Grade: %f\n",highestGrade); printf("Total No. of Passed: %d\n",passedCount); //number of student failed = total - passed printf("Total No. of Failed: %d\n",n-passedCount);
How to fix this zeros??
Here's the code!
#include<stdio.h>
struct student //Defining structure
{
int id;
char name[20];
float percentage;
};
void main(){ //Program execution starts
int n, passedCount = 0; //Variable for user input output
float highestGrade = 0; //variable for output highest score
printf("Enter Number of Records: ");
scanf("%d",&n); //user input number of students
struct student record[n]; //defining array of size n
for (int i = 0; i < n; i++){ //running loop n times
printf("\nRecords of STUDENT: %d\n",i+1);
printf("ID: ");
scanf("%d",&record[i].id); //user input student id
printf("\nName: ");
scanf("%s",record[i].name); //user input student name
printf("\nPercentage: ");
scanf("%f",&record[i].percentage); //user input student percentage
//comparing entered percentage with already stored highest
if (record[i].percentage > highestGrade)
highestGrade = record[i].percentage;
//checking whether the student passed
if (record[i].percentage > 70 && record[i].percentage <= 100)
passedCount++;
}
//Displaying output
printf("\n\nHighest Grade: %f\n",highestGrade);
printf("Total No. of Passed: %d\n",passedCount);
//number of student failed = total - passed
printf("Total No. of Failed: %d\n",n-passedCount);
}
Look in the Expected Results in the Outputs!
Step by step
Solved in 2 steps with 1 images