In the previous blog we saw whether the given year is leap or not, now we will see whether the student has passed or failed in the exam .
Conditional Statements:-
If condition:-
The if statement is used to examine a given condition and perform actions based on whether or not that condition is true. It's most commonly utilized in scenarios where we need to perform many operations for various situations. The if statement's syntax is seen below.
if(expression)
{
}
If-Else Condition:-
For a single condition, the if-else statement is used to conduct two operations. It's an enhancement to the if statement that allows us to conduct two different operations, one for the condition's correctness and the other for the condition's incorrectness. It is important to note that the if and else blocks cannot be run at the same time. The syntax is seen below.
if(expression)
{
}
else
{
}
To check whether the student has passed or failed in the exam .
CODE:-
#include <stdio.h>
int main()
{
int total,s1,s2,s3,s4,s5;
printf("Enter the five subject marks");
scanf("%d %d %d %d %d",&s1,&s2,&s3,&s4,&s5);
total=s1+s2+s3+s4+s5;
if(total>250)
{
printf("The student has PASSED in the exam");
}
else
{
printf("The student has FAILED in the exam");
}
}
Algorithm:-
1.Start
2.Declare the variables s1,s2,s3,s4,s5 as subject marks for the five subjects and use the scanf statement to get the input for the first 5 variables by using the format specifier "%d".
3.Use the total variable to sum the s1,s2,s3,s4,s5 marks .
4.Use the if-else statement to check if the student has passed or failed in the exam .
5.If the student has got more than 250 marks then the student has passed the exam.
Explanation:-The pass mark for the examination is more than 250 so that particular condition is specified.
6.Else the student has failed in the exam .
7.Stop
Screenshot:-
1.Code Screenshot:-
2.Output Screenshot:-
In the next blog, we will see whether the given number is palindrome or not .
0 Comments