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.
- Prepare
- C
- Conditionals and Loops
- For Loop in C
- Discussions
For Loop in C
For Loop in C
Sort by
recency
|
841 Discussions
|
Please Login in order to post a comment
include
include
include
include
int main() { int a, b; scanf("%d\n%d", &a, &b); // Complete the code. char *nums[9] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; for(int i = a; i <= b; i++){ if(i > 0 && i < 10) printf("%s\n", nums[i-1]); else{ if(i % 2 == 0) printf("even\n"); else printf("odd\n"); }
}
return 0; }
int main() { int n,a, b; scanf("%d\n%d\n", &a, &b); scanf("%d\n", &n); //if(n>0) //{ for(int i=a; i<=b;i++) { switch(i) { case(1):printf("ONE"); break; case(2):printf("TWO"); break; case(3):printf("THREE"); break; case(4):printf("FOUR"); break; case(5):printf("FIVE"); break; case(6):printf("SIX"); break; case(7):printf("SEVEN"); break; case(8):printf("EIGHT"); break; case(9):printf("NINE"); break; }
} //} else if(n%2==0) printf("even\n"); else { printf("\nodd"); } }
This challenge is a great way to practice using the for loop and conditional statements effectively. 11xplay Pro Login
include
void digitnames(int n){ char *digitNames[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
} void oddeven(int m){ int odd,even; if(m%2==0){ printf("even\n"); }else{printf("odd\n");} } int main() { int digitstore[2]; for (int i = 0; i < 2; i++) { scanf("%d", &digitstore[i]); }
* oddeven(digitstore[i]); }
}