Tuesday, July 19, 2011

Same program in both C and C++

A program that can take variable value from the user and then print the value of that variable.
C Program:-
                            
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int a;
printf("\n Enter the value of a=");
scanf("%d",&a);
printf("\n The value of a= %d",a);
getch();
}


Same Program in C++:-


#include<iostream.h>

#include<conio.h>
void main(void)
{
clrscr();
int a;
cout<<" Enter the value of a="<<endl;
cin>>a;
cout<< The value of a="<<a<<endl;
getch();
}

Output:-

Enter the value of a= 4   
The value of a= 4

No comments:

Post a Comment