Monday, 28 October 2013

Table in c++ with help of For loop

# include<iostream.h>
using namespace std;
void main()
{
int a,i;
cout<<"Enter Number";
cin>>a;
for(i=1;i<=10;i++)
{
cout<<a<<"*"<<i<<"="<<a*i<<endl;
}

}

Now,
We will explain this program,
First we take two integers,(Find all data members ranges at:-http://www.jdrana.blogspot.com/2013/10/add-numbers-in-c.html)
then we will take one input from user and save it in a variable,
When for loop starts ,i is equal to one ,then condition is check and 1 is less then 10 so for loop enters into its body and prints,
(Consider we will give input 2)
2*1=2
then control goes to next line due to endl(endl is used for one line space)
then i will be incremented and condition is again check
(How For loop works:-http://www.jdrana.blogspot.com/2013/10/include-include-void-main-int-i-fori0i.html)
So,
the Output is:-
2*1=2
2*2=4
2*3=6
2*4=8
2*5=10
2*6=12
2*7=14
2*8=16
2*9=18
2*10=20
Fell free to give Suggestions.......!

0 comments: