+ 3
how to create multiplication table using 'while' with input number
how can u create multiplication table by inputting any number and get its multiplication table . ex. int no =2 while(no<22){ cout<<number <<no <<endl; no+=2 } output 2 ,4,6,8...,20 so how can i take any value as 'no' and create its multiplication table ?
2 Antworten
+ 7
Would be shorter with a for loop.
int n; cin >> n;
for (int i = 0; i < 22; i++)
cout << n << "*" << i << " = " << n*i << endl;
// which is the equivalent of
int n, i = 0; cin >> n;
while (i < 22) {
cout << n << "*" << i << " = " << n*i << endl;
i++;
}
// ... doesn't really look like much of a difference now, does it.
+ 6
Replace 'int no=3' with 'no = Input()', the user will then define 'no'