C++ Language
who to print a line Hello world
PROGRAM:
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World";
}
OUTPUT:
Hello World
--------------------------------
Process exited with return value 0
Press any key to continue . . .
Sum of two numbers
Program
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter a first value:";
cin>>a;
cout<<"Enter a second value:";
cin>>b;
c=a+b;
cout<<"Total="<<c;
}
OUTPUT:
Enter a first value:1
Enter a second value:23
Total=24
--------------------------------
Process exited with return value 0
Press any key to continue . . .
How to draw right angle triangle
#include<iostream>
using namespace std;
int main()
{
int a,b;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
cout<<"*";
std:cout<<endl;
}
}
OUTPUT:
*
**
***
****
*****
--------------------------------
Process exited with return value 0
Press any key to continue . . .
Relational operator
Program#1
// If condition is true result is 1 if false result is 0
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"\nEnter a value of a: ";
cin>>a;
cout<<"\nEnter a value of b: ";
cin>>a;
cout<<"condition a>b"<<endl;
cout<<(a>b)<<endl;
// If condition is true result is 1 if false result is 0
cout<<"condition a<b"<<endl;
cout<<(a<b)<<endl;
}
RESULT
Enter a value of a: 12
Enter a value of b: 21
condition a>b
0
condition a<b
1
--------------------------------
Process exited with return value 0
Press any key to continue . . .
Conditional operator
Program#1
// If condition is true result is 1 if false result is 0
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"\nEnter a value of a: ";
cin>>a;
cout<<"\nEnter a value of b: ";
cin>>a;
cout<<"condition a&&b"<<endl;
cout<<(a&&b)<<endl;
// If condition is true result is 1 if false result is 0
cout<<"condition a||b"<<endl;
cout<<(a||b)<<endl;
}
OUTPUT
Enter a value of a: 12
Enter a value of b: 32
condition a&&b
1
condition a||b
1
--------------------------------
Process exited with return value 0
Press any key to continue . . .
PROGRAM
write a program to find that Given vertices are not the sides of right angle triangle
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"\n Enter a value of a:";
cin>>a;
cout<<"\n Enter a value of b:";
cin>>b;
cout<<"\n Enter a value of c:";
cin>>c;
if(a==b)
{
if(c!=a)
cout<<"a and b are equal";
}
else if(b==c)
{
if(a!=b)
cout<<"b and c are equal";
}
else if(a==c)
{
if(b!=c)
cout<<"a and c are equal";
}
else if(a>b)
{
if(a>c)
cout<<"a is the greatest";
}
else if(b>a)
{
if(b>c)
cout<<"b is the greatest";
}
if(a!=b)
{
if (c>a)
{
if(c>a)
cout<<"\nc is the greatest";
}
else
cout<<"all the values are equal";
return 0;
}}
PROGRAM
#include<iostream>
using namespace std;
int main()
{
int base,hypotunus,perpendicular,a,s,f,d;
for(f=1;f<=5;f++)
{
for(d=1;d<=f;d++)
cout<<" *";
cout<<" \n";
}
cout<<"Enter base:";
cin>> base;
cout<<"Enter hypotunus:";
cin>> hypotunus;
cout<<"Enter perpendicular:";
cin>> perpendicular;
a=hypotunus*hypotunus;
s=(hypotunus*hypotunus)+(perpendicular*perpendicular);
if(a==s)
cout<<"Given vertices are the sides of right angle triangle:";
else
cout<<"Given vertices are not the sides of right angle triangle:";
}
PROGRAM (L.C.M)
#include<iostream>
using namespace std;
int main()
{
int x,y,z,G,L;
cout<<"Enter a first no";
cin>>x;
cout<<"Enter a second no";
cin>>y;
cout<<"Enter a third no";
cin>>z;
G=(x>y&&x>z)?x:(y>x&&y>z)?y:(z>x&&z>y)?z:(x==y&&y<z)?z:(y==z&&z<x)?x:y;
for(L=G;L<=x*y*z;L=L+G)
{
if(L%x==0&&L%y==0&&L%z==0)
break;
}
cout<<"L.C.M is"<<L;
return 0;
}
using namespace std;
int main()
{
int x,y,z,G,L;
cout<<"Enter a first no";
cin>>x;
cout<<"Enter a second no";
cin>>y;
cout<<"Enter a third no";
cin>>z;
G=(x>y&&x>z)?x:(y>x&&y>z)?y:(z>x&&z>y)?z:(x==y&&y<z)?z:(y==z&&z<x)?x:y;
for(L=G;L<=x*y*z;L=L+G)
{
if(L%x==0&&L%y==0&&L%z==0)
break;
}
cout<<"L.C.M is"<<L;
return 0;
}
PROGRAM (H.C.F)
#include<iostream>
using namespace std;
int main()
{
int x,y,z,s,L;
cout<<"Enter a first no";
cin>>x;
cout<<"Enter a second no";
cin>>y;
cout<<"Enter a third no";
cin>>z;
s=(x<y&&x<z)?x:(y<x&&y<z)?y:(z<x&&z<y)?z:(x==y&&y<z)?z:(y==z&&z<x)?x:y;
for(L=s;L>=1;L--)
{
if(x%L==0&&y%L==0&&z%L==0)
break;
}
cout<<"H.C.F is"<<L;
return 0;
}
Comments
Post a Comment