## Posts

Showing posts from June, 2010

### Sample C++ Program To Calculate Final Velocity.

This is a sample C++ Program to calculate final velocity when time, acceleration and initial velocity are given.

#include <iostream.h>
#include <conio.h>

void main()
{
clrscr();
int v,u,a,t;
cout << "Enter The Velocity, Acceleration, Time: " << endl;

cin>>u>>a>>t;
v=u+a*t;
cout << "The Final Velocity Is " << v << "." << endl;
getch();
}

OUTPUT:

Enter The Velocity, Acceleration, Time:
0
5
2

The Final Velocity Is 10.

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++ Program To Check Whether A Number Is Greater Than 100 Or Not…

### C++ Program To Find Area Of The Triangle Using Heron's Formula.

This is a sample C++ program to find the area of a triangle using Heron's Formula.

#include <iostream.h>
#include <conio.h>
#include <math.h>

void main()
{
double s1, s2, s3, ar, s;
cout<< "Enter 3 Sides :";
cin >> s1 >> s2 >> s3;

s = (s1+s2+s3)/2;
ar = sqrt( s * ( s - s1) * (s - s2) * (s - s3));
cout << "\n The Area Of The Triangle = " << ar;
getch();
}

OUTPUT:

Enter 3 sides :
2
2
2

The Area of the triangle = 1.732051

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++ Program To Check Whether A Number Is Greater Than 100 Or Not.
-- C++ Progr…

### C++ Program To Find Sum & Average Of Two Numbers.

This is a sample C++ program to accept two numbers & find it's sum and average.

#include <iostream.h>
#include <conio.h>

void main()
{
clrscr();
int x, y, sum;
float average;

cout << "Enter 2 Integers : " << endl;
cin>>x>>y;
sum=x+y;
average=sum/2;

cout << "The Sum Of " << x << " & " << y << " Is " << sum << "." << endl;
cout << "The Average Of " << x << " & " << y << " Is " <<  average << "." << endl;
getch();
}

OUTPUT:

Enter 2 Integers :
20
40

The Sum Of 20 & 40 Is 60.
The Average Of 20 & 40 Is 30.

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two V…

### Sample C++ Program To Accept A Number ‘n’ & Find Sum Of All Numbers Upto 'n' - 15.

This program accepts a number from the user and finds the sum of all the numbers up to the number entered by the user.

SAMPLE PROGRAM:

#include <iostream.h>

#include <conio.h>

int recursion(int num);

int main()
{

int num = 0;
int sumnum;

cout << "Enter any integer greater than 0: " << endl;
cin >> num;

sumnum = recursion(num);
cout << "The sum is: " << sumnum << endl;

cin.ignore();
cin.get();

return 0;
}

int recursion(int num)
{

int sum = 0;

if(num == 1)
return 1;
else
{
sum = recursion(num - 1) + num;
return sum;
}

}

OUTPUT:

Enter any integer greater than 0: 6
The sum is: 21

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program T…

### Sample C++ Program To Calculate The Greatest Common Divisor Of Two Numbers - 14.

This program accepts two numbers from the user and finds out the greatest common divisor of the two numbers.

SAMPLE PROGRAM:

#include <iostream.h>

#include <conio.h>

int GCD(int a, int b)
{

int remainder;

while( b != 0 )
{
remainder = a % b;
a = b;
b = remainder;
}

return a;

}

int main()

{

int x, y;

cout << "To find the greatest common divisor, enter the values specified below \n";

cout << "Value 1: ";

cin >> x;

cout << "Value 2: ";

cin >> y;

cout << "\nThe Greatest Common Divisor of " << x << " and " << y << " is " << GCD(x, y) << endl;

return 0;

}

OUTPUT:

To find the greatest common divisor, enter the values specified below

Value 1: 20
Value 2: 10

The Greatest Common Divisor of 20 and 10 is 10

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Prog…

### Sample C++ Program To Find The Square Root Of A Number - 13

This program helps to find out the square root of the number entered by the user.

SAMPLE PROGRAM:

#include <iostream.h>

#include <conio.h>

#include <math.h>

int main()

{

clrscr();

int x;

cout << "Enter a number ";

cin >> x;

double y = sqrt(x);

cout << "The square root of " << x << " is " << y << endl;

x++;

return 0;

}

