Sunday, July 26, 2009

A simple C++ code?

hey.. can you give me the code for a program that gives the first 25 multiples of a number given by the user?





The output would be like:


cout%26lt;%26lt;"Please enter a number: ";





then the program would give the first 25 multiples of that number..

A simple C++ code?
Off the top of my head, and not having used the language in a long time, the code below should basically be what you are looking for. This would all go in the main section of the program.





int number;


int answer;


cout%26lt;%26lt;”Please enter a number: “%26lt;%26lt;endl;


cin%26gt;%26gt;number;





for (int x=1; x%26lt;26; x++)


{


answer= number *x;


cout%26lt;%26lt;endl%26lt;%26lt;answer;


}
Reply:Just use a loop. A for loop would be good for this one.
Reply:#include "iostream.h"





void main()


{


int number = 0;


cout %26lt;%26lt; "please enter a number: ";


cin %26gt;%26gt; number;





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


{


cout %26lt;%26lt; k*number %26lt;%26lt; "\n";





}





}
Reply:This is obviously a homework question, you would never do this in real life; and if you did, and were working in C++, you'd know how to do this in your sleep. I suggest you pay attention in class, read your textbook and stop bothering us with your homework problems.
Reply:it is simple really, do it


No comments:

Post a Comment