A triangle with one of its angle 90° is called right triangle. We shall now see how to print stars., in right triangle shape. AlgorithmAlgorithm should look like this −Step 1 - Take number of rows to be printed, n.Step 2 - Make outer iteration I for n times to print rowsStep 3 - Make inner iteration for J to IStep 3 - Print '.' (star)Step 4 - Print NEWLINE character after each inner iterationStep 5 - ReturnPseudocodeWe can derive a pseudocode for the above mentioned algorithm, as follows −procedure righttriangleFOR I = 1 to N DOFOR J = 1 to I DOPRINT '.'
![]() ![]()
END FORPRINT NEWLINEEND FORend procedureImplementationImplementation of right triangle in C is as follows −.
Program to print some text on the same line using multiple print statements Program to print addition of two numbers and print if summation is equal to third number or not Program that reads a number and prints even if the number is even and prints odd if the number is odd.
'VISHNU VARDHAN REDDY UNDYALA' writes: can u help in writing tha codeplease send me tha codeit is very urgent to me i know i have to do spacingbut i can't maintaining tha loops for thati am waiting 4 ur replyGive us your instructor's e-mail address so we can send the code tohim directly. I'm sure you wouldn't want to take credit for somebodyelse's work.Don't worry, we'll be sure to mention your name.-Keith Thompson (TheOtherKeith) San Diego Supercomputer Center We must do something. This is something. Therefore, we must do this. Void PrintTriangle(int noOfMaxAsterix)int n, i, j, k, l;n = (noOfMaxAsterix - 1) / 2;for (i = 0; i. BEGIN PGP SIGNED MESSAGE-Hash: SHA1VISHNU VARDHAN REDDY UNDYALA wrote: Hi,Could anyone over here, write a program in C using only for loop toprint the following output.I tried but could only get one side of the triangle.Quick reply is appreciated.
Thanks,This is not a C question, and thus is off topic here.But here's a hintAssuming that the top line of the triangle is #1, and the next line down isline #2, try to relate the number of stars in a line to the line number. Also,try to relate the number of spaces before the first star to the line number.You should be able to come up with two formula, one for stars and one forspaces, that vary properly with line number.Now, re-read the information on printf format codes, paying particularattention to the 'field width' and 'precision' specifiers. See if there is away to use the two formula from above to regulate your printf output.You should be able to reconstruct the triangle with /one/ for loop and /one/printf, within certain limits of triangle size.- -Lew PitcherMaster Codewright & JOAT-in-training GPG public key available on requestRegistered Linux User #112576 Slackware - Because I know what I'm doing.-BEGIN PGP SIGNATURE-Version: GnuPG v1.2.7 (GNU/Linux)iD8DBQFDYstkagVFX4UWr64RAv/fAKDgEjxdeDH5642W/MX0ct6Fz8j8dACg7Qt0BxFRlt/IzSFt+qoKGC4Oh2g+wmS-END PGP SIGNATURE. Nelu yazdi: void PrintTriangle(int noOfMaxAsterix)int n, i, j, k, l;n = (noOfMaxAsterix - 1) / 2;for (i = 0; i. Keith Thompson wrote:'VISHNU VARDHAN REDDY UNDYALA' writes: can u help in writing tha codeplease send me tha codeit is very urgent to me i know i have to do spacingbut i can't maintaining tha loops for thati am waiting 4 ur replyGive us your instructor's e-mail address so we can send the code tohim directly.
I'm sure you wouldn't want to take credit for somebodyelse's work.Don't worry, we'll be sure to mention your name.Exactly what I thought.:) Why don't people get it that they won't learnanything that way?Arne- PGP key FD05BED7 - -. 'Arne Schmitz' wrote in messagenews:[email protected]. Keith Thompson wrote:'VISHNU VARDHAN REDDY UNDYALA' writes: can u help in writing tha codeplease send me tha codeit is very urgent to me i know i have to do spacingbut i can't maintaining tha loops for thati am waiting 4 ur replyGive us your instructor's e-mail address so we can send the code tohim directly. I'm sure you wouldn't want to take credit for somebodyelse's work.Don't worry, we'll be sure to mention your name.Exactly what I thought.:) Why don't people get it that they won't learnanything that way?Too many 'students' are not interested in learning,but only in acquiring a diploma or certificate.' I r a progrmr. Sez rite hear on ths papr, see?'
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |