Question:
C Programming Help! (While Loops/Temperature Plates)?
anonymous
1970-01-01 00:00:00 UTC
C Programming Help! (While Loops/Temperature Plates)?
Three answers:
anonymous
2016-05-27 18:51:47 UTC
when you compile, try to use the single step feature and watch your variables, this should answer the question. here is how I did it, // bradstest.cpp : main project file. #include "stdafx.h" #include "stdio.h" using namespace System; int main(array ^args) { Console::WriteLine(L"Hello World"); const char x[] = {'1','2','3','4','5'}; int y,z= 4; int zz; for (y=4; y>=0; y--) { for (zz = z; zz >=0; zz--) { printf("%c", x[zz]); } printf("\n"); z--; } Console::Read(); return 0; }
Tasm
2009-05-28 09:10:56 UTC
Every 101 programming class has the print a triangle problem. All that math is just to confuse the real lesson.



Basically, the number of spaces you need to print before the data on a line is equal to the height of the triangle.



Lines = 6



* (6 spaces)

*** (5 spaces)

***** (4 spaces)

******* (3 spaces)

********* (2 spaces)

*********** (1 space)

************* (0 space)



dataCount = 1;



for(line = 0; line
{

for(space = 0; space
cout << " ";

for(data = 0; data
cout << "*";

dataCount+=2;

}
Paul
2009-05-24 23:48:21 UTC
You just need two nested loops - these can be for loops or while loops, the principle is the same. The inner loop takes care of printing one row. The outer loop runs the inner loop multiple times to generate all the rows.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...