# Thread: Help nested for loops

1. ## Help nested for loops

so i have run into another wall, there is this problem where it tells me to print dollard signs

Using 2 For loops printout

\$\$\$\$\$
\$\$\$\$
\$\$\$
\$\$

Code:
```#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,j;

for(i=1;i<=5;i++){
for(j=1;j<=5;j++){
printf("i= %i and j= %i\n",i,j);
}
}
getchar();
}```
ok so i can get the numbers to print out but how can i work it so it prints dollard signs instead of the numbers, im a bit lost 2. Originally Posted by dals2002 so i have run into another wall, there is this problem where it tells me to print dollard signs

Using 2 For loops printout

\$\$\$\$\$
\$\$\$\$
\$\$\$
\$\$

Code:
```#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,j;

for(i=1;i<=5;i++){
for(j=1;j<=5;j++){
printf("i= %i and j= %i\n",i,j);
}
}
getchar();
}```
ok so i can get the numbers to print out but how can i work it so it prints dollard signs instead of the numbers, im a bit lost
I have decided to take your question literally:
Code:
`printf("\$");` 3. Make a small mental note of the lengths of the sequences of the dollar signs to print.
Write a for loop that it's control variable will take those values.
Now that you have a variable that iterates over the lengths of the sequences of the
dollar signs you want to print, write a second for loop that is controlled (stops) by the
value of that variable, and simply print a '\$'. 4. Originally Posted by tabstop I have decided to take your question literally:
Code:
`printf("\$");`
what i mean to print out is

\$\$\$\$\$
\$\$\$\$
\$\$\$
\$\$

but if i do it that way it all prints it out in a straight line down which is not really what im looking for 5. Originally Posted by xuftugulus Make a small mental note of the lengths of the sequences of the dollar signs to print.
Write a for loop that it's control variable will take those values.
Now that you have a variable that iterates over the lengths of the sequences of the
dollar signs you want to print, write a second for loop that is controlled (stops) by the
value of that variable, and simply print a '\$'
.
the second loop is exactly what i don't get how can i change the values to printout \$ signs, i get the part where i set the system to do it

Code:
```for(i=1;i<=1;i++){
for(j=1;j<=5;j++){
what am i suppose to printout, so that it prints dollards instead of numbers?```
or am i doing it wrong? 6. putchar('\$'); for example My question is what is the sequence of the lengths of the sequences of dollar signs
that you want to print, and how would you write a for loop that enumerates that sequence? 8. Originally Posted by vart putchar('\$'); for example
i kind of got it now just need to break it up which i been trying to put j-- to see if it does remove the one but i guess it doesn't, also i have another question is there anyway to write putchar('\$'), wanna make sure i know more than one just in case it presents itself in any future test thanks

Code:
```int main()
{
int i,j;

for(i=1;i<=4;i++){
for(j=1;j<=5;j++){
putchar('\$');
}
printf("\n");
}
getchar();
}```
now it prints out, how can i make it

\$\$\$\$\$ ----> \$\$\$\$\$
\$\$\$\$\$ ----> \$\$\$\$
\$\$\$\$\$ ----> \$\$\$
\$\$\$\$\$ ----> \$\$ 9. replace the j<=5 with the appropriate condition 10. Originally Posted by vart replace the j<=5 with the appropriate condition
wow i can't believe i missed that, i really missed it by a long shot

here is the finished program

Code:
```int main()
{
int i,j;

for(i=1;i<=4;i++){
for(j=1;j<=6-i;j++){
putchar('\$');
}
printf("\n");
}
getchar();
}```
can i ask, is there anyways to write putchar('\$'), in other formats? 11. is there anyways to write putchar('\$'), in other formats?
What do you mean? I do not understand your question 12. Originally Posted by vart What do you mean? I do not understand your question
like is there any other way to like re write it so that instead of putchar('\$') i can use like printf or something else? 13. well all that is left for me to say its thanks to all that contributed and helped   14. yes you can.
There is a lot of IO functions http://msdn2.microsoft.com/en-us/lib...xx(VS.71).aspx

You can read their descrition and decide what of them could be used to output one char to file/stdout 15. Originally Posted by vart yes you can.
There is a lot of IO functions http://msdn2.microsoft.com/en-us/lib...xx(VS.71).aspx

You can read their descrition and decide what of them could be used to output one char to file/stdout
thanks this is very helpful  Popular pages Recent additions 