Sie sind auf Seite 1von 37

MODULE - 6 : SKILL ORIENTATION:

1. WRITE A PROGRAM IN C++ TO DISPLAY A MESSAGE :


/* Display a message*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout <<"Welcome to C++ Programing\n";
cout <<"Welcome to Davangere University \n";
cout <<"Welcome to Tolahunase \n" ;
getch();
}
Output:
Welcome to C++ Programing
Welcome to Davangere University
Welcome to Tolahunase

2. WRITE A PROGRAM IN C++ TO DISPLAY MESSAGES:


/* Display a message*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"Davangere University fourth semester CBCS B.Com. degree:\n";
cout <<"Every student must and should study C++ language for future needs:\n";
getch();
}
Output :
Davangere University fourth semester CBCS B.Com degree:
Every student must and should study C++ language for future needs:

1
3. PROGRAM TO IN C++ TO DISPLAY THE MESSAGE IN THE FOLLOWING FORMAT:
/* To display the massage as in the following format*/
WELCOME
To
C++

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout <<"WELCOME\n";
cout <<"To\n";
cout <<"C \n";
getch();
}
Output:
WELCOME
To
C++

4. WRITE A PROGRAM IN C++ TO SUM OF TWO NUMBERS I.E. 200 AND 400:
/* To sum of two numbers*/
#include<iostream.h>
#include<conio.h>
void main()
{
int a , b, sum;
clrscr();
a =200, b=400;
sum = a + b;
cout <<"sum of two numbers is: << sum;
getch();
}
Output:
Sum of two numbers is 600

2
5. WRITE A PROGRAM IN C++ TO SUM OF THREE NUMBERS :
/*To sum of three numbers*/
#include<iostream.h>
#include<conio.h>
void main()
{
int a = 10, b = 20, c = 30, sum;
clrscr();
sum = a + b + c;
cout <<"sum of three numbers is: " << sum;
getch();
}
Output:
sum of three numbers is 60

6. WRITE A PROGRAM IN C++ TO MULTIPLY OF THREE NUMBERS:


/* to multiply of three numbers*/
#include<iostream.h>
#include<conio.h>
void main()
{
int a = 10, b =20, c =30, multiply;
clrscr();
multiply = a * b * c ;
cout <<"multiply of three numbers is:” <<multiply;
getch();
}
Output:
Product of three numbers is 6000

7. WRITE A PROGRAM IN C++ TO SUM AND SUBTRACTION OF THREE NUMBERS:


/* sum and subtraction */
#include <iostream.h>
#include <conio.h>
void main()
{
int x = 300, y = 200, z = 100, sum, subtraction;
clrscr();
3
sum =x + y + z;
subtraction = x – y - z;
cout <<"Sum of three numbers is\n:" << sum;
cout <<"Subtraction of three numbers \n:"<< sub;
getch();
}
Output:
Sum of three numbers is 600
Subtraction of three numbers is 100

8. PROGRAM TO SUM, SUBTRACTION, MULTIPLICATION AND DIVISION OF TWO


NUMBERS (ARITHMETIC FUNCTIONS):
/* Addition, subtraction, multiplication and division*/
#include <iostream.h>
#include <conio.h>
void main()
{
int a = 60, b = 50, sum, subtraction, product;
float division;
clrscr();
sum = a + b;
subtraction = a - b;
product = a * b;
division = a / b;
cout << "Sum is \n: " << sum;
cout << "subtraction is \n:" << subtraction;
cout << "Product is \n:" << product;
cout << "Division is \n: " << division;
getch();
}
Output:
Sum is 110
Difference is 10
Product is 300
Division is 1.2

4
9. PROGRAM TO CALCULATE ARITHMETIC FUNCTIONS AND AVEREAGE OF FOUR
NUMBERS:
/* Program to calculate arithmetic functions*/
#include <iostream.h>
#include <conio.h>
void main()
{
int a = 50, b = 40, c =30, d = 20, sum, sub, mul;
float div, avg;
clrscr();
sum = a + b + c + d;
sub = a - b;
mul = a * b * c * d;
div = a/b;
avg = (a + b + c + d)/4;
cout <<"sum is \n: "<< sum;
cout << "substraction is \n: " << sub;
cout << "product is \n:" << mul << endl;
cout <<"division is \n:" << div <<endl;
cout <<"average is \n:" << avg << endl;
getch();
}

10. PROGRAM TO FIND MARKS STATEMENT A STUDENT:


/* Program to find student marks a statement*/
#include <iostream.h>
#include <conio.h>
void main()
{
int fa, itb, brf, it, total;
float avg;
clrscr();
fa =96;
itb =85;
brf =75;
it =89;
total = fa + itb + brf +it;
avg = total /4.00;
5
cout << total << “, “<< avg;
getch();
}
Output:
Total 345
Sum 86.25

