Sunday, July 26, 2009

C++ code this problem?

task:Write a C program that will output the seven times table, as follows:


7x1 = 7


7x2= 14


7x3= 21...

C++ code this problem?
#include %26lt;stdio.h%26gt;





int main {


int i;


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


write("7 x %d = %d\n",i, i*7);


}


return 0;


}





It that what you want?
Reply:Dude, you can write this on your own. You ask for c++ and your question says c program?





#include%26lt;iostream%26gt;


int main(void) {


int table, limit;


std::cout%26lt;%26lt;"Which table do you need?\n";


std::cin%26gt;%26gt;table;


std::cout%26lt;%26lt;"Specify the count limit?\n";


std::cin%26gt;%26gt;limit;


std::cout %26lt;%26lt;"Generating "%26lt;%26lt;limit%26lt;%26lt;" rows of table "%26lt;%26lt;table%26lt;%26lt;"\n";


for(int k=1; k %26lt;= limit; k++) {


std::cout%26lt;%26lt;table%26lt;%26lt;" * "%26lt;%26lt;k%26lt;%26lt;" = "%26lt;%26lt;table*k%26lt;%26lt;"\n";


}


}





I compiled it under g++, I not aware which compiler you use.





Output:


---------


Which table do you need?


7


Specify the count limit?


15


Generating 15 rows of table 7


7 * 1 = 7


7 * 2 = 14


7 * 3 = 21


7 * 4 = 28


7 * 5 = 35


7 * 6 = 42


7 * 7 = 49


7 * 8 = 56


7 * 9 = 63


7 * 10 = 70


7 * 11 = 77


7 * 12 = 84


7 * 13 = 91


7 * 14 = 98


7 * 15 = 105








-----------





Hope that is what you need.





I am a perl programmer, but it was fun recollecting c++ and writing simple program for you.

sundew

No comments:

Post a Comment