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

Learn Programming in c++

# include<iostream>uisng namespace std;void main(){cout<<"I am JD"<<endl;}
here

# 

is used for the folder location(c++ compiler automatically known where headers files is)
include is used to inculde some header file in your program(we willl discuss later what is header file)
iostream is the header file.....
It is used for cin & cout etc etc.....
using namespace std;
Namespaces are like drawers in a filing cabinet. All of the standard library is in one drawer, and the only way to get to the stuff in that drawer is to tell C++ where to find it. You do that by prefixing the name with std,
std::cout is basically like saying "Hey C++! Look in  and get me cout, asap!". If you don't tell C++ which drawer to look in, it won't find what you want.
simply,this is used for declaring cin & cout ...
void main()
This is essential for any  c++ program(either it is console application or win32 application)
this is the starting point for any program,without this program the compiler cannot known where to start compling the program....
{
}
left and right braces are used for boundary line of your program...as in football there is a boundary so c and c++  has braces for that
cout
this is used for printing any thing in screen(only for console apps)
the thing which is in inverted commas can be printed..the compile cannot compile inverted commas inner side
this "<<" is,I mean is a operator to print anything on screen as operator for addition is + etc....
endl is used for having a one line space
Plz like my blog and feel free for suggestions