11. PROGRAM TO FIND EMPLOYEE SALARY:


/* Program to find employee salary*/
#include <iostream.h>
#include<conio.h>
void main()
{
char name [20];
int empnum;
int bs =60000;
int da, hra, cca;
int pf, it, gs, ded, ns;
clrscr ();
da = bs * 90 / 100;
hra = bs * 9 / 100;
cca = bs * 4 / 100;
gs = bs + da + hra + cca;
pf = gs * 3 / 100;
it = gs * 30 / 100;
ded = pf + it;
ns = gs - ded;
cout <<"Employee name \n: " << name;
cout << "Employee code number \n: " << empnum;
cout << "Gross salary is \n: " << gs;
cout << "Total deduction \n: " << ded;
cout << "Net salary is \n: " << ns;
getch();
}
Output:
Employee name
Employee code number

6
Gross salary is
Total deduction is
Net salary is

Cout <<:
It is one of the features of C++ language. The cout << is an object oriented built in function. The
cout pronounced as ‘C out’ is a predefined object and it an output statement. The operator << is
called the insertion operator. The cout << included in iostream.h.
Syntax: cout << string;

Cin >>:
It is an input statement and causes the program to wait for the user to type in a number. The operator
>> is known as extraction operator. It is called predefined object. It is used to accept the values from
the key board into predefined variables. This is used to accept numeric, character and string type of
data. It is included in iostream.h .
Syntax: cin >> number 1;
======================================================================
12. PROGRAM TO ADD THREE NUMBERS BY USING INPUT:
/* Add Three Numbers*/
#include <iostream.h>
#include <conio.h>
void main()
{
int a, b, c, add;
clrscr();
cout <<"Enter a first number:\n";
cin >> a;
cout << "Enter a second number:\n";
cin >> b;
cout << "Enter a third number:\n";
cin << c ;
add = a + b + c;
cout << "sum of three numbers is :” << add;
getch();
}
ouyput:
Enter a first number
10
Enter a second number
20
Enter a third number
30
Sum of three number 60

7
13. PROGRAM TO MULTIPLY THREE NUMBERS BY USING INPUT:
/* Program to multiply three numbers*/
#include <iostream.h>
#include<conio.h>
void main()
{
int a, b, c, prod;
clrscr();
cout << "Enter a first number\n:”;
cin >> a ;
cout << "Enter a second number\n:”;
cin >> b ;
cout << "Enter a third number\n:”;
cin >> c ;
prod = a * b * c;
cout << "Product of three numbers is \n:" << prod ;
getch();
}
output:
Enter a first number
2
Enter a second number
4
Enter a third number
5
Product of three numbers is 40

14. PROGRAM TO CALCULATE SQUARE OF A NUMBER:


/*Program to find square of a number*/
#include<iostream.h>
#include<conio.h>
void main()
{
int n, square;
clrscr();
cout << "Enter a number\n" ;
cin >> n;
square = n * n ;
cout << "Square of number is : “ << square;
getch();
}

8
Output:
Enter a number
6
Square of number is 36

15. PROGRAM TO FIND CUBE OF A NUMBER:


/*program to find cube of a number*/
#include <iostream.h>
#include <conio.h>
void main()
{
int n, cube;
clrscr();
cout << "Enter a number\n" ;
cin >> n;
cube = n * n * n ;
cout << "cube of number is : “ << cube;
getch();
}
Output:
Enter a number
5
Cube of a number is 125

16. PROGRAM TO FIND SQUARE, CUBE, FOURTH AND FIFTH A NUMBER BY USING
INPUT:
/* Program a find square, cube, fourth and fifth a number */
#include <iostream.h>
#include <conio.h>
void main()
{
int n, square, cube, fourth, fifth;
clrscr();
cout << “ Enter a number \n";
cin >> n;
square = n * n;
cube = n * n * n;
fourth = n * n * n * n;
fifth = n * n * n * n * n;
cout << “ squre is: “ << square;
cout << “ cube is: “ << cube;
cout << “ fourth is: “ << fourth;
cout << “ fifth is: “ << fifth;
getch();
}
Input:
Enter a number
5
Output:
square is 25
cube is 125
fourth is 625
fifth is 3125

9
17. PROGRAM TO FIND AREA OF A CIRCLE:
/* Program to find area of a circle*/
#include<iostream.h>
#include<conio.h>
void main()
{
int radius;
float circle;
clrscr();
cout << “ Enter a radius : \n" ;
cin >> radius ;
circle = 3.142 * radius * radius;
cout << “ Area of a circle is : “ << circle;
getch();
}

18. PROGRAM TO FIND CIRCUMFERENCE OF A CIRCLE:


