9Google AdSense

If-Else Example

#include <stdio.h>
#include <stdlib.h>

//checking student passed or failed in exam
int main()
{
    int mark;
    scanf("%d",&mark);
    if(mark>=50)
        printf("You are passed");
    else
        printf("You are failed");

    return 0;
}

=====================================
#include <stdio.h>
#include <stdlib.h>

//checking student grade
int main()
{
    int mark;
    scanf("%d",&mark);
    if(mark>=80)
        printf("Grade : A+");
    else if(mark>=70)
        printf("Grade: A");
    else if(mark>=60)
        printf("Grade: A-");
    else if(mark>=50)
        printf("Grade: B");
    else if(mark>=40)
        printf("Grade: B-");
    else
        printf("Grade: Fail");

    return 0;
}

======================================

#include <stdio.h>
#include <stdlib.h>

//check a number is even or odd

int main()
{
    int number;
    scanf("%d",&number);
    if(number == 0)
        printf("Given number is zero");
    else if(number%2==0)
        printf("%d is a even number",number);
    else
        printf("%d is a odd number",number);
    return 0;
}

==========================================



==========================================

#include <stdio.h>
#include <stdlib.h>

//check a number is positive or negative

int main()
{
    int number;
    scanf("%d",&number);
    if(number == 0)
        printf("Given number is zero");
    else if(number>0)
        printf("%d is a positive number",number);
    else
        printf("%d is a negative number",number);
    return 0;
}

===========================================
#include <stdio.h>
#include <stdlib.h>

//voting age check

int main()
{
    int age;
    printf("Enter Your Age :");
    scanf("%d",&age);
    if(age>=18)
    {
         printf("you can vote");
    }
    else
    {
         printf("you are not Eligible for voting");
    }
    return 0;
}

No comments: