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
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 |
Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do...while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .
when i use cout or cin call & then either << or >> .....it shows declaration syntax error...what should i do? cout<<"anything"; int a; cin>>a; return 0;
quoroum of computer languages?
Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0. Instructor's notes: This problem requires either a while or a do-while loop.
UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls....
A sample program using data structure? what is file handling?
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.
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.
what is syntax error?
what is exceptions?
Why are memory errors hard to debug?
Declaration of Cube Guys please help me.. Is this a right way to declare cube.? If i Compile it. It Says: Cube undeclared what should i do? Please help \thanks in advanced #include<stdio.h> #include<math.h> #include<conio.h> main( ) { float x,y; while(x++<10.0) { printf("Enter Number:"); scanf("%d", &x); y = cube(x); printf("%f %f %f \n", x,pow(x,2),y); cube(x); } { float x; float y; y = x*x*x; } getch(); return (y); }