/*Program to find circumference of a circle*/
#include <iostream.h>
#include <conio.h>
void main()
{
int r;
float circumference;
clrscr();
cout << “ Enter radius: \ n" ;
cin >> r ;
circumference = 2 * 3.142 * r;
cout << “ circumference of a circle is : “ << circumference ;
getch();
}

19. PROGRAM TO FIND AREA OF CIRCLE AND CIRCUMFERENCE OF CIRCLE IN A


SINGLE PROGRAM:
/* Program find area of a circle and circumference of a circle*/
#include<iostream .h>
#include<conio.h>
void main()
{
float r, circle, circum;
clrscr();
10
cout << “ Enter a radius : \n “ ;
cin >> r ;
circle = 3.142 * r * r;
circum = 2 * 3.142 * r;
cout << "Area of circle is : \n"<< circle ;
cout << "Area of circumference is: “ << circum ;
getch();
}

20. PROGRAM TO FIND AREA OF A RECTANGLE BY USING INPUT:


/* Program to find area of a rectangle*/
#include <iostream.h>
#include <conio.h>
void main()
{
int l, b, rectangle;
clrscr();
cout << "Enter a length\n";
cin >> l ;
cout << "Enter a breadth\n";
cin >> b ;
rectangle = l * b ;
cout << "area of a rectangle is : " << rectangle ;
getch();
}
Input:
Enter a length
12
Enter a breadth
8
Area of rectangle is 96

21. PROGRAM TO FIND AREA OF A TRIANGLE BY USING INPUT:


/* Program to find area of a triangle*/
#include <iostream.h>
#include <conio.h>
void main()
{
float base, height, triangle;
clrscr();
cout << "Enter a base: \n";
cin >> base ;
11
cout << “ Enter height: \n" ;
cin >> height ;
triangle = 0.5 * base * height;
cout << "Area of a triangle is: \n"<< triangle ;
getch();
}

22. PROGRAM TO FIND AREA OF RECTANGLE AND TRIANGLE IN A SINGLE PROGRAM :


/*Program to find area of rectangle and triangle */
#include <iostream.h>
#include <conio.h>
void main()
{
float l, b, base, height, rectangle, triangle;
clrscr();
cout << "Enter length:\n" ;
cin >> l ;
cout << "Enter breadth:\n" ;
cin >> b ;
cout << "Enter height:\n" ;
cin >> height ;
cout << "Enter base:\n" ;
cin >> base ;
rectangle = l * b ;
triangle = 0.5 * base * height;
cout << "Area of rectangle is: \n" << rectangle ;
cout << "Area of triangle is: \n" << triangle ;
getch();
}

23. PROGRAM TO FIND AREA OF CIRCLE, CIRCUMFERENCE, RECTANGLE AND TRIANGLE IN A SINGLE PROGRAM :
/* Program find area, circumference of circle, rectangle and triangle */
#include <iostream.h>
#include <conio.h> a
void main()
{
float r, circle, cir, l, b, base, height, rectangle, triangle;
clrscr()
12
cout << "Enter a radius:\n";
cin >> r ;
cout << "Enter length:\n" ;
cin >> l ;
cout << "Enter breadth:\n" ;
cin >> b ;
cout << "Enter height:\n" ;
cin >> height ;
cout << "Enter base: \n" ;
cin >> base ;
circle = 3.142 * r * r;
cir = 2 * 3.142 * r;
rectangle = l * b ;
triangle = 0.5 * base * height;
cout << "Area of circle is: \n" << circle ;
cout << "Area of circumference is: \n" << cir ;
cout << "Area of rectangle is: \n" << rectangle ;
cout << "Area of triangle is: \n" << triangle ;
getch();
}

24. PROGRAM TO CALCULATE SIMPLE INTEREST:


/* Program to calculate simple interest */
#include<iostream.h>
# include <math.h>
void main()
{
int p, t, r ;
float si, amt;
clrscr();
cout << "Enter principal amount: \n" ;
cin >> p ;
cout << "Enter time : \n" ;
cin >.> t ;
cout << "Enter rate of interest:\n" ;
cin >> r ;
si = ( p * t * r ) / 100;
amt = p + si ;
cout << "Simple interest is: \n" << si ;
cout << "Total amount is: \n" << amt ;
getch();
}

13
25. PROGRAM TO CALCULATE COMPOUND INTEREST:
/* Program to calculate compound interest */
#include <iostream.h>
#include <conio.h>
# include <math.h>
void main()
{
int p, t, r;
float ci, amt;
clrscr();
cout << "Enter principal amount: \n" ;
cin >> p ;
cout << "Enter time : \n" ;
cin >> t ;
cout << "Enter rate of interest:\n" ;
cin >> r ;
ci = p * pow ( ( 1 + r / 100.0 ) , t );
cout << "compound interest is: \n" << ci ;
getch();
}

