0% found this document useful (0 votes)
32 views

Lab Assignment 1

Uploaded by

Dewanand Giri
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)
32 views

Lab Assignment 1

Uploaded by

Dewanand Giri
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
You are on page 1/ 6

Program 1

#include <iostream>
using namespace std;

int main( )
{
cout<<``hello world’’;
return 0;
}

Program 2

#include <iostream>
using namespace std;

int main( )
{
int a,b,sum;
cout<<``Enter two numbers”;
cin>>a;
cin>>b;
sum=a+b;
cout<<``Sum is”<<sum;
return 0;
}

Program 3

#include​ ​<iostream>
using​ ​namespace​ std;

int​ ​main​( )
{
​int​ ​math​,​oop​,​ds​,​mp​,​stats​,​total​,​percentage​;
​cout​<<​"Enter marks in math,oop,ds,mp and stats respectively"​<<endl​;
​cin​>>​math​>>​oop​>>​ds​>>​mp​>>​stats​;
​total​=​(​math​+​oop​+​ds​+​mp​+​stats​);
​percentage​=​((​total​)​*​1​)​/​5​;
​cout​<<​"Subject"​<<​"​\t​"​<<​"Marks"​<<endl​;
​cout​<<​"Math"​<<​"​\t​"​<<​math​<<endl​;
​cout​<<​"OOP"​<<​"​\t​"​<<​oop​<<endl​;
​cout​<<​"DS"​<<​"​\t​"​<<​ds​<<endl​;
​cout​<<​"MP"​<<​"​\t​"​<<​mp​<<endl​;
​cout​<<​"Stats"​<<​"​\t​"​<<​stats​<<endl​;
​cout​<<​"total="​<<​"​\t​"​<<​total​<<endl​;
​cout​<<​"Percentage"​<<​"​\t​"​<<​percentage​<<​"%"​<<endl​;
​return​ ​0​;
}

Program 4:

#include<iostream>
using namespace std;
int main()
{
// declare variables
double n1,n2,n3;

// take input
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;

// compare first and second number


if(n1 > n2)
{
// compare first and third number
if(n1 > n3)
cout << "Largest = " << n1 << endl;
else
cout << "Largest = " << n3 << endl;
}
else
{
// compare second and third number
if(n2 > n3)
cout << "Largest = " << n2 << endl;
else
cout << "Largest = " << n3 << endl;
}
return 0;
}

Program 5

#include <iostream>

using namespace std;

int main()

int i,fact=1,number;

cout<<"Enter any Number: ";

cin>>number;

for(i=1;i<=number;i++){

fact=fact*i;

cout<<"Factorial of " <<number<<" is: "<<fact<<endl;

return 0;

Program 6

#include <iostream>

using namespace std;

int main()

int a=5, b=10;

cout<<"Before swap a= "<<a<<" b= "<<b<<endl;

a=a*b; //a=50 (5*10)

b=a/b; //b=5 (50/10)

a=a/b; //a=10 (50/5)

cout<<"After swap a= "<<a<<" b= "<<b<<endl;


return 0;

Program 7

#include<iostream>

using namespace std;

int main()

// declare variables

float p, t, r, interest;

// take input from end-user

cout << "Enter principal amount, time and rate:";

cin >> p >> t >> r;

// calculate interest

interest = (p*t*r)/100;

// display result

cout << "Interest = " << interest << endl;

return 0;
}

Program 8

#include <iostream>

using namespace std;


int main()

int n, i, m=0, flag=0;

cout << "Enter the Number to check Prime: ";

cin >> n;

m=n/2;

for(i = 2; i <= m; i++)

if(n % i == 0)

cout<<"Number is not Prime."<<endl;

flag=1;

break;

if (flag==0)

cout << "Number is Prime."<<endl;

return 0;

Program 9

#include <iostream>

using namespace std;

int main()

int n,r,sum=0,temp;

cout<<"Enter the Number= ";

cin>>n;
temp=n;

while(n>0)

r=n%10;

sum=sum+(r*r*r);

n=n/10;

if(temp==sum)

cout<<"Armstrong Number."<<endl;

else

cout<<"Not Armstrong Number."<<endl;

return 0;

You might also like