Data types in c++

Variable:-
A variable is a value that can change during the execution of program.

Constant :-
Constant are the value that remain fix at run time.

Types of data :-

Integers
The integers can store only numbers (digits) without decimal point. Normally this type of data is used for counting purpose. The maximum limit of integer is 32,667.

Long
Long data is used for very long number.

Float
This type of data can store numbers with decimal point. This type of data is used for measurement purpose .

Character
This type of data is can store alphabets and other character.
Examples of integers

Addition
#include<iostream.h>
int main()
{
int a,b;
a=10;
b=5;
cout<<"\n"<<" Sum = "<<a+b;
system("pause");
return 0;
}

Examples of long


#include<iostream.h>
int main()
{
long a,b;
a=1547864;
b=1478954;
cout<<"\n"<<" Sum = "<<a+b;
system("pause");
return 0;
}

Example of float

#include<iostream.h>
int main()
{
float a,b,c;
a=3.5;
b=3.2;
c=a+b;
cout<<"\n"<<" Sum = "<<c;
system("pause");
return 0;
}


Write a program that accept the three integers from the user and display their sum?

#include<iostream.h>
int main()
{
int num1,num2,num3,sum;
cout<<"\n"<<" Enter first number = ";
cin>>num1;
cout<<"\n"<<" Enter second number = ";
cin>>num2;
cout<<"\n"<<" Entera third number = ";
cin>>num3;
sum=num1+num2+num3;
cout<<"\n\n"<<" Sum = "<<sum;
system("pause");
return 0;
}

Write a program that accept the three integers from the user and display their multiply?
#include<iostream.h>
int main()
{
long num1,num2,num3,mul;
cout<<"\n"<<" Enter first number = ";
cin>>num1;
cout<<"\n"<<" Enter second number = ";
cin>>num2;
cout<<"\n"<<" Entera third number = ";
cin>>num3;
mul=num1*num2*num3;
cout<<"\n\n"<<" Mul = "<<mul;
system("pause");
return 0;
}

Write a program that accept the two integers from the user and display their subtraction?
#include<iostream.h>
int main()
{
int num1,num2,sub;
cout<<"\n"<<" Enter first number = ";
cin>>num1;
cout<<"\n"<<" Enter second number = ";
cin>>num2;
sub=num1-num2;
cout<<"\n\n"<<" Sub = "<<sub;
system("pause");
return 0;
}

Write a program that accept the two integers from the user and display their division?

#include<iostream.h>
int main()
{
float num1,num2,divide;
cout<<"\n"<<" Enter first number = ";
cin>>num1;
cout<<"\n"<<" Enter second number = ";
cin>>num2;
divide=num1/num2;
cout<<"\n\n"<<" Divide = "<<divide;
system("pause");
return 0;
}

Write a program to find area?
#include<iostream.h>
int main()
{
float length,breadth,area;
cout<<"\n"<<" Enter length = ";
cin>>length;
cout<<"\n"<<" Enter breadth = ";
cin>>breadth;
area=length*breadth;
cout<<"\n\n"<<" Area = "<<area;
system("pause");
return 0;
}

Write program that accept temperature in centigrade and convert it into Fahrenheit?
#include<iostream.h>
int main()
{
float c,f;
cout<<"\n"<<" Enter a Temperature in Centigrade = ";
cin>>c;
f=(1.8*c)+32;
cout<<"\n\n\n"<<" Temperature in Fahrenheit = "<<f;
system("pause");
return 0;
}

Example of character

Simple program
#include<iostream.h>
int main()
{
char a;
cin>>a;
cout<<a;
system("pause");
return 0;
}




Write program that accept character and convert it into ASCII code ?

#include<iostream.h>
int main()
{
char a;
clrscr();
cin>>a;
cout<<(int)a;
system("pause");
return 0;
}


1 comments:

Nice Article..... Keep It Up Bro