26. PROGRAM TO CALCULATE SIMPLE AND COMPOUND INTEREST IN A SINGLE PROGRAM:


/* Program to find simple and compound interest */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float p, t, r, ci, si;
clrscr();
cout << "Enter principal amount: \n" ;
cin >> p ;
cout << "Enter time : \n" ;
cin >> t ;
cout << "Enter rate of interest:\n" ;
cin >> r ;
si = ( p * r * t ) / 100;

14
ci = p * pow ( ( 1 + r / 100.0 ) , t );
cout << "simple interest is : \n" << si ;
cout << "compound interest is: \n" << ci ;
return();
}

27. PROGRAM TO SOLVE A 2 + B 2 :


/* Program to solve a 2 and b 2 */
#include <iostream.h>
#include <conio.h>
void main()
{
int a, b, m;
clrscr();
cout << "Enter any 2 numbers: \n" ;
cin >> a >> b ;
m = (a * a) + (b * b);
cout << "The m value is : \ n" << m ;
return();
}

28. PROGRAM TO SOLVE 2P2 + 3P +1:


/*Program to solve 2p2 + 3p + 1*/
#include<iostream .h>
#include<conio.h>
main()
{
int p, m;
clrscr();
cout << "Enter a value: \n" ;
cin >> p ;
m = 2 * p * p + 3 * p + 1;
cout << " The value is: \n" << m ;
getch();
}

15
29. PROGRAM TO SOLVE 2 X 2 + 3 X Y + 1:
/*Program to solve 2 x 2 + 3 x y + 1 */
#include <iostream.h>
#include <conio.h>
main()
{
int x, y, z;
clrscr();
cout << "Enter any 2 numbers: \n" ;
cin >> x >> y ;
z = 2 *( x * x ) + 3 * ( x * y ) + 1;
cout << "the z value is : \n" << z ;
getch();
}

30. PROGRAM TO SOLVE SQUARE ROOT OF A 2 + B 2 :


/* Program to solve square root of a ^ 2 + b ^ 2 */
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int a, b;
float x, y;
clrscr();
cout << "Enter any two values: \n" ;
cin >> a >> b ;
x = (a * a) + (b * b);
y = sqrt ( x ) ;
cout << "the output is: \n"<< y ;
getch();
}

16
31. PROGRAM TO FIND FUTURE ANNUITY:
/*future annuity*/
#include<iostream.h>
#include<math.h>
void main()
{
int a, r, n, r1;
float fa;
clrscr();
r1 = r / 100;
cout << "enter the installment amt:\n" ;
cin >> a ;
cout << "enter the rate of interest : \n" ;
cin >> r ;
cout << "enter number of years: \n" ;
cin >> n ;
fa = a / r1 * pow ( ( 1 + r1 ) , n -1);
cout << "future annuity is: \n" fa ;
getch();
}
_________________________________________________________________________
IF STATEMENT:
An if – statement is a single selection or decision statement. When a set of statements have to be
executed when an expression is evaluated to true (non-zero value)
or when a set of statements have to be skipped when an expression is evaluated to false (zero), then
if – statement is used. It is used when we have only one alternative. Hence, it is also called one-way
decision / selection statement.
Syntax: if ( condition)
statement True executed;
if ( condition)
statement 1;
IF--- ELSE STATEMENT:
If one set of activities have to be performed when an expression is evaluated to true and another set
of activities have to be performed when an expression is evaluated to false, then if- else –statement is
used. The if- statement is a simple selection / decision statement that is used when we must choose
between two alternatives. Hence, it is also called two-way decision / selection statement.
Syntax: if (condition)
{
Statement-1;
}
else
{
Statement-2;
}
-------------------------------------------------------------------------------------------------------------------------

17
32. PROGRAM TO FIND BIGGEST AMONG TWO NUMBERS:
/*Program to find biggest among two numbers*/
#include<iostream.h>
#include<conio.h>
void main()
{
int a, b;
clrscr ();
cout << "Enter a first number\n" ;
cin >> a ;
cout << "Enter a second number\n" ;
cin >> b ;
if ( a > b )
cout << " a is big \n: " ;
if ( b > a )
cout << " b is big\n: " ;
getch();
}

33. PROGRAM TO FIND BIGGEST AMONG THREE NUMBERS:


/*Program to find biggest among three numbers*/
# include < iostream.h >
#include < conio.h >
void main ()
{
int a, b, c ;
clrscr ();
cout << "Enter a first number\n: " ;
cin >> a ;
cout << "Enter a second number\n: " ;
cin >> b ;
cout << "Enter a third number\n: " ;
cin >> c ;
if ( a > b && a > c )
cout << "a is big number : \n" ;
else
if ( b > a && b > c )

18
cout << "b is big number: \n" ;
else
cout << "c is big number:\n" ;
getch();
}

