Monday, July 27, 2009

C++ programmers need your help....im not able to do this program?

the program is to print the character "*" in the form of an X

C++ programmers need your help....im not able to do this program?
#include %26lt;stdio.h%26gt;





#define X_SIZE 15





int main() {


int line;





for (line = 0; line %26lt; X_SIZE; ++line) {


int i, first, last;





if (line %26lt; X_SIZE - 1 - line) {


first = line;


last = X_SIZE - 1 - line;


} else {


first = X_SIZE - 1 - line;


last = line;


}





// print spaces before the first '*'


for (i = 0; i %26lt; first; ++i)


printf(" ");





printf("*");





if (first != last) {


for (i = first + 1; i %26lt; last; ++i)


printf(" ");





printf("*");


}


printf("\n");


}


return 0;


}
Reply:simply check * using getchar(),and print x if there is *
Reply:Can u give some more detail of programm
Reply:http://en.wikipedia.org/wiki/C%2B%2B
Reply:#include%26lt;iostream.h%26gt;


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





void main()


{


int i;





clrscr();


for(i=0;i%26lt;7;i++)


{


gotoxy(7-i,2+i);


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


gotoxy(1+i,2+i);


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


}





getch();


}





I think this will do.





if u need further help mail me.
Reply:i am not having c++ compiler now, so there might be syntax error. Hope this is enough.





int i;


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


{


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


printf(" ");


printf("*");


for (int k = i; k %26lt; 10 - i; k++)


printf(" ");


printf("*");


cout%26lt;%26lt;"/n"; //go to next line


}


for (i = (10 / 2); i %26gt; 0; i--)


{


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


printf(" ");


printf("*");


for (int k = i; k %26lt; 10 - i; k++)


printf(" ");


printf("*");


cout%26lt;%26lt;"/n"; //go to next line


}


No comments:

Post a Comment