Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
13 views14 pages

Jeevan Oops Practical File

The document contains a series of C++ programs demonstrating basic programming concepts such as summing two numbers, calculating factorials, finding squares, averaging numbers, and more. Each program includes input prompts, output examples, and some common programming errors. Overall, it serves as a practical guide for beginners to learn fundamental programming techniques.

Uploaded by

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

Jeevan Oops Practical File

The document contains a series of C++ programs demonstrating basic programming concepts such as summing two numbers, calculating factorials, finding squares, averaging numbers, and more. Each program includes input prompts, output examples, and some common programming errors. Overall, it serves as a practical guide for beginners to learn fundamental programming techniques.

Uploaded by

d73111147
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Deepak

2323327

1. PROGRAM TO FIND THE SUM OF TWO NUMBERS


INPUT

#include<conio.h>
#include<iostream>
using namespace std;
int main()
{

int number 1;
int number 2;
int sum;
cout<<”\n enter the first number:-“;
cin>>number1;
cout<<”\n sum of “<<number1<<”and”<<number2<<”is”<<sum;
getch();
}

OUTPUT
enter the first number :- 35
enter the second number :- 65
sum of 35 and 65 is 100
Deepak
2323327

2. PROGRAM TO FIND THE FACTORIAL OF A GIVEN NUMBER


INPUT

#include<conio.h>
#include<iostream>
using namespace std;
int main()
{ int n;
Long factorial = 1.0;
Cout<<”enter a positive integer:-“;
cin>> n;
if(n<0)
cout<<”error! Factorial of a negative number doesn’t exist”;
else{
for(int i=1; i<=n; ++i){factorial*=i}
cout<<”factorial of “ << n << “=”<<factorial;}
return 0;
}

OUTPUT

Enter a positive number : 5


Factorial of 5 = 120
Deepak
2323327

3. PROGRAM TO FIND SQUARE OF A GIVEN NUMBER

#include<conio.h>

#include<iostream>

using namespace std;

int main(){

int n,square;

cout<<”enter a number:”;

cin>>n;

square=n*n;

cout<<”square of” <<n <<” is: “” << square;

return 0;

OUTPUT
enter a number : 7
square of 7 is : 49
Deepak
2323327

4. PROGRAM TO CALCULATE AVERAGE OF THREE NUMBERS

#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
Int num_1;
cout<<”enter num_1:”;
cin>>num_1;
int num_2;
cout<<”enter num_2:”;
cin>>num_2;
int num_3;
cout<<”enter num_3:”;
cin>>num_3;
float average =( num_1 + num_2 + num_3) /3;
cout<<”average:”<<average <<endl;
return 0;
}

OUTPUT

enter num_1: 32
enter num_2: 12
enter num_3: 12
average: 18
Deepak
2323327

5. PROGRAM TO PRINT MESSAGE WITH INPUTTED NAME


#include<conio.h>

#include<iostream>

using namespace std;

int main()
{

string name;

cout<<” What is your name “;

cin>>name;

cout<<”Hello nice to meet you “<<name;

getch();
}
OUTPUT

What is your name jeevanjot singh

Hello nice to meet you jeevanjot singh


Deepak
2323327

6. WRITE A PROGRAM TO FIND THE LARGEST FROM THE THREE NUMBERS

#include<conio.h>
#include<iostream>
using namespace std;
int main()

{ int a, b, c;
cout<<” enter the number: 1 “;
cin>>a;
cout<<”enter the number: 2 “;
cin>>b;
cout<< “ enter the number: 3 “;
cin>>c;
if(a>=b)
{if(a>=c)
cout<<” largest number is: a “;
else
cout<<”largest number is: b “ ; }
else{
if(b>=c)
cout<< “ largest number is: b “;
else
cout<<” largest number is: c “; }
getch(); }

OUTPUT

enter the number 1: 37


enter the number 2: 18
enter the number 3: 41
largest number is :37
Deepak
2323327

7. PROGRAM TO ENTER MARKS OF SIX SUBJECTS AND FIND OUT THE


TOTAL MARKS

#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
int english, hindi, punjabi, SS, science, mathematics, total;
cout<<”enter the marks of english:”;
cin>>english;
cout<<”enter the marks of hindi:”;
cin>>hindi;
cout<<”enter the marks of punjabi: “;
cin>>punjabi;
cout<<”enter the marks of SS: “;
cin>>SS;
cout<<”enter the marks of science: “;
cin>>science;
cout<<”enter the marks of mathematics: “;
cin>>mathematics;
total=english+hindi+punjabi+SS+science+mathematics;
cout<<”Total marks is “ <<total ;
getch();
}
Deepak
2323327

OUTPUT

enter the marks of english : 83


enter the marks of hindi : 90
enter the marks of punjabi : 91
enter the marks of SS : 79
enter the marks of science: 81
enter the marks of mathematics : 73

Total marks is 497


Deepak
2323327

8. PROGRAM TO GENERATE MULTIPLICATION USING WHILE LOOP

#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
int num=1;
int multiplier=2;
while(num<=10){
int result=num*multiplier;
cout<<result<<endl;
num++;
}
return 0;}

OUTPUT
2
4
6
8
10
12
14
16
18
20
Deepak
2323327

9. PROGRAM TO MAKE A SIMPLE CALCULATOR USING SWITCH CASE

#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
char op;
float num1,num2;
cout<<”enter an operator(+,-,*,/):”;
cin>>op;
cout<<”enter first number:”;
cin>>num1;
cout<<”enter second number:”;
cin>>num2;
switch(op){
case’+’:
cout<<num1<<”+”<<num2<<”=”<<num1+num2<<endl;
break;
case’-‘:
cout<<num1<<”-“<<num2<<”=”<<num1-num2<<endl;
break;
case’*’:
cout<<num1<<”*”<<num2<<”=”<<num1*num2<<endl;
break;
case’/’:
cout<<num1<<”/”<<num2<<”=”<<num1/num2<<endl;
break;
default;
cout<<”invalid operator”<<endl;
break;
}
getch(); }
Deepak
2323327

OUTPUT

enter an operator (+,-,*,/): *


enter first number : 10
enter second number : 7
10*7=70
Deepak
2323327

10. PROGRAM TO FIND THE SUM OF TWO MATRICS


#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
int array[2][2],arr1[2][2],arr2[2][2],I,j;
for(i=0;i<2;i++)
{
for(i=0;i<2;i++)
{
cout<<”elements of ARRAY1:- “;
cin>>array[i][i];
}
}
for(i=0;i<2,i++)
{
for(i=0;i<2;i++)
{
cout<<”elements of ARRAY2:- “;
cin>>arr[i][i];
}
}
for(i=0;i<2;i++)
{
for(j=0:j<2;j++)
{
arr2[i][i]=array[i][i]+arr1[i][i];
}
}
cout<<”\n SUM OF TWO ARRAY:- “;
for(i=0;i<2;i++)
Deepak
2323327

{
cout<<”\n”;
for(j=0;j<2;j++)
{
cout<<arr2[i][i]<<”\t”;
}
}
return 0;
}
OUTPUT
elements of ARRAY1:- 2
elements of ARRAY1:- 3
elements of ARRAY1:- 4
elements of ARRAY1:- 5
elements of ARRAY2:-5
elements of ARRAY2:-4
elements of ARRAY2:-3
elements of ARRAY2:-2

SUM of TWO ARRAY:-

7 7
7 7
Deepak
2323327

You might also like