Sunday, August 2, 2009

C programming help?

help please i need to write a c program with a for loop on how to print the following:


*


**


***


****


*****


and


*******


******


*****


****


***


**


*thank-you!!!

C programming help?
To print like this


*


**


***


****


*****


use the following program





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


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


printf("*");


printf("\n");


}





To print like this





*******


******


*****


****


***


**


use the following program





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


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


printf("*");


printf("\n");


}





Be coz the question u asked was has two different style of output so u have to write two different pairs of for loops
Reply:int i,j;





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


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


printf("*");


printf("\n");


}





*note: n is the number of lines(input) you want to print, for example.. like on your first example it is 5 lines with 5 asterisks so n=5..





*i wont give the answer to the second, hehe..


its almost the same as the first code


dont just copy it..


analyze what the first code is doing


and try modifying the first code.. **clue: decrement.. --





hope these things helped you.. :)
Reply:WHAT THE **** IS THIS?!?!? IS THIS A QUESITON? WTF? ALL I SEE IS RANDOM SYMBOLS!!
Reply:you need 2 loops, one inside the other.


The outer loop defines how many *'s to print, so will count from 1 to 5.


The inner loop will actually draw the *'s.





example in pseudocode:


loop stars = 1 to 5 {


loop draw=1 to stars {


print '*'


}


print new line


}





now just convert to c.


No comments:

Post a Comment