34. PROGRAM TO FIND BIGGEST AMONG FOUR NUMBERS:


/* Program to biggest among four numbers*/
# include <iostream.h>
# include <conio.h>
void main ()
{
int a, b, c, d ;
clrscr();
cout << "Enter any four numbers\n" ;
cin >> a >> b >> c >> d ;
if ( a > b && a > c && a > d )
cout ( "a is big:\n" ;
else
if ( b > a && b > c && b > d )
cout << "b is big:\n" ;
else
if ( c > a && c > b && c > d )
cout << " c is big:\n" ;
else
cout << "d is big:\n" ;
getch();
}

35. PROGRAM TO FIND SMALLEST TWO NUMBERS:


/*Program to find smallest among two numbers */
# include <iostream.h>
# include <conio.h>
void main ()
{
int a, b ;
clrscr ();
cout << "Enter any two number\n" ;
cin >> a >> b ;
if ( a < b )
cout << "a is small\n" ;

19
else
cout << "b is small\n" ;
getch();
}

36. PROGRAM TO FIND SMALLEST AMONG THREE NUMBERS:


/* Program to smallest among three numbers*/
# include <iostream.h>
# include <conio.h>
void main ()
{
int a, b, c ;
clrscr();
cout << "Enter a first number\n" ;
cin >> a ;
cout << "Enter a second number\n" ;
cin >> b ;
cout << "enter a third number\n" ;
cin >> c ;
if ( a < b && a < c )
cout << "a is small \n" ;
else
if ( b < a && b < c )
cout << "b is small number\n" ;
else
cout << "c is small number\n" ;
getch();
}

37. PROGRAM TO FIND SMALLEST AMONG FOUR NUMBERS:


/* Program to find smallest among four numbers*/
# include <iostream.h>
# include <conio.h>
void main ()
{
int a, b, c, d;
clrscr();

20
cout << "Enter any four numbers\n" ;
cin >> a >> b >> c >> d ;
if ( a < b && a < c && a < d )
cout << "a is small \n" ;
else
if ( b < a && b < c && b < d )
cout << "b is small \n" ;
else
if ( c < a && c < b && c < d )
cout << "c is small \n" ;
else
cout << "d is small \n" ;
getch();
}

38. PROGRAM TO FIND A GIVEN NUMBER IS POSITIVE OR NEGATIVE:


/* Program find positive or negative*/
# include <iostream.h>

# include <conio.h>
void main()
{
int a ;
clrscr();
cout << "Enter a number\n" ;
cin >> a ;
if ( a > 0 )
cout << a is positive\n" ;
else
cout << "a is negative\n" ;
getch();
}

39. PROGRAM TO FIND VOTE ELIGIBILITY:


/*Program to find vote eligibility*/
# include < iostream.h>

# include < conio.h>

21
void main()

int age ;
clrscr();
cout << "Enter your age\n" ;
cin >> age ;
If ( age> = 18)
cout << "Eligibility to vote\n" ;
else
cout << "Not eligibility to vote\n" ;
getch();
}

40. PROGRAM TO FIND ELIGIBILITY TO PASS OR FAIL:


/*Program to find eligibility to find pass or fail*/
# include < iostream.h>
# include < conio.h>
void main()
{
int marks ;
clrscr ();
cout << "Enter a marks\n";

cin >> marks ;


if ( marks > = 40 )
cout << “ Pass\n" ;
else
cout << "Fail\n " ;
getch();
}
---------------------------------------------------------------------------------------------------------------------
41. PROGRAM TO FIND ELIGIBILITY TO WRITE CET/MAT/CAT EXAMINATION:
/* Program to find eligibility to write cet/mat/cat examination */
# include < iostream.h>
# include < conio.h>
void main()

22
{
int age ;
clrscr();
cout << "enter your age\n" ;
cin >> age ;
if ( age > = 18)
cout << "Eligible to write CET examination\n" ;
else
cout << " Not eligible to write CET examination\n" ;
getch ();
}

42. PROGRAM TO FIND ELIGIBILITY TO MAT EXAMINATION. MARKS SHOULD BE MORE THAN 500 OR EQUAL:
/*Program to find eligibility to write MAT exam & Marks should be more than 500 or equal*/
# include < iostream.h>
# include < conio.h>
void main()

int age, marks ;

clrscr();

cout << "Enter your age\n";

cin >> age ;

cout << "Enter marks\n" ;

cin >> marks ;

if ( age> = 25 && marks > = 500 )

