Monday, May 24, 2010

Please help me in for loop using C++?

for loop using TC?


please help me to solve this problem.. i cant help it.. i dont know how to do it.. please....





1 2 3 4 5


2 3 4 5


3 4 5


4 5


5


%26gt;%26gt; that will be the output using for loop





thanks.. please do help me guys

Please help me in for loop using C++?
#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


void main()


{


for(int i=5;i%26gt;=1;i--)


{


for(j=1;j%26lt;=i;j++)


cout%26lt;%26lt;i;


cout%26lt;%26lt;"\n";


getch()


}


}
Reply:using the following loop


for(i=1;1%26lt;=5;i++)


{


for(j=i;j%26lt;=5lj++)


{


cout%26lt;%26lt;setw(3)%26lt;%26lt;j;


}


cout%26lt;%26lt;endl;


}
Reply:try starting with a for loop to keep count of where you are up to, so it needs to start at 1 and have a max of 5, then it will increment each time ... you know the structure of a for loop -





for (i = 1; i %26lt;= 5; i++) { ... }





then inside that for loop you'll need an output function to print the number you're up to, so, i to your max of 5. this output for loop will end when it reaches 5. so put this for loop inside the curly brackets of your outer for loop.





then you'll go back to your outer for loop which will go to the next number, then your inner for loop will go from there and so on ...





always break your problem down and address one step at a time :)


No comments:

Post a Comment