C++ "Hello, World!" Program
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello, World!";
return 0;
}
C++ Program Add Two Integers
#include<iostream>
using namespace std;
int main()
{
int number1, number2, sum;
cout << "Enter two integers: ";
cin >>number1 >> number2;
sum = number1 + number2;
cout << "sum is"<< number1 << " + " << number2 << " = " << sum;
return 0;
}
C Program to Compute Quotient and Remainder
#include<iostream>
using namespace std;
int main()
{
int dividnd, divisor, quotient, remainder;
cout<<"Enter dividend:";
cin>>dividnd;
cout<<"Enter divisor: ";
cin>>divisor;
quotient = dividnd / divisor;
remainder = dividnd % divisor;
cout<<"Quotient = "<< quotient;
cout<<"Remainder = "<< remainder;
return 0;
}
Write a program to enter mark of 6 different subjects and find out the total mark (Using
cin and cout statement)
#include<iostream>
using namespace std;
int main()
{
int sub1,sub2,sub3,sub4,sub5,sub6,total;
cout<<"enter marks of sub1";
cin>>sub1;
cout<<"enter marks of sub2 ";
cin>>sub2;
cout<<"enter marks of sub3";
cin>>sub3;
cout<<"enter marks of sub4";
cin>>sub4;
cout<<"enter marks of sub5";
cin>>sub5;
cout<<"enter marks of sub6";
cin>>sub6;
total=sub1+sub2+sub3+sub4+sub5+sub6;
cout<<"Total is"<< total;
return 0;
}
C++ Program to Swap Two Numbers.
#include<iostream>
using namespace std;
int main()
{
int num1, num2, temp;
cout<<"Enter 1st Number: ";
cin>>num1;
cout<<"Enter 2nd Number: ";
cin>>num2;
cout<<"Before Swapping: 1st Number: "<< num1 <<" 2nd Number: "<< num2;
temp=num1;
num1=num2;
num2=temp;
cout << "\nAfter swapping." << endl;
cout << "1st Number: "<< num1 <<" 2nd Number: "<< num2;
return 0;
}