Friday, May 21, 2010

C language help?

How do you do this one with FOR loop and how with DO...WHILE loop?





*


**


***


****


Until ten

C language help?
#include %26lt;iostream%26gt;





using namespace std;





int main()


{


int i,j;





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


{


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


{


cout%26lt;%26lt;"*";


}


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


}


return 0;


}
Reply:i don't if it is right...


x = 0


while (x %26lt; 11)


{


do


y=x


while (y %26gt; 0)


{


do


printf (" * \n");


}


printf ("\n");


printf (" * ");


}
Reply:#include %26lt;stdio.h%26gt;


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


printf("For Loop\n");


int i ;


char stars1[11] = "*";


for (i = 0; i %26lt; 10; i++){


printf("%s\n",stars1); //print the char array of stars


strcat(stars1,"*"); //concatenate to our initial string one more star


}





i = 0


char stars2[11]="*";


printf("While\n");





do{


printf("%s\n",stars2);


strcat(stars2,"*");


i++;





}while(i %26lt; 10);








+++++++++++++++++++++++++++++++++++++


or you can do this





int i = 0;


int j = 0;





for(i = 0; i %26lt; 10;i++){


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


printf("%s","*");


}


printf("\n");





}


i = 0;


j = 0;





do{


do{


printf("%s","*");


j++;


}while(j %26lt; (i+1));


j = 0;


i++;


printf("\n");


}while(i %26lt; 10);





Good Luck


No comments:

Post a Comment