C Program To Display Student Results

The C program to display student results demonstrates the working of conditional statement in the C language. The program takes student’s marks in percentage (%) as input , process the input value and displays the results (pass or fail) as output.

Advertisements

The output depends on the conditional statement in the example program.

Learn C programming basics before you begin with this example program.

Problem Definition

The program decides whether a student has passed or failed an exam. If the input is in percentage mark ( say 70%), a simple conditional statement checks if given percentage mark is below 40%.

Advertisements
( mark < 40)

The student result is a pass when mark is above 40% , else the student has failed. The result is displayed at the console.Here we list the steps involved in processing input values.

  1. Receive input in percentage mark (%)
  2. Check if the given mark is above below 40%
  3. If below 40%, then the student has failed
  4. Else the student passed.
  5. Display the result.

Flowchart – Display Student Results

The program start at the top (Start) and terminates where it says, (End) in the flowchart.

Flowchart - C Program to Display Student Results
Flowchart – C Program to Display Student Results

Program Code – Display Student Results

/*Show result of student using Marks */
#include <stdio.h>
#include <conio.h>
int main()
{
    int marks,i;
    /* Read student marks */
    printf("Enter the marks (in percentage ) of Student:");
    scanf("%d",&marks);
    /* display result */
    if(marks < 40)
    {
        for(i=0;i<40;i++)
        printf("_");printf("\n\n");
        printf("Result = Failed\n");
        for(i=0;i<40;i++)
        printf("_");printf("\n\n");
    }
    else
    {
        for(i=0;i<40;i++)
        printf("_");printf("\n\n");
        printf("Result = Passed\n");
        for(i=0;i<40;i++)
        printf("_");printf("\n\n");
    }
    system("pause");
    return 0;
}

Output

The student entered his or her mark which is 60%. The given mark are above 40%, required condition to pass the exam. Hence, the student result is passed.

Enter the marks ( in percentage ) of Student:60
___________________________________________________
Result = Passed
___________________________________________________

Advertisements

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.