Lets say we have a simple problem of Accepting 2 Numerical variables 'X' and 'Y' and an alphabet from the user and print them on the Screen. Now in order to achieve the output we can write the program both in C as well as C++.
In C++ :
#include<iostream.h>
#include<conio.h>
void main( )
{ int x,y;
char a;
cout<<"Enter the First Number to be stored : "<<endl;
cin>>x;
cout<<"Enter the Second Number to be stored: "<<endl;
cin>>y;
cout<<"Enter the alphabet :"<<endl;
cin>>a;
cout<<"The stored data is:<<endl;
cout<<x<<","<<y<<","<<a<<endl;
getch( );
}
In above written program, the program asks the user to enter the 'First Number' and stores it in the Variable 'x'. Similarly, in the second statement, the program asks the user to enter the 'Second Number' and stores it in the Variable 'y'. Lastly, the Alphabet is stored in the Variable 'a'.
The output for the above program as seen in the output screen will be :
Enter the First Number to be stored :
4 ---------> 'Say you enter 4'.
Enter the Second Number to be stored:
7 ---------> 'Say you enter 7'.
Enter the Alphabet :
B ---------> 'Say you enter B'.
The stored data is:
4,7,B
Give this program a Try!!
No comments:
Post a Comment