Name – Vishal Prakash Raj
Course – Diploma Cse
Q id – 19070046
TO PRINT HELLO WORLD
#include <iostream>
using namespace std;
int main()
cout << "Hello world!" << endl;
return 0;
}
2.FIND AREA OF TRIANGLE
#include<iostream>
using namespace std;
int main() {
float b,h,area;
cout<<”enter base & height :”;
cin>>b>>h;
area =(b*h)/2;
cout<<”area of triangle =”<<area;
return 0;
}
3.SWAPPING OF NUMBER
#include<iostream>
using namespace std;
int main() {
int a=10 , b=20,c;
cout<<"before swapping :";
cout<<"\n a="<<a <<"b="<<b;
c=a;
a=b;
b=c;
cout<<"after swapping :";
cout<<"\n a="<<a <<"b="<<b;
return 0;
}
4.To find the largest no. among two numbers using if else
#include<iostream>
using namespace std;
int main() {
int a,b, largest ;
cout<<"enter two numbers:";
cin>>a;
cin>>b;
if(a>b)
largest =a;
else
largest =b;
cout<<"largest number is " << largest;
return 0;
}
5. program for increment
#include<iostream>
using namespace std;
int main() {
float a;
cout <<"Enter value of a :";
cin>>a;
a++;
cout<<"value of a after increment :"<<a;
return 0;
}
6. program to check a no. is positive or negative
#include<iostream>
using namespace std;
int main() {
float a;
cout<<"Enter an integer :";
cin>>a;
if(a>0)
cout<< "you have entered a positive number i.e "<<a;
else
cout<< "you have entered a negative number i.e "<<a;
return 0;
}
7. program to check a no. is positive or negative or zero
#include<iostream>
using namespace std;
int main()
float a;
cout<<"Enter an integer :";
cin>>a;
if(a>0)
cout<< "you have entered a positive number i.e "<<a;
else if(a<0)
cout<< "you have entered a negative number i.e"<<a;
else
cout<< "you have entered zero";
return 0;
}
8. program to find the factorial of a number
#include<iostream>
using namespace std;
int main()
{ int i,fact=1, num;
cout<<"Enter a number :";
cin>>num;
for (i=1;i<=num;i++)
fact = fact *i ;
cout<< "factorial of" <<num<< " is :"<<fact;
return 0;
}
9. program to find area and volume using class & object
#include <iostream>
using namespace std;
class Room { // create a class
public: //access specifier
double length;
double breadth;
double height;
double calculateArea() {
return length * breadth;
double calculateVolume() {
return length * breadth * height;
};
int main() {
Room room1; // create object of Room class
room1.length = 42.5; // assign values to data members
room1.breadth = 30.8;
room1.height = 19.2;
cout << "Area of Room = " << room1.calculateArea() << endl;
cout << "Volume of Room = " << room1.calculateVolume() << endl;
return 0;
}
10. Program for displaying array elements
#include <iostream>
using namespace std;
int main() {
int numbers[5]={1,11,22,32,45},i;
cout<< “The numbers are:”;
for(int i=0i<5;i++)
cout<<numbers[i]<< “ “;
return 0;
}
THANK YOU