Assume that the int variables i and j have been
declared, and that n has been declared and initialized.

Write code that causes a "triangle" of asterisks of size
n to be output to the screen. Specifically, n lines should
be printed out, the first consisting of a single asterisk,
the second consisting of two asterisks, the third
consistings of three, etc. The last line should consist of
n asterisks. Thus, for example, if n has value 3, the
output of your code should be
*
**
***
You should not output any space characters.

Hint: Use a for loop nested inside another for loop.

Answers were Sorted based on User's Feedback



Assume that the int variables i and j have been declared, and that n has been declared and ini..

Answer / sreepal

#include<stdio.h>
main()
{
int i,j,n;
printf("Enter the size of Triangle:");
scanf("%d", &n);

for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("*");
}
printf("\n");
}
}

Is This Answer Correct ?    9 Yes 4 No

Assume that the int variables i and j have been declared, and that n has been declared and ini..

Answer / geetha.s.b

*
**
***

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More C C++ Errors Interview Questions

Write a program to accept two strings of Odd lengths. Then take all odd characters from one string and even characters from the other and concatenate and produce a string.

1 Answers  


quoroum of computer languages?

0 Answers   Infosys,


full c programming error question based problem

3 Answers   HCL, TCS,


loop1: { x=i<n?(i++):0; printf("%d",i); exit(x); continue; } Error- misplaced continue. Doubt-1.will the exit(x) be executed for all values of x 2.will this statement go out of the program.

5 Answers   CMC,


Given that two int variables, total and amount , have been declared, write a sequence of statements that: initializes total to 0 reads three values into amount , one at a time. After each value is read in to amount , it is added to the value in total (that is, total is incremented by the value in amount ). Instructor's notes: If you use a loop, it must be a for loop. And if you use a loop control variable for counting, you must declare it.

1 Answers   Google,






what are the techniques for reducing the fragility of a memory bug?

1 Answers  


Display this kind of output on screen. 1 0 1 1 0 1 3. Display this kind of output on screen. 1 1 0 1 0 1 4. Display this kind of output on screen. 1 1 0 1 0 1 5.Display this kind of output on screen. 1 2 3 4 5 6 7 8 9 10

1 Answers  


class test { int a; public: test(int b):a(b){} void show(){ cout<<a; } }; void main() { test t1; test t2(5); t1.show(); t2.show(); } }

1 Answers  


what is meant for variable not found?

3 Answers  


which typw of errors ? & how to solve it ?

0 Answers  


what is macro in c? Difference between single linked list & double linked list what is fifo & lifo? what is stack & queue?

2 Answers   TCS,


Write down the difference between c. Loop and goto statement d. (!0) and (!1) e. (1= =! 1) and (1!=1) f. NULL and !NULL

0 Answers  


Categories