The Syntax for taking input from the user is different in all three languages, so let’s see the syntax and write your first basic code in all the 3 languages.
C
#include <stdio.h>
int main()
{
int a, b, c;
printf ( "first number: " );
scanf ( "%d" , &a);
printf ( "second number: " );
scanf ( "%d" , &b);
c = a + b;
printf ( "Hello World\n%d + %d = %d" , a, b, c);
return 0;
}
|
C++
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cout << "first number: " ;
cin >> a;
cout << endl;
cout << "second number: " ;
cin >> b;
cout << endl;
c = a + b;
cout << "Hello World" << endl;
cout << a << "+" << b << "=" << c;
return 0;
}
|
Python
a = input ( "first number: " )
b = input ( "second number: " )
c = a + b
print ( "Hello World" )
print (a, "+" , b, "=" , c)
|
Comparing Python with C and C++
In the following article, we will compare the 3 most used coding languages from a beginner’s perspective. It will help you to learn basics of all the 3 languages together while saving your time and will also help you to inter shift from one language you know to the other which you don’t. Let’s discuss a brief history of all the 3 languages and then we will move on to the practical learning.