Computer Science, asked by souravb12b, 8 months ago

The function printPattern(int num) prints even or odd numbers based on the value of the input argument num (num 20).
if the input number num is even, the function is expected to print the first num even whole numbers and in case it is odd. is expect
the first num odd numbers.
For example: given input 2, the function prints the string "O 2" (without quotes).
The function compiles successfully but fails to print the desired result due to logical errors.
Your task is to debug the program to pass all the test cases.​

Answers

Answered by upriyanshu833
0

Answer:

my son is doing a job

Explanation:

he is also INDIAN

Answered by dreamrob
2

Program in C++:

#include<iostream>

using namespace std;

void printPattern(int num)

{

if(num % 2 == 0)

{

 for(int i = 0; i <= num; i = i + 2)

 {

  cout<<i<<" ";

 }

}

else

{

 for(int i = 1; i <= num; i = i + 2)

 {

  cout<<i<<" ";

 }

}

}

int main()

{

int num;

cout<<"Enter a number : ";

cin>>num;

if(num < 0)

{

 cout<<"Invalid Input";

 return 0;

}

printPattern(num);

return 0;

}

Output:

Enter a number : 2

0 2

Similar questions