Display a table of numbers from 50 to 150

using for loop
Please show us your code, and explain more specifically what problem you're having with it.
i cannot understand what to do in this i mean do i have to show the table of any no. lets say 2 and show its table from 50 to 150 or

i need to show table of every number from 50 to 150
i cant understand this question just explain it to me please.
Perhaps you should seek clarification from the person who assigned the question to you.
Only the person who set the question knows what they really mean.

It sounds like they just want a list of numbers from 50 to 150, but I wouldn't use the word "table" to describe that.
This is how you'd do it for a table of numbers from 0 to 9. I'll leave it to you to figure out how 50 to 150 would work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>

char table[] =
"    ######################################\n   ####"
"###################################\n  ############"
"########################## #\n ####################"
"##################  #\n############################"
"##########   #\n#   #                              "
"  #   #\n#   #                                #   #"
"\n#                                    #\n#        "
"                            #\n#                   "
"                 #\n#                              "
"      #\n" ;

int main()
{
    unsigned num = 0 ;
    for ( unsigned i=0; i<sizeof(table)-1; ++i )
    {
        if ( table[i] == '#' )
            (std::cout << num), num = (num+1) % 10 ;
        else
            std::cout << table[i] ;
    }
}
That is quite creative cire, it is definitely a very realistic looking table.
http://ideone.com/CSDk9N
using nested loop i made this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream.h>
#include<conio.h>
void main()
{
int num;
cout<<endl;
for(int i=50;i<=150;i++)
{
	cout<<"\tTable of "<<i<<endl<<endl;
	for(int j=1;j<=10;j++)
	{

   cout<<"\t"<<i<<" * "<<j<<" = "<<(i*j)<<endl;

   }
   cout<<endl;
   getch();
   }
getch();
}
}

but i want to know that can i do this using loop only not nested loop.
Last edited on
So, basically, for each number from 50 to 150, you're printing out that number's multiplication table? I don't see that implied by the question you've posted, but it's not a bad thing to do.

A nested loop is by far the most sensible way to do it.
For one thing, he's using <iostream.h> and <conio.h> which are both nonstandard.
I am using iostream.h and conio.h its because we are using Borland turbo 3.0 I know the new compiler syntax but I am studying now that's why I am using old compiler but I am asking that It could be possible to get this output without nested loop just answer this question and you guys think it could be possible to get output without using nested loop then explain it to me


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
I'm not sure which is the "more active" thread on this problem currently, whether this one (here) or this one
http://www.cplusplus.com/forum/general/97824/#msg526009

Guess I'll post here.
If I had to do it in one loop only I would let i go from 501 to 1510 then find the product of i/10 with i%10.
Watch out for cases like this one though: 50 * 10 =500, which would turn out as 51*0. A test for this case (i%10==0) and corrective code would be needed.
Last edited on
I get it and the last guy fun2code don't no what he saying if you explaint it to me a little bit more
but the answer is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream.h>
#include<conio.h>
void main()
{
for(int i=50;i<=150;i++)
{
cout<<"Table of "<<i<<endl<<endl;
cout<<i<<"  *  1"<<" = "<<i*1<<endl;
cout<<i<<"  *  2"<<" = "<<i*2<<endl;
cout<<i<<"  *  3"<<" = "<<i*3<<endl;
cout<<i<<"  *  4"<<" = "<<i*4<<endl;
cout<<i<<"  *  5"<<" = "<<i*5<<endl;
cout<<i<<"  *  6"<<" = "<<i*6<<endl;
cout<<i<<"  *  7"<<" = "<<i*7<<endl;
cout<<i<<"  *  8"<<" = "<<i*8<<endl;
cout<<i<<"  *  9"<<" = "<<i*9<<endl;
cout<<i<<"  *  10"<<" = "<<i*10<<endl;
getch();
}
getch();
}
But I'm forced to ask the same question as I asked in the other thread: why? Using the nested loop is much better.
I was thinking of something like this:
1
2
3
4
5
6
7
for(int i=501; i <= 1510; ++i)
{
    if( i%10 == 0 )
        cout << i/10 - 1 << " * 10 = " << (i/10 - 1)*10 << endl;
    else
        cout << i/10 << " * " << i%10 << " = " << (i/10)*(i%10) << endl;
}

But your solution seems fine.

I agree with MikeyBoy. A nested loop is a natural fit for this problem.
Is the single loop an assigned requirement?

EDIT: Better,
1
2
for(int i=500; i <= 1509; ++i)
        cout << i/10 << " * " << (i%10 + 1) << " = " << (i/10)*(i%10 + 1) << endl;
Last edited on
Topic archived. No new replies allowed.