Conditional Statements in C hackerrank solution

    
        
        #include <stdio.h>

        int main() {
            int n;
            scanf("%d", &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 {
                printf("Greater than 9\n");
            }
        
            return 0;
        }
        
        
        
        
    

Let's go through the solution step by step:

We include the header file to use the standard input/output functions.

In the main() function, we declare an integer n to store the input value.

We use the scanf() function to read input from the user and store it in the variable n.

We use a series of if-else if statements to check the value of n against different conditions.

If n is equal to 1, 2, 3, ..., 9, we print the corresponding word ("one", "two", "three", ..., "nine") using the printf() function.

If n is not equal to any of the values 1 to 9, we print "Greater than 9" using the printf() function.

By providing the expected input and executing the code, you should see the desired output according to the problem statement on HackerRank.