We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
my code is giving output eight nine nine even odd instead of eight nine even odd...why?? please help!
include
include
include
include
int main()
{
int a, b;
scanf("%d\n%d", &a, &b);
for(int n=a;n<=b;n++){
if(n>=1&&n<=9){
switch(n){
case 1:
printf("one\n");
case 2:
printf("two\n");
case 3:
printf("three\n");
case 4:
printf("four\n");
case 5:
printf("five\n");
case 6:
printf("six\n");
case 7:
printf("seven\n");
case 8:
printf("eight\n");
case 9:
printf("nine\n");
}}
else if(n>9&&n%2==0)
printf("even\n");
else if(n>9&&n%2==1)
printf("odd\n");
}
// Complete the code.
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
For Loop in C
You are viewing a single comment's thread. Return to all comments →
my code is giving output eight nine nine even odd instead of eight nine even odd...why?? please help!
include
include
include
include
int main() { int a, b; scanf("%d\n%d", &a, &b); for(int n=a;n<=b;n++){ if(n>=1&&n<=9){ switch(n){ case 1: printf("one\n"); case 2: printf("two\n"); case 3: printf("three\n"); case 4: printf("four\n"); case 5: printf("five\n"); case 6: printf("six\n"); case 7: printf("seven\n"); case 8: printf("eight\n"); case 9: printf("nine\n"); }} else if(n>9&&n%2==0) printf("even\n"); else if(n>9&&n%2==1) printf("odd\n"); }
}