Data types in C++
Data types are used during the declaration of a variable which determined the type of data a variable can store. Primarily they are of three types:
- Integer
- Character
- Float
Write a program in C++ giving an idea of primary data types.
We need to consider different variables with different data types. We need to store the input data in their respective variables and print them. This will let us know about different data types.
Program
#include<conio.h>
void main()
{
long int admno;
char name[20];
int age;
float prcnt;
clrscr();
cout<<"Enter your admission number="; //Input part
cin>>admno;
cout<<"Enter your name=";
cin>>name;
cout<<"Enter your age=";
cin>>age;
cout<<"Enter your percentage=";
cin>>prcnt;
cout<<"\nInformation"; //Output part
cout<<"\nAdmission number="<<admno;
cout<<"\nName="<<name;
cout<<"\nAge="<<age;
cout<<"\nPercentage="<<prcnt<<"%";
getch();
}
Explanation
In the program, each variable has own data type and stores a particular value only. The float data type is used to store percentage as it is a decimal number. The int data type can't store decimal so a float data type is used. The char data type is used to store characters and symbols.
// is used to add a comment. It starts from // and ends at end of a line.
// is used to add a comment. It starts from // and ends at end of a line.
No comments:
Post a Comment