write a c program to find the percentage marks where obtain marks and total marks is given by user also show the fail message if marks is less than 17%
To write a C program that calculates the percentage of marks obtained by a student and checks if the marks are less than 17%, you can follow these steps:
1. Include the necessary header files:
```
#include <stdio.h>
```
2. Declare the main function:
```
int main() {
// Write your code here
return 0;
}
```
3. Declare the variables to store the obtained marks, total marks, and the percentage:
```
int obtainMarks, totalMarks;
float percentage;
```
4. Prompt the user to enter the obtained marks and total marks:
```
printf("Enter the obtained marks: ");
scanf("%d", &obtainMarks);
printf("Enter the total marks: ");
scanf("%d", &totalMarks);
```
5. Calculate the percentage:
```
percentage = (float)obtainMarks / totalMarks * 100;
```
6. Check if the percentage is less than 17% and display the appropriate message:
```
if (percentage < 17.0) {
printf("Fail! Your percentage is %.2f%%\n", percentage);
} else {
printf("Pass! Your percentage is %.2f%%\n", percentage);
}
```
7. Complete the program by adding the closing braces for the main function:
```
int main() {
// Write your code here
int obtainMarks, totalMarks;
float percentage;
printf("Enter the obtained marks: ");
scanf("%d", &obtainMarks);
printf("Enter the total marks: ");
scanf("%d", &totalMarks);
percentage = (float)obtainMarks / totalMarks * 100;
if (percentage < 17.0) {
printf("Fail! Your percentage is %.2f%%\n", percentage);
} else {
printf("Pass! Your percentage is %.2f%%\n", percentage);
}
return 0;
}
```
By following these steps, you can write a C program that calculates the percentage marks and display a fail message if the marks are less than 17%.