OUTPUT:

Enter a number 4

The square root of 4 is 2

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++ Program To Check Whether A Number Is Greater Than 100 Or Not.
-- C++ Program To Check Whether A Number & It's Log Value Are Greater Than…

### Sample C++ Program To Calculate The Area Of A Rectangle - 12.

This program helps user to find the area of a rectangle. All the user has to do is enter the length and the breadth of the rectangle.

SAMPLE PROGRAM:

#include <iostream.h>

#include <conio.h>

int main()

{

float length;

float width;

float area;

cout << "Enter length of rectangle: ";

cin >> length;

cout << "Enter width: ";

cin >> width;

area = length * width;

cout << "\nArea of rectangle is: " << area << endl;

return 0;

}

OUTPUT:

Enter length of rectangle: 4

Enter width: 3

Area of rectangle is: 12

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++ Program To Check W…

### Sample C++ Program To Check Prime Number - 11.

This program helps to identify whether the number entered by the user is a prime number or not.

SAMPLE PROGRAM:

#include <iostream.h>

#include <conio.h>

void main()
{

clrscr();
int i, flag = 0, n;

cout << "Enter the number: ";
cin >>n;

for(i = 1; i <= n / 2; i++)
{
if(n % i == 0)
flag = 1;
break;
}

if(flag == 1)
cout << "\n Prime Number. ";

else
cout << "\n Not A Prime Number. ";

}

OUTPUT:

Enter the number: 7
Prime Number

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++ Program To Check Whether A Number Is Greater Than 100 Or Not.
-- C++ Program To Check Whether …

### Sample C++ Program To Check Whether A Number & It's Log Value Are Greater Than 10 Or Not - 10.

This program accepts three marks from the user and then the percentage value is printed on the screen.

SAMPLE PROGRAM:

#include <iostream.h>

#include <conio.h>

#include <math.h>

int main()

{

int x, logx;

cout << "Enter an integer: ";

cin >> x;

logx = log(x);

if ( (x < 10) && (logx < 10) )

cout << "x and log(x) are less than 10." << endl;

else

cout << "x and log(x) are not less than 10." << endl;

return 0;

}

OUTPUT:

Enter an integer: 2
x and log(x) are less than 10.

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++ Program To Check Whether A Number I…

### Sample C++ Program To Check Whether A Number Is Greater Than 100 Or Not - 9.

This program accepts a number from the user and checks whether the number is greater than 100 or not.

SAMPLE PROGRAM:

#include <iostream.h>

#include <conio.h>

int main()

{

int x;

cout << "Enter an integer: ";

cin >> x;

if (x < 100)

cout << "X is less than 100" << endl;

else if (x > 100)

cout << "X is greater than 100" << endl;

else if (x == 100)

cout << "X is equal to 100" << endl;

return 0;

}

OUTPUT:

Enter an integer: 54

X is less than 100

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++ Program To Check Whether A Number Is Greater Than …

### Sample C++ Program To Accept Three Numbers & Print Percentage Marks - 8.

This program accepts three marks from the user and then the percentage value is printed on the screen.

SAMPLE PROGRAM:

#include <iostream.h>

#include <conio.h>

int main()

{

clrscr();

float sub1, sub2, sub3, marks, perc;

cout<<"Enter marks obtained in three subjects: ";

cin>> sub1 >> sub2 >> sub3;

marks = sub1 + sub2 + sub3;

perc = (marks / 300) * 100;

cout<<'\n'<<"The percentage marks are: "<<perc <<"%";

return 0;

}

OUTPUT:

Enter marks obtained in three subjects: 90

90

90

The percentage marks are: 90%

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++…

### Sample C++ Program To Accept & Print Marks & Find Total - 7.

This program accept marks for different subjects and then displays the marks and then the total in the screen.

SAMPLE PROGRAM:

#include <iostream.h>

#include <conio.h>

int main()

{

clrscr();

float sub1, sub2, sub3, total;

cout<<"Enter marks obtained in three subjects: ";

cingt;gt; sub1 gt;gt; sub2 gt;gt; sub3;

total = sub1 + sub2 + sub3;

cout<<"The marks obtained are: " <<'\n';

cout<<sub1<<'\n';

cout<<sub2<<'\n';

cout<<sub3<<'\n';

cout<<" Total marks = " << total;

return 0;

}

