Featured
- Get link
- Other Apps
C program TO calculates and displays the percentage score
C program TO calculates and displays the percentage score
Sure, here's an example of a C program that takes input for a student's name, roll number, and marks obtained in four subjects, and then calculates and displays the percentage score:
```c
#include <stdio.h>
int main() {
char name[50];
int rollno;
int marks[4];
printf("Enter student's name: ");
scanf("%[^\n]", name);
printf("Enter roll number: ");
scanf("%d", &rollno);
printf("Enter marks obtained in four subjects:\n");
for (int i = 0; i < 4; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &marks[i]);
}
int totalMarks = 0;
for (int i = 0; i < 4; i++) {
totalMarks += marks[i];
}
float percentage = (float)totalMarks / 400 * 100;
printf("\nStudent Name: %s\n", name);
printf("Roll Number: %d\n", rollno);
printf("Percentage Score: %.2f%%\n", percentage);
return 0;
}
```
In this program, we use an array `marks` to store the marks obtained in four subjects. The loop iterates through the array to calculate the total marks, and then the percentage is calculated using the formula `(totalMarks / 400) * 100`. The `%.2f` format specifier is used to display the percentage with two decimal places.
```c
#include <stdio.h>
int main() {
char name[50];
int rollno;
int marks[4];
printf("Enter student's name: ");
scanf("%[^\n]", name);
printf("Enter roll number: ");
scanf("%d", &rollno);
printf("Enter marks obtained in four subjects:\n");
for (int i = 0; i < 4; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &marks[i]);
}
int totalMarks = 0;
for (int i = 0; i < 4; i++) {
totalMarks += marks[i];
}
float percentage = (float)totalMarks / 400 * 100;
printf("\nStudent Name: %s\n", name);
printf("Roll Number: %d\n", rollno);
printf("Percentage Score: %.2f%%\n", percentage);
return 0;
}
```
In this program, we use an array `marks` to store the marks obtained in four subjects. The loop iterates through the array to calculate the total marks, and then the percentage is calculated using the formula `(totalMarks / 400) * 100`. The `%.2f` format specifier is used to display the percentage with two decimal places.
```c
#include <stdio.h>
int main() {
char name[50];
int rollno;
int marks[4];
printf("Enter student's name: ");
scanf("%[^\n]", name);
printf("Enter roll number: ");
scanf("%d", &rollno);
printf("Enter marks obtained in four subjects:\n");
for (int i = 0; i < 4; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &marks[i]);
}
int totalMarks = 0;
for (int i = 0; i < 4; i++) {
totalMarks += marks[i];
}
float percentage = (float)totalMarks / 400 * 100;
printf("\nStudent Name: %s\n", name);
printf("Roll Number: %d\n", rollno);
printf("Percentage Score: %.2f%%\n", percentage);
return 0;
}
```
In this program, we use an array `marks` to store the marks obtained in four subjects. The loop iterates through the array to calculate the total marks, and then the percentage is calculated using the formula `(totalMarks / 400) * 100`. The `%.2f` format specifier is used to display the percentage with two decimal places.
```c
#include <stdio.h>
int main() {
char name[50];
int rollno;
int marks[4];
printf("Enter student's name: ");
scanf("%[^\n]", name);
printf("Enter roll number: ");
scanf("%d", &rollno);
printf("Enter marks obtained in four subjects:\n");
for (int i = 0; i < 4; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &marks[i]);
}
int totalMarks = 0;
for (int i = 0; i < 4; i++) {
totalMarks += marks[i];
}
float percentage = (float)totalMarks / 400 * 100;
printf("\nStudent Name: %s\n", name);
printf("Roll Number: %d\n", rollno);
printf("Percentage Score: %.2f%%\n", percentage);
return 0;
}
```
In this program, we use an array `marks` to store the marks obtained in four subjects. The loop iterates through the array to calculate the total marks, and then the percentage is calculated using the formula `(totalMarks / 400) * 100`. The `%.2f` format specifier is used to display the percentage with two decimal places.
```c
#include <stdio.h>
int main() {
char name[50];
int rollno;
int marks[4];
printf("Enter student's name: ");
scanf("%[^\n]", name);
printf("Enter roll number: ");
scanf("%d", &rollno);
printf("Enter marks obtained in four subjects:\n");
for (int i = 0; i < 4; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &marks[i]);
}
int totalMarks = 0;
for (int i = 0; i < 4; i++) {
totalMarks += marks[i];
}
float percentage = (float)totalMarks / 400 * 100;
printf("\nStudent Name: %s\n", name);
printf("Roll Number: %d\n", rollno);
printf("Percentage Score: %.2f%%\n", percentage);
return 0;
}
```
In this program, we use an array `marks` to store the marks obtained in four subjects. The loop iterates through the array to calculate the total marks, and then the percentage is calculated using the formula `(totalMarks / 400) * 100`. The `%.2f` format specifier is used to display the percentage with two decimal places.
```c
#include <stdio.h>
int main() {
char name[50];
int rollno;
int marks[4];
printf("Enter student's name: ");
scanf("%[^\n]", name);
printf("Enter roll number: ");
scanf("%d", &rollno);
printf("Enter marks obtained in four subjects:\n");
for (int i = 0; i < 4; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &marks[i]);
}
int totalMarks = 0;
for (int i = 0; i < 4; i++) {
totalMarks += marks[i];
}
float percentage = (float)totalMarks / 400 * 100;
printf("\nStudent Name: %s\n", name);
printf("Roll Number: %d\n", rollno);
printf("Percentage Score: %.2f%%\n", percentage);
return 0;
}
```
In this program, we use an array `marks` to store the marks obtained in four subjects. The loop iterates through the array to calculate the total marks, and then the percentage is calculated using the formula `(totalMarks / 400) * 100`. The `%.2f` format specifier is used to display the percentage with two decimal places.
```c
#include <stdio.h>
int main() {
char name[50];
int rollno;
int marks[4];
printf("Enter student's name: ");
scanf("%[^\n]", name);
printf("Enter roll number: ");
scanf("%d", &rollno);
printf("Enter marks obtained in four subjects:\n");
for (int i = 0; i < 4; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &marks[i]);
}
int totalMarks = 0;
for (int i = 0; i < 4; i++) {
totalMarks += marks[i];
}
float percentage = (float)totalMarks / 400 * 100;
printf("\nStudent Name: %s\n", name);
printf("Roll Number: %d\n", rollno);
printf("Percentage Score: %.2f%%\n", percentage);
return 0;
}
```
In this program, we use an array `marks` to store the marks obtained in four subjects. The loop iterates through the array to calculate the total marks, and then the percentage is calculated using the formula `(totalMarks / 400) * 100`. The `%.2f` format specifier is used to display the percentage with two decimal places.
```c
#include <stdio.h>
int main() {
char name[50];
int rollno;
int marks[4];
printf("Enter student's name: ");
scanf("%[^\n]", name);
printf("Enter roll number: ");
scanf("%d", &rollno);
printf("Enter marks obtained in four subjects:\n");
for (int i = 0; i < 4; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &marks[i]);
}
int totalMarks = 0;
for (int i = 0; i < 4; i++) {
totalMarks += marks[i];
}
float percentage = (float)totalMarks / 400 * 100;
printf("\nStudent Name: %s\n", name);
printf("Roll Number: %d\n", rollno);
printf("Percentage Score: %.2f%%\n", percentage);
return 0;
}
```
In this program, we use an array `marks` to store the marks obtained in four subjects. The loop iterates through the array to calculate the total marks, and then the percentage is calculated using the formula `(totalMarks / 400) * 100`. The `%.2f` format specifier is used to display the percentage with two decimal places.
```c
#include <stdio.h>
int main() {
char name[50];
int rollno;
int marks[4];
printf("Enter student's name: ");
scanf("%[^\n]", name);
printf("Enter roll number: ");
scanf("%d", &rollno);
printf("Enter marks obtained in four subjects:\n");
for (int i = 0; i < 4; i++) {
printf("Subject %d: ", i + 1);
scanf("%d", &marks[i]);
}
int totalMarks = 0;
for (int i = 0; i < 4; i++) {
totalMarks += marks[i];
}
float percentage = (float)totalMarks / 400 * 100;
printf("\nStudent Name: %s\n", name);
printf("Roll Number: %d\n", rollno);
printf("Percentage Score: %.2f%%\n", percentage);
return 0;
}
```
In this program, we use an array `marks` to store the marks obtained in four subjects. The loop iterates through the array to calculate the total marks, and then the percentage is calculated using the formula `(totalMarks / 400) * 100`. The `%.2f` format specifier is used to display the percentage with two decimal places.
Comments
Post a Comment
NAME
EMAIL ID
MESSAGE