Jan 25, 2022

operations on 'For' loop (C Language)

Use of if-else statements with for loop in C.

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

int main()
{
    int a, b;
    scanf("%d\n%d", &a, &b);
    // Complete the code.
    for (int n = a; n <= b; n++)
    {

        if (n == 1)
        {
            printf("one\n");
        }
        else if (n == 2)
        {
            printf("two\n");
        }
        else if (n == 3)
        {
            printf("three\n");
        }
        else if (n == 4)
        {
            printf("four\n");
        }
        else if (n == 5)
        {
            printf("five\n");
        }
        else if (n == 6)
        {
            printf("six\n");
        }
        else if (n == 7)
        {
            printf("seven\n");
        }
        else if (n == 8)
        {
            printf("eight\n");
        }
        else if (n == 9)
        {
            printf("nine\n");
        }
        else if (n % 2 == 0)
        {
            printf("even\n");
        }
        else
        {
            printf("odd\n");
        }
    }

    return 0;
}

No comments:

Post a Comment

Comparing two files in C language.

Operations on More than one File.    # include < stdio.h > # include < stdlib.h > # include < string.h > int main ( int ...