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) 

1 <= B, C <=1000000
0 <= A <= 1

 Input Format 

The first line contains the value of A, B and C separated by space(s).

 Output Format 

The first line contains the integers separated by a space.

 Example Input/Output 1 

 Input 

1 2 10

 Output 

2 4 6 8 10

 Example Input/Output 2 

 Input 

0 1 10

 Output 

1 3 5 7 9

 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

Popular Posts

Top Scoring Batsman - TEST ODI 20-20

Highly Profitable Months

Largest Possible Number With Digits

Minimum Sum of Non-Negative Elements

Count Embedded Integers in String

String - Vowels Position Sum

Desktop Products