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; }

8th Oct 2020, 5:27 AM
Uttaran Das
Uttaran Das - avatar
5 Respostas
+ 7
Just rearrange the statements in while loop to do calculations before printing: https://code.sololearn.com/c0k29GsOhOH0/?ref=app
8th Oct 2020, 5:40 AM
A C K
A C K - avatar
+ 5
To avoid 0, initialize i with 1 int i=1, mult;
8th Oct 2020, 5:30 AM
A C K
A C K - avatar
+ 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; }
8th Oct 2020, 6:11 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Thanx a lot
8th Oct 2020, 5:41 AM
Uttaran Das
Uttaran Das - avatar
0
But in the first code I have already done that
8th Oct 2020, 5:33 AM
Uttaran Das
Uttaran Das - avatar