BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/index.php)
-   Computer programming for IT (http://bzupages.com/forumdisplay.php?f=27)
-   -   Table of 5-10 Using Nested Loops (http://bzupages.com/showthread.php?t=364)

BSIT07-01 24-04-2008 05:54 PM

Table of 5-10 Using Nested Loops
 
Table of 5-10 Using Nested Loops

Here is the source code for a Nested loop to write the Table of 5 upto 10


Code:

#include
using namespace std;

int tableof=5;
int tablefrom=5;
int tableto=10;
int counter=1;
int main()
    {
    while(tablefrom<=tableto)
        {
        cout<         while(counter<=10)
            {
   
            cout<             counter++;
            }
        tablefrom++;
        tableof++;   
        counter=1;
/*Here we have freed up the counter ,Because we have to use it
 to write the next loop*/
        }
    return 0;
    }


!!Ahmad Mushtaq!! 24-04-2008 06:15 PM

Re: Syntax Error may occur in Wasif's program!
 
Assalam-o-Alaikum!

Hi guys! As usual : I copied Wasif's code and pasted it in my Visual C++.

It gave the following error:
PROBLEM:
Quote:

C:\Program Files\Microsoft Visual Studio\MyProjects\Nested Loop\Wasif's program.cpp(16) : error C2059: syntax error : '<'
SOLUTION:
Please remove the space between the two adjacent '<' after <
cout<

REASON:
When I tried to edit Wasif post, I found no blank space there. May be the problem is because of the way this forum formats the text. Well! There is no need to worry! :peace:

BSIT07-01 24-04-2008 06:25 PM

Re: Table of 5-10 Using Nested Loops
 
Dear Thanks for identifying the Bug,
I've removed the bug now.. What do you think about the method , If you have any other method to solve this problem , Please Share it here.

BSIT07-01 24-04-2008 11:39 PM

Re: Table of 5-10 Using Nested Loops
 
More Precise Form with three Variables Instead of 4

Code:

#include
using namespace std;

int tableof=5;
int tableto=10;
int counter=1;
int main()
    {
    while(tableof<=tableto)
        {
        cout<         while(counter<=10)
            {
   
            cout<             counter++;
            }
       
        tableof++;   
        counter=1;
        }


    return 0;
    }


BSIT07-01 24-04-2008 11:44 PM

Re: Table of 5-10 Using Nested Loops
 
Generalized form to write table of a range

:giggle::bs2:
Code:

#include
using namespace std;

int tableof;
int tableto;
int counter=1;
int main()
    {
    cout<<"Enter the Number from which You want to start Table:";
    cin>>tableof;
    cout<<"Enter the Number UPTO which You want to Write the Table:";
    cin>>tableto;


    while(tableof<=tableto)
        {
        cout<         while(counter<=10)
            {
   
            cout<             counter++;
            }
       
        tableof++;   
        counter=1;
        }


    return 0;
    }


.BZU. 25-04-2008 01:21 AM

Re: Table of 5-10 Using Nested Loops
 
Bhai I really miss you in the C++ class last day..
kisi bhi student ko yeh bnana nahi aya tha , aur mujhko bhi nahi aya ..
But main nay kuch banaya tu liya tha ..
Mujhay yeh samjh nahi aa rahi hay kay yeh aap nay iss main akhir main
Quote:

counter=1;
kiyon likha hay

BSIT07-01 25-04-2008 08:21 AM

Re: Table of 5-10 Using Nested Loops
 
I've Clarified the reason in first post , That is . Counter is the Variable which I used in the Inner While Loop to write the Table , If we don't Give it Value of 1 , The inner loop will not be executed because for that value of counter should be <=10

I think , Now it should be Clear.


All times are GMT +5. The time now is 10:39 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.