cout << " Elegible to write Mat exam\n" ;


else
cout << "Not eligible to write Mat exam\n" ;
getch ();
}

23
43. PROGRAM TO FIND CONDITIONAL MARKS CARD / STATEMENT OF A STUDENT.
INPUT: STUDENT NAME, REGISTER NUMBER, SIX SUBJECTS MARKS.
FIND TOTAL, AVERAGE AND RESULT (GRADE):
/* Program to prepare conditional marks card of a student */
# include < iostream.h>
# include < conio.h>
void main()
{
char name [20];
int regnum, s1, s2, s3, s4, s5, s6, sum;
float avg;
clrscr ();
cout << "Enter Student Name\n" ;
cin >> name ;
cout << "Enter student Register Number \n" ;
cin >> regnum ;
cout << "Enter first subject marks\n" ;
cin >> s1 ;
cout << "Enter second subject marks\n" ;
cin >> s2 ;
cout << "Enter third subject marks\n" ;
cin >> s3 ;
cout << " Enter fourth subject marks\n" ;
cin >> s4 ;
cout << "Enter firth subject marks\n" ;
cin >> a5 ;
cout << "Enter sixth subject marks\n" ;
cin >> s6 ;
sum = s1 + s2 + s3 + s4 + s5 + s6;
avg = sum / 6;
cout << "Student name is \n" << name ;
cout << "Register Number \n" << regnum ;
cout << "Total Marks \n" << sum ;
cout << "Average Marks \n" << avg ;
if ( s1 < 40 || s2 < 40 || s3 < 40 || s4 < 40 || s5 < 40 || s6 < 40)

24
cout <, "Fail\n" ;
else
if ( avg> = 75 )
cout << "Distinction\n" ;
else
if ( avg > = 60 && avg < 75 )
cout << "First class \n" ;
else
if ( avg> = 50 && avg < 60 )
cout << "Second class\n" ;
else
cout << " Pass\n" ;
getch();
}

44. PROGRAM TO FIND COMMISSION PAYABLE TO A SALESMAN.


INPUT: SALESMAN NAME, SALESMAN NUMBER AND SALES AMOUNT (SALES DONE):
/* Program to calculate commission payable to a salesman */
#include <iostream.h>
#include <conio.h>
void main()
{
char name [20 ];
int slno ;
float salesamt, com;
clrscr();
cout << " Enter salesman name\n" ;
cin >> name ;
cout << "Enter salesman number\n" ;
cin >> slno ;
cout << " Enter sales amount\n" ;
cin >> salesamt ;
if ( salesamt > = 150000)
com = salesamt * 15 / 100;
else
if ( salesamt > = 80000 && salesamt < 150000)
com = salesamt * 10 / 100;
else
if ( salesamt > = 50000 && salesamt < 80000)
com = salesamt * 5 / 100;
else
if ( salesamt > = 25000 && salesamt < 50000 )
25
com = salesamt * 2 / 100;
else
if ( salesamt < 25000)
com = salesamt * 0 / 100;
cout << "salesman name \n"<< name ;
cout << “ Selesman number \n"<< slno ;
cout << "sales amount \n << salesamt ;
cout << "sales commission is \n" << com ;
getch();
}

