43. WAP to understand if, else if functions.

 #include<stdio.h>

void main()

{

 

        // METHOD 1

        /*

        int i;

        printf("Enter the marks : ");

        scanf("%d",&i);

 

        if(i>74)

        printf("A\n");

 

        else if(i>59)

        printf("B\n");

 

        else if(i>39)

        printf("C\n");

 

        else

        printf("Fail\n");

        */

 

 

        // METHOD 2

        int a;

        printf("Enter the marks : ");

        scanf("%d",&a);

 

        if(a>39)

        {

                if(a>59)

                {

                        if(a>74)

                        {

                        printf("A\n");

                        }

                        else

                        printf("B\n");

                }

                else

                printf("C\n");

        }

        else

        printf("Fail");

}

Comments