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.......!

Wednesday, 23 October 2013

For Loop

# include<iostream>
# include<conio.h>
void main()
{
int i;
for(i=0;i<9;i++)
cout<<"i am JD";

}
In this program,we will discuss how for loop works in c++......!
for(i=0;
what is this??
here we simply declare i to 0...
then we i<9
this is condition this for loops works when i is less then 9
and at last i++;
this is the increment operator we discuss in previous post...
first i will become zero then the condition will check if the condition is true then the loop prints whatever type in next line or compiler will do what is on next line.....!
Note:
if single line you want to execute with for loop then brackets cannot be needed,but if you make two lines or more then,then to execute with for loop then you will put brackets ....)
after doing what is in the brackets(if two or more lines are),then the loop go to the last one(i++),here i will be incremented and then i will become 1 then a condition will again check either it is less thhen 9 or not.if it is,then loop body will execute otherwise not...
Output is:-
i am JD
i am JD
i am JD
i am JD
i am JD
i am JD
i am JD
i am JD
i am JD
i am JD
Fell free to give suggestions in comment box

Increment and decrement

# include<iostream>
using namespace std;
void main()
{
int a;
cout<<"Enter a";
cin>>a;
a++;
cout<<a;
a--;
cout<<a;
}
here we will take any value from the user and that value is save in a...
then a will be incremented
Incremented mean to add one more to some variable like here a++ mean if a==1 then after incremented a will be 2...
after printing a on screen a will be decremented like a--;
Decremented mean to minus one to some variable like here a-- if a==2 ten after decremented a will be 1;
Your Suggestions will help us,so plz give suggestions in comment box
or feel free to share any problem

Saturday, 19 October 2013

Add numbers in C++

# include<iostream>
using namespace std;
void main()
{
int a,b,c;
cout<<"enter first number"<<endl;
cin>>a;
cout<<"Enter second number";
cin>>b;
c=a+b;
cout<<"The sum is"<<c<<endl;
}
here,
int is used for  integer (positive and negative)type....
here are all c++ data types and there ranges
signed char: -127 to 127 (note, not -128 to 127; this accommodates 1's-complement platforms)
unsigned char: 0 to 255
"plan" cha: -127 to 127 or 0 to 255 (depends on default char signedness)
signed short: -32767 to 32767
unsigned short::0 to 65535
signed int: -32767 to 32767
unsigned int: 0 to 65535
signed long:-2147483647 to 2147483647
unsigned long 0 to 4294967295
signed long long: -9223372036854775807 to 9223372036854775807
unsigned long long:0 to 184467440737095516
then,
cin is used for saving the required data type a value.
and 
c=a+b;
if a=4,b=4;
then c=8;
so,the answer is 8
Plz like my blog and feel free for suggestions