if/else

C++ Program to convert a lowercase alphabet to uppercase or vice-versa

#include<iostream.h> #include<conio.h> void main() { clrscr(); char ch; cout<<“Enter any Alphabet:”; cin>>ch; if(ch>=’a’&&ch<=’z’) { cout<<“ntYou have entered a lowercase alphabet”; ch=ch-32; cout<<“nnThe uppercase alphabet is “<<ch; } else { cout<<“ntYou have entered an Uppercase alphabet”; ch=ch+32; cout<<“nnThe lowercase alphabet is “<<ch; } getch(); }

C++ Program to print three numbers in descending order

#include<iostream.h>#include<conio.h> void main(){ clrscr(); int a,b,c,big1,big2,big3; cout<<“Enter three numbers:”; cin>>a>>b>>c;  big1=a; if(b>big1) big1=b; else if(c>big1) big1=c; if(big1==a) { if(b>c) { big2=b; big3=c; } else { big2=c; big3=b; } } else { if(big1==b) if(a>c) { big2=a; big3=c; } else { big2=c; big3=a; } else { if(a>b) { big2=a; big3=b; } else { big2=b; big3=a; } } …

C++ Program to print three numbers in descending order Read More »

C++ Program to Find Roots of Quadratic Equation

Here you will get simple C++ program to find roots of quadratic equation ax2+bx+c=0. #include<iostream> #include<math.h> //to calculate square root using namespace std; int main() { float root1,root2,a,b,c,d,imaginaryPart,realPart; cout<<“Quadratic Equation is ax^2+bx+c=0”; cout<<“\nEnter values of a,b and c:”; cin>>a>>b>>c; d=(b*b)-(4*a*c); if(d>0) { cout<<“\nTwo real and distinct roots”; root1=(-b+sqrt(d))/(2*a); root2=(-b-sqrt(d))/(2*a); cout<<“\nRoots are “<<root1<<” and “<<root2; } …

C++ Program to Find Roots of Quadratic Equation Read More »

C++ Program to Find LCM and HCF of two numbers

#include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,hcf,lcm,max,min,r; cout<<“Enter two numbers:”; cin>>a>>b; if(a>b) { max=a; min=b; } else if(b>a) { max=b; min=a; } if(a==b) hcf=a; else { do { r=max%min; max=min; min=r; }while(r!=0); hcf=max; } lcm=(a*b)/hcf; cout<<“nLCM=”<<lcm<<“nHCF=”<<hcf; getch(); }

C++ Program to Check Character is Uppercase, Lowercase, Digit, or Special Character

Below I have shared a C++ program to check whether a given character is an uppercase or lowercase alphabet, a digit, or a special character. First of all, I read a character and then compare it with the ASCII values given below. If the ASCII value of the character is other than the values mentioned …

C++ Program to Check Character is Uppercase, Lowercase, Digit, or Special Character Read More »