### table of numbers from 50 to 150

in this we have to show table of 50 to 150
like 50 table from 1 to 10
then 51 table ......150 table
i just want to know is there any way i can get this using loop not using nested loop
i made the nested loop code to show you what i want on ouput
 1234567891011121314151617181920 #include #include void main() { int num; cout<
Last edited on
A couple of things.

You must be using an old or out of date compiler. To be standard-compliant, the include file you want is <iostream>, not <iostream.h>, and you will need to use std::cout and std::endl (or using namespace std;). Also, main() must return an int, not void.

Anyway, you do not have a nested loop. You have 2 loops running concurrently. A nested loop would be:

 1234567891011121314 #include using namespace std; int main() { int num; cout<
i accidentally paste the wrong code sorry
now its correct
i just need to know that can i achieve the output without using nested loop
I don't think you can. If you want to get every combination of i and j, you need to nest the loops.
Could you show how the output shall look?
 50 * 1 =50 50 * 2 =100 50 * 3 =150 50 * 4 =200 50 * 5 =250 50 * 6 =300 50 * 7 =350 50 * 8 =350 50 * 9 =450 50 * 10 =500 51 * 1 =51 51 * 2 =102 51 * 3 =153 51 * 4 =204 51 * 5 =255 51 * 6 =306 51 * 7 =357 51 * 8 =408 51 * 9 =459 51 * 10 =510

it will continue to 150 table
Last edited on
If you're dead set on not using nested loops, then you could probably kludge it with some fiddly maths and a bunch of if statements. But why would you bother? Using nested loops is much simpler and cleaner.
@tjnapster555

Here is one way to do the table and NOT use a nested loop, though I guess a while loop may constitute to be type of nested loop. Anyway, here it is..

 1234567891011121314151617181920212223242526 // Table.cpp : main project file. #include #include int main() { int num,j=1; std::cout << std::endl; for(int i=50;i<=150;i++) { if (j=1) std::cout<<"\tTable of "<
 @itenite1
It is obvious that your code has a nested loop.
Am I missing something, or is everyone humping this doorknob on purpose?
 1234567891011121314 for(int i = 50; i <= 150; i++) { int j = 1; std::cout << i << " * " << j << " = " << i * j << std::endl; j++; // 1 std::cout << i << " * " << j << " = " << i * j << std::endl; j++; // 2 std::cout << i << " * " << j << " = " << i * j << std::endl; j++; // 3 std::cout << i << " * " << j << " = " << i * j << std::endl; j++; // 4 std::cout << i << " * " << j << " = " << i * j << std::endl; j++; // 5 std::cout << i << " * " << j << " = " << i * j << std::endl; j++; // 6 std::cout << i << " * " << j << " = " << i * j << std::endl; j++; // 7 std::cout << i << " * " << j << " = " << i * j << std::endl; j++; // 8 std::cout << i << " * " << j << " = " << i * j << std::endl; j++; // 9 std::cout << i << " * " << j << " = " << i * j << std::endl; // 10 }
Last edited on
 123456789101112 #include #include int main() { for ( int n = 1, i = 50; i <= 150; i += n / 10, n = n % 10 + 1 ) { std::cout << std::setw( 3 ) << i << " * " << std::setw( 2 ) << n << " = " << std::setw( 4 ) << i * n << std::endl; } }
Last edited on
Topic archived. No new replies allowed.