OUTPUT:

Enter marks obtained in three subjects: 90

92

90

The marks obtained are:

90

92

90

Total marks = 272

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Pro…

### Sample C++ Program To Print Square Of A Numeric Value - 6.

This program allows the user to enter a numeric value and the output will be the square of the value.

SAMPLE PROGRAM:

#include <iostream.h>

#include <conio.h>

int main()

{

clrscr();

int var, sqrs;

cout << "Enter variable: ";

cin >> var;

sqrs = var * var;

cout << '\n'<< "The square is: "<<sqrs;

return 0;

}

OUTPUT:

Enter variable: 5

The square is: 25

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++ Program To Check Whether A Number Is Greater Than 100 Or Not.
-- C++ Program To Check Whether A Number & It's Log Value Are Greater Than 10 Or Not.

-- C++ Program To Check Wh…

### Sample C++ Program To Print Sum Of Two Values - 5.

This program allows user to enter two values and then the sum of the two values will be printed on the screen.

SAMPLE PROGRAM:

#include <iostream.h>

#include <conio.h>

int main()

{

clrscr();

int value1, value2, sum;

cout<<"Enter first value: ";

cin>>value1;

cout<<"Enter second value: ";

cin>>value2;

sum = value1 + value2;

cout<<"The sum of given values is : ";

cout<< sum;

return 0;

}

OUTPUT:

Enter first value: 6

Enter second value: 7

The sum of given values is : 13

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++ Program To Check Whether A Number Is Greater Than 100 Or Not.
-- C++ Program To Check Whether A Number & It's Log Value Are Greater Than 10 Or Not.

-- C++ Program To Check Whether A Number Is Prime Or Not.
-- C++ Program To C…

### Sample C++ Program To Accept & Display A Number.

This program accepts a number from the user and displays it on the screen.

SAMPLE PROGRAM:

#include <iostream.h>

#include <conio.h>

int main()

{

int n;

cout << "Please enter a number: ";

cin >> n;

cout << "The number which you entered is " << n << endl;

getch();

return 0;

}

OUTPUT:

The number which you entered is 3

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++ Program To Check Whether A Number Is Greater Than 100 Or Not.
-- C++ Program To Check Whether A Number & It's Log Value Are Greater Than 10 Or Not.

-- C++ Program To Check Whether A Number Is Prime Or Not.
-- C++ Program To Calculate The Area Of A Rectangle.
-- C++ Program To Find The Square Root Of A Number.
-- C++ Prog…

### Sample C++ Program To Accept & Print The User’s Age

This program lets users to enter their age and prints it on the screen.

SAMPLE PROGRAM:

#include <iostream.h>

int main()

{

int age;

cin >> age;

cout << "You are " << age << " years old." << endl;

return 0;

}

OUTPUT:

You are 40 years old.

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++ Program To Check Whether A Number Is Greater Than 100 Or Not.
-- C++ Program To Check Whether A Number & It's Log Value Are Greater Than 10 Or Not.

-- C++ Program To Check Whether A Number Is Prime Or Not.
-- C++ Program To Calculate The A…

### Sample C++ Program To Output Or Display Any Message/Statement

The following C++ program displays any message or statement that is passed in the program.

SAMPLE PROGRAM 1:

# include <iostream.h>

int main()

{

cout << "Hello C++";

return 0;

}

OUTPUT:

Hello C++

SAMPLE PROGRAM 2:

# include <iostream.h>

int main()

{

cout << "Welcome To C++ Programming World.";

return 0;

}

OUTPUT:

Welcome To C++ Programming World.

ALSO CHECK THE FOLLOWING C++ PROGRAMS:

-- C++ Program To Accept & Print The User’s Age.
-- C++ Program To Print A String.
-- C++ Program To Accept & Display A Number.
-- C++ Program To Print Sum Of Two Values.

-- C++ Program To Print Square Of A Numeric Value.

-- C++ Program To Accept & Print Marks & Find Total.
-- C++ Program To Accept Three Numbers & Print Percentage Marks.
-- C++ Program To Check Whether A Number Is Greater Than 100 Or Not.
-- C++ Program To Check Whether A Number & It's Log Value Are Greater Than 10 Or Not.

-- C++ Program To Check Whether A Number Is Prime Or…