Category Archives: 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; } }… 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. Output Quadratic Equation is ax^2+bx+c=0 Enter values of a,b and c:3 4 1 Two real and distinct roots Roots are -0.333333 and -1

C++ Program to find quotient and remainder of two numbers

#include<iostream.h>#include<conio.h> void main(){ clrscr(); int a,b,q,r; cout<<“Enter two numbers:”; cin>>a>>b; if(a>b) { q=a/b; r=a%b; cout<<“nQuotient=”<<q; cout<<“nRemainder=”<<r; } else cout<<“nFirst no. should be greater than second no….!!!”; getch();}

C++ Program to Check whether a year is Leap year or not

#include<iostream.h>#include<conio.h> void main(){ clrscr(); int year; cout<<“Enter Year(ex:1900):”; cin>>year; if(year%100==0) { if(year%400==0) cout<<“nLeap Year”; } else if(year%4==0) cout<<“nLeap Year”; else cout<<“nNot a Leap Year”; getch();}

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 Find Greatest Number Among Three Numbers

Below I have shared C++ program to find greatest number among three numbers. For example among three numbers 5, 13 and 7, the greatest number is 13. If you have any problem regarding above greatest number program then you can ask it by commenting below. C++ Program to Find Greatest Number Among Three Numbers  … Read More »