Print OddEven
Coding Problem Keys
Print OddEven
Problem Statement
Three integers A, B and C are passed as input. If A is 0 the program must print the odd numbers from B to C. If A is 1 the program must print the even numbers from B to C. The function printOdd is implemented to print the odd numbers in the given range. Fill in the mussing lines of code to implement the function printEven and dispatcher to run the program successfully.
Boundary Condition(S)
Input Format
Output Format
Example Input/Output 1
Input
Output
Example Input/Output 2
Input
Output
Note: Max Execution Time Limit: 5000 millisecs
Solution
Programming Language: C Language
#include <stdio.h> void printOdd(int start, int end) { start = start%2! = 0? start : start+1; while(start <= end) { printf("%d ",start); start += 2; } }
void printEven(int s, int e){
s += s%2;
while(s <= e){
printf("%d ", s);
s += 2;
}
}
void dispatcher(void (*f) (int, int), int x, int y){
f(x,y);
}
// Published By PKJCODERS
int main() { int even, start, end; scanf("%d %d %d", &even, &start, &end); void (*funcPtr)(int, int) = even == 1? printEven : printOdd; dispatcher(funcPtr, start, end); return 0; }
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments