Sort by

recency

|

822 Discussions

|

  • + 0 comments

    ////The solution without for loop

    include

    int a,b; void assign() {
    switch (a) { case 1: printf("one\n"); break; case 2: printf("two\n"); break; case 3: printf("three\n"); break; case 4: printf("four\n"); break; case 5: printf("five\n"); break; case 6: printf("six\n"); break; case 7: printf("seven\n"); break; case 8: printf("eight\n"); break; case 9: printf("nine\n"); break; default: if (a > 9 && a % 2 == 0) { printf("even\n"); } else { printf("odd\n"); } break; } } int main() { int i = 0; scanf("%d\n%d", &a, &b); while ( a <= b) { assign(); a++; }

    return 0;
    

    }

  • + 0 comments

    include

    include

    include

    include

    int main() { int a, b; scanf("%d\n%d", &a, &b); // Complete the code. int i ; for(i=a;i<=b;i++){ if(i>=1 && i<=9){ switch(i){ case 1: printf("one\n"); break; case 2: printf("two\n"); break; case 3: printf("three\n"); break; case 4: printf("four\n"); break; case 5: printf("five\n"); break; case 6: printf("six\n"); break; case 7: printf("seven\n"); break; case 8: printf("eight\n"); break; case 9:
    printf("nine\n"); break; } } else{ if(i>9){ if(i%2==0){ printf("even\n"); } else{ printf("odd\n"); } } } } return 0; }

  • + 0 comments

    Good Code

    #include<stdio.h>
    
    int main() {
        int n,b;
    
        scanf("%d", &n);
        scanf("%d", &b);
    
        for (int i = n;i <= b; i++ ){
            printf((i==1)?"one": (i==2)?"two":(i==3)?"three"
            :(i==4)?"four":(i==5)?"five":(i==6)?"six"
            :(i==7)?"seven":(i==8)?"eight":(i==9)?"nine"
            : (i%2==0)?"even":"odd");
            printf("\n");
        }
    
        return 0;
    
    }
    
  • + 0 comments
    int main() 
    {
        char numberStrings[9][20] = {
            "one",
            "two",
            "three",
            "four",
            "five",
            "six",
            "seven",
            "eight",
            "nine"
        };
        int a, b;
        scanf("%d\n%d", &a, &b);
        
        for(int i = a; i <= b; i++ ) {
            if(i > 0 && i <= 9) {
                printf("%s\n", numberStrings[i - 1]);
            } else {
                printf("%s\n", ((i % 2) == 1) ? "odd" : "even");
            }
        }
    
        return 0;
    }
    
  • + 0 comments

    For loops are such a powerful tool in programming! They allow you to repeat actions efficiently, making your code more concise and readable. cricbet99club