C++ 07:Examples on If - else
1)WAP to read the angles of a triangle and check weather it is equilateral or not.
#include <iostream>
using namespace std;main(){ int a, b, c; cout << "Enter a angle:"; cin >> a >> b >> c; if (a + b + c == 180 && a == b == c) { cout << "It is Equilateral Triangle"; } else { cout << "It is not equilateral Triangle"; }
}2. WAP to check weather the triangle is isosceles triangle or not.
#include <iostream>
using namespace std;main(){ int x, y, z; cout << "Enter a angle: "; cin >> x >> y >> z; if ((x + y + z == 180) && (x == y || y == z || x == z)) { cout << "It is an isoceles triangle" << endl; } else { cout << "It is not isoceles triangle" << endl; }}3. WAP to check weather a triangle is right angled triangle or not.
#include <iostream>
using namespace std;main(){ int p, q, r; cout << "Enter angles of triangle: "; cin >> p >> q >> r; if (p + q + r == 180 && (p == 90 || q == 90 || r == 90)) { cout << "it is a right angled Triangle"; } else { cout << "it is not a right angled triangle"; }}More examples-------->
Comments
Post a Comment