0
Why can't i start my code for multiplication table from 3*1=3 ?
I wrote a code for multiplication table of 3. However I just won't get 3 * 1 = 3. Why is it? Here's the code: #include <iostream> using namespace std; int main() { cout << "Let's write table of 3 ! \n" ; int i=1,mult ; while (i <= 10) { cout << "3 * " << i << " = " << mult << endl; i = i+1; mult = 3*i ; } return 0; } __________________________ however this code somewhat works ( but I would like to omit 3*0=0 ) #include <iostream> using namespace std; int main() { cout << "Let's write table of 3 ! \n" ; int i=0,mult ; while (i <= 10) { cout << "3 * " << i << " = " << mult << endl; i = i+1; mult = 3*i ; } return 0; }
5 Answers
+ 7
Just rearrange the statements in while loop to do calculations before printing:
https://code.sololearn.com/c0k29GsOhOH0/?ref=app
+ 5
To avoid 0, initialize i with 1
int i=1, mult;
+ 4
Take input from user u can calculate table of any number see i did little changes
#include <iostream>
using namespace std;
int main()
{
int number;
cout << "Let's write table of " ;
cin>>number;
cout<<endl;
int i=1,mult ;
while (i <= 10) {
cout <<number<< "* " << i << " = " << mult << endl;
i = i+1;
mult = 3*i ;
}
return 0;
}
+ 1
Thanx a lot
0
But in the first code I have already done that