Knowee
Questions
Features
Study Tools

Note: This question helps in clearing Cognizant conceptual technical interview12345678910111213#include <stdio.h> int main() { for (int num = 1; num <= 5; num++) { if (num % 2 == 0) { continue; } for (int i = 1; i <= num; i++) { printf("%d ", i); } printf("\n"); } return 0; }

Question

Note: This question helps in clearing Cognizant conceptual technical interview12345678910111213#include <stdio.h> int main() { for (int num = 1; num <= 5; num++) { if (num % 2 == 0) { continue; } for (int i = 1; i <= num; i++) { printf("%d ", i); } printf("\n"); } return 0; }

🧐 Not the exact question you are looking for?Go ask a question

Solution

The code you've posted is written in C language. It's a simple program that uses two for loops and an if condition. Here's a step-by-step explanation of what it does:

  1. The main function is declared. This is the entry point of the program.

  2. A for loop is initiated with a variable 'num' that starts at 1 and increments by 1 each time until it reaches 5.

  3. Inside this loop, an if condition checks if 'num' is an even number by using the modulus operator (%). If 'num' is even, the 'continue' statement is executed. This means that the rest of the current iteration is skipped, and the loop continues with the next iteration.

  4. If 'num' is not even (i.e., it's odd), another for loop is initiated with a variable 'i' that starts at 1 and increments by 1 each time until it reaches the value of 'num'.

  5. Inside this second loop, the value of 'i' is printed to the console, followed by a space.

  6. After the second loop finishes, a newline character is printed to the console. This means that the next print statement will start on a new line.

  7. The process repeats until 'num' is greater than 5.

  8. The main function returns 0, which signifies that the program has ended successfully.

So, the output of this program would be:

1 1 2 3 1 2 3 4 5

This is because the 'continue' statement skips the iterations where 'num' is even, so the inner loop only runs when 'num' is odd.

This problem has been solved

Similar Questions

what is conceptualize interaction? discuss about importance of conceptualized design?

Multiple Choice QuestionA person using ______ skills has the ability to think in abstract terms and see how parts fit together to form the whole.Multiple choice question.technicalhuman relationsoperationalconceptual

describe in detail cognitive framework

Describe in detail cognitive framework

Describe in detail cognitive framework

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.