Tuesday, July 28, 2009

C++ problem...?

can anyone help me how to write a c++ program to get the output like this:





* * * *


* *


* * * *





(use array and for)


the question wants me to use for and array..not just using cout%26lt;%26lt;"* * * *"%26lt;%26lt;endl; .....

C++ problem...?
#include %26lt;iostream%26gt;


#include %26lt;cstdlib%26gt;





using namespace std;





int main (void)


{


string arr [] = { "****" , "**" , "****" };


for (int i = 0; i %26lt; 3; i++) cout %26lt;%26lt; arr[i] %26lt;%26lt; endl;


system("pause");


return EXIT_SUCCESS;


}
Reply:well i can give u the pseudocode





create an array with length 9 that contain '*'s





for (i=0;i%26lt;len(array));i++)


{


cout%26lt;%26lt;array(i);


if ((i=3)or(i=5))


{


count%26lt;%26lt;"\n";


}


}
Reply:u can use while loop for it. self try now for graphic design.


No comments:

Post a Comment