For Statement:
This is one of the looping or branching statements. A for loop is a control statement using
which the programmer can give instructions to the computer to execute a set of statements
repeatedly for a specified number of times. Since it is required to specify how many times a
set of statements have to be executed, it is also called counter-controlled loop. Once the
specified number of times the loop is executed, the control comes out of the loop.
Syntax: for (initialization; test-condition; increment/decrement)
{
Statements;
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

45. PROGRAM TO GENERATE 1 -5 NATURAL NUMBERS USING FOR STATEMENT:


/* Program to generate 1 to 5 numbers*/
#include <iostream.h>
#include <conio.h>
void main ()
{
int i;
clrscr();
for ( i = 1 ; i < = 5 ; i = i + 1 )
{
cout << \n" << i ;
}
getch ();
}
Output:
1
2
3
4
5
26
46. PROGRAM TO GENERATE NATURAL NUMBERS FROM 110 TO 120:
/*Program to generate 110 to 120 natural numbers*/
#include <iostream.h>
#include <conio.h>
void main ()
{
int i ;
clrscr ();
for ( i = 110 ; i < = 120 ; i + + )
{
cout << \n" << i ;
}
getch();
}

47. PROGRAM TO GENERATE REVERSE NATURAL NUMBERS FROM 20 TO 1:


/*Program to generate 20 to 1 reverse number*/
#include <iostream.h>
#include <conio.h>
void main ()
{
int i;
clrscr ();
for ( i = 20 ; i > = 1 ; i = i - 1 )
{
cout << \n" << i ;
}
getch();
}
===========================================================================
48. PROGRAM TO GENERATE EVEN NUMBERS FROM 36-46:
/*Program to generate even numbers from 36 to 46 */
#include <iostream.h>
#include <conio.h>
void main ()
{
int i;
clrscr ();
27
for ( i = 36 ; i < = 46 ; i = i + 2 )
{
cout << \n" << i ;
}
getch();
}

49. PROGRAM TO GENERATE REVERSE EVEN NUMBERS FROM 14 TO 2:


/* generate reverse even numbers from 14 to 2*/
# include <iostream.h>
# include <conio.h>
void main ()
{
int i;
clrscr ();
for ( i=14; i > = 2 ; i = i - 2 )
cout << \n"<< i ;
getch();
}
--------------------------------------------------------------------------------------------------------------------------
50. PROGRAM TO GENERATE ODD NUMBERS FROM 11-71:
/*Program to generate odd numbers from 11-71 */
#include <iostream.h>
#include <conio.h>
void main ()
{
int i;
clrscr ();
for ( i =11; i < = 71; i = i + 2 )
{
cout << \n"<< i ;
}
getch();
}
51. PROGRAM TO GENERATE REVERSE ODD NUMBERS FROM 21 TO 9
/* generate reverse odd numbers*/
# include <iostream.h>
# include <conio.h>
void main ()
28
{
int i;
clrscr ();
for ( i = 21; i > = 9 ; i = i - 2 )
cout << \n" << i ;
getch();
}
--------------------------------------------------------------------------------------------------------------------------
52. PROGRAM TO GENERATE N ( 1 TO N ) NATURAL NUMBER:
/* Program to generate 1 to n natural number */
#include<iostream.h>
#include<conio.h>
void main()
{
int i, n;
clrscr ();
cout << "Enter a number\n" ;
cin >> n ;
for ( i = 1 ; i < = n ; i = i + 1 )
{
cout << \n" << i ;
}
getch();
}
Output:
Enter a number
6
1
2
3
4
5
6
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

53. PROGRAM TO GENERATE AND SUM OF ‘N’ NATURAL NUMBER:


/* Program to generate and sum of n natural number*/
#include <stdio.h>
#include <conio.h>
void main()
{
int i, n, sum = 0;
29
clrscr ();
cout << "Enter a number\n" ;
cin >> n ;
for ( i = 1; i < = n ; i = i + 1 )
{
cout << \n" << i ;
sum = sum + i ;
}
cout << "sum of n natural number \n" << sum ;
getch();
}

55. PROGRAM TO GENERATE AND SUM OF EVEN NUMBERS FROM 2-30:


/* Program to generate and sum of even numbers from 2-30*/
#include<iostream.h>
#include<conio.h>
void main()
{
int i, sum=0;
clrscr();
for ( i = 2 ; i < = 30; i = i + 2 )
{
cout << \n"<< i ;
sum = sum + i ;
}
cout << "sum of even numbers is " << sum ;
getch();
}

56. PROGRAM TO GENERATE AND SUM OF ODD NUMBERS FROM 1-21:


/* Program to generate and sum of odd numbers from 1-21 */
#include<iostream.h>
#include<conio.h>
void main()
{
int i, sum=0;
clrscr();
for ( i = 1; i < = 21; i = i + 2 )
{
30
cout << \n"<< i ;
sum = sum + i ;
}
cout << "sum of odd numbers is \n" << sum ;
getch();
}

57. PROGRAM TO PRINT MULTIPLICATION TABLE OF A NUMBER:


/* Program to generate print multiplication table */
#include <iostream.h>
#include <conio.h>
void main()
{
int i, n, x;
clrscr ();
cout << "Enter the number\n:" ;
cin >> n ;
for (i = 1; i < = 10 ; i = i + 1 )
{
x=n*i;
cout << “ * “ << i << “ = “ << x << endl ;
}
getch();
}
58. PROGRAM TO FIND FACTORIAL OF A NUMBER:
/* Program to find factorial number*/
# include <iostream.h>
# include <conio.h>
void main()
{
int f = 1;
int n, i;
clrscr();
cout << "enter a number\n: " ;
cin >> n ;
for ( i =1; i < = n; i = i + 1 )
f=f*i;
cout << " factorial number is : \n"<< f ;
getch ();
}
31
Input:
Enter a number
5
The factorial number is 120

59. PROGRAM TO GENERATE FIBONACCI NUMBERS OR SERIES:


/* Program to generate fibonocci number */
# include<iostream.h>
# include<conio.h>
void main()
{
int i, f = 0, s = 1, n ;
clrscr();
n = f + s;
for ( i =1; i < = 10; i = i + 1 )
{
cout << f << “, " << s << “ , “ << n << endl;
f=s;
s=n;
n=f+s;
}
getch ();
}
Output:
F s n
0 1 1
1 1 2
1 2 3
2 3 5
3 5 8
5 8 13
8 13 21
13 21 34
21 34 55
34 55 89

60. PROGRAM TO FIND SMALLEST AMONG 10 NUMBERS:


/ * Program to find Smallest among 10 Numbers * /
#include<iostream.h>
#include<conio.h>
void main()
{
int i, small = 20000, a ;

32
clrscr();
for ( i = 1; i < = 10 ; i ++ )
{
cout << "Enter the 10 Numbers \n: " ;
cin >> a ;
if (a < small )
small = a ;
}
cout << “ the smallest among 10 numbers is : “ << small ;
getch ();
}
-------------------------------------------------------------------------------------------------------------------------------

61 . PROGRAM TO FIND BIGGEST AMONG 10 NUMBERS:


/ * Program to find Biggest among 10 Numbers * /
#include<iostream.h>
#include<conio.h>
void main()
{
int i , big = 2, a ;
clrscr();
for ( i = ; i < = 10 ; i = i + 1 )
{
cout << “ Enter the numbers \n” ;
cin >> a ;
if a ( a > big )
big = a;
}
cout << “ The biggest among ten numbers is \n “ << big;
getch ( )
}

62. PROGRAM TO FIND BIGGEST AND SMALLEST AMONG 10 NUMBERS:

// Program to find Biggest and Smallest among N Numbers//


#include<instream.h>
#include<conio.h>
void main()
33
{
int i, big = 2, small = 20000, a ;
clrscr();
for ( i = 1 ; i = 10; i = i + 1)
{
cout << “ Enter a numbers: ” ;
cin >> a ;
if ( a > big )
big = a ;
if ( a < small)
small = a ;
}
cout << “ The Biggest 10 Numbers is : “ << big ;
cout << “ \n”;
cout << “ The Smallest 10 Numbers is: “ << small ;
getch();
}

63. Program to Read and Print Array Element:


/* Program to read and print array */
include <iostream.h>
include<conio.h>
void main()
{
clrscr();
int a[30], i , n , sum = 0 ;
cout << “ enter the value : “ ;
cin >> n ;
cout << “ enter the value for array : “ ;
for ( i = 0 ; i = i + 1)
{
cin >> a [ i ] ;
sum = sum + a [ i ]
}
cout << “ array elements are : “ ;
for ( i = 0 ; i < n ; i ++)
{

34
cin >> a [ i ] ;
}
cout << “ sum: “ << sum ;
getch ();
}
-------------------------------------------------------------------------------------------------------------------------
64. Program to find 3*3 Matrix using 2 Dimensional Arrays:
include <iostream.h>
include<conio.h>
void main()
{
clrscr();
int a[3] [3] ;
int i, j;
cout << "Enter Array elements\n: " ;
for ( i = 1; i < = 3 ; i = i + 1 )
{
for ( j = 1 ; j < = 3 ; j = j + 1 )
{
cin >> a [ i ] [ j ] ;
}
}
cout << "The Matrix is\n: " ;
for ( i = 1 ; i < = 3; i = i + 1 )
{
for ( j = 1 ; j < = 3 ; j = j + 1 )
{
cout << a [ i ] [ j ] ;
}
cout << “ \n” ;
}
getch();
}
------------------------------------------------------------------------------------------------------------------------

35
65. Program to find 5*5 Matrix using 2 Dimensional Arrays:
include <iostream.h>
include<conio.h>
void main()
{
clrscr();
int a[5] [5] ;
int i, j;
cout << "Enter Array elements\n: " ;
for ( i = 1; i < = 5 ; i = i + 1 )
{
for ( j = 1 ; j < = 5 ; j = j + 1 )
{
cin >> a [ i ] [ j ] ;
}
}
cout << "The Matrix is\n: " ;
for ( i = 1 ; i < = 5; i = i + 1 )
{
for ( j = 1 ; j < = 5 ; j = j + 1 )
{
cout << a [ i ] [ j ] ;
}
cout << “ \n” ;
}
getch();
}
------------------------------------------------------------------------------------------------------------------------
66. Program to find Quantity Sold of Pens and Pen Cost and Find Total Amount:
include<iostream.h>
include<conio.h>
void main()
{
int qty, price, tamount;
clrscr();
cout << "Enter Quantity sold\n" ;
cin >> qty ;
36
cout << "Enter the price of pen\n" ;
cin >> price ;
tamount = qty * price;
cout << “total amount of pen is\n: ” << tamount ;
getch();
}
--------------------------------------------------------------------------------------------------------------------------

37

Das könnte Ihnen auch gefallen