Question discussion

What is the output of the following code?

359040Medium DSSSB TGT Computer Science 0 replies 0 views
0
What is the output of the following code?
#include <stdio.h>
int main() {
    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= i; j++) {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}
  • A* ** ***
  • B*** ** *
  • C*** *** ***
  • DCompilation Error
Correct answer: A

Explanation

The outer loop runs 3 times and the inner loop prints i stars each time, giving *, ** and *** on separate lines.

Discussion 0

Nobody has replied yet. Start the discussion!