0% found this document useful (0 votes)
3 views4 pages

Introduction To C++

The document provides an introduction to C++ programming with examples comparing C and C++. It includes code snippets for printing 'Hello World', adding two numbers, and calculating the square root of a number. Each example highlights the differences in syntax and functions between C and C++.

Uploaded by

Nika
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Introduction To C++

The document provides an introduction to C++ programming with examples comparing C and C++. It includes code snippets for printing 'Hello World', adding two numbers, and calculating the square root of a number. Each example highlights the differences in syntax and functions between C and C++.

Uploaded by

Nika
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to C++

Hello World
#include<stdio.h> #include<iostream>

int main() int main()


{ {
printf(“Hello world in C.”); std::cout<<“Hello world in C++”;
printf(“\n”); std::cout<<“\n”;

return 0; return 0;
} }
Addition of two numbers
#include<stdio.h> #include<iostream>
int main() int main()
{ {
int a, b, sum; int a, b;
printf(“Input two numbers:\n”); std::cout<<“Input two numbers:\n”;
scanf(“%d %d”, &a, &b); std::cin>>a>>b;
sum = a+b; int sum = a+b;
printf(“Sum of %d and %d ”, a, b); std::cout<<“Sum of”<<a<<“and”<<b;
printf(“is: %d\n”, sum); std::cout<<“is:”<<sum<<“\n”;
return 0; return 0;
} }
Square Root of a number
#include<stdio.h> #include<iostream>
#include<math.h> #include<cmath>
int main() using namespace std;
{ int main()
double x, sqrt_x; {
printf(“Input number:\n”); double x;
cout<<“Input number:\n”;
scanf(“%lf”, &x);
cin>>x;
sqrt_x = sqrt(x);
double sqrt_x = sqrt(x);
printf(“Sq. Root of %lf is:”, x);
cout<<“Sq. Root of”<<x<<“is:”;
printf(“%lf\n”, sqrt_x); cout<<sqrt_x<<“\n”;
return 0; return 0;
} }

You might also like