Category Archives: if/else

Perfect Number in C

Here you will get program for perfect number in C. Perfect number is a positive number which is equal to the sum of all its divisors excluding itself. For example: 28 is a perfect number as 1 + 2 + 4 + 7 + 14 = 28. 15 is not perfect number as 1 +… Read More »

C Program to Find Roots of Quadratic Equation

Here you will get 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:1 1 1 Roots are complex and imaginary Roots are -0.50+0.87i and -0.50-0.87i

C program to swap two numbers without using temporary variable

#include<stdio.h> #include<conio.h> void main() { int x,y; clrscr(); printf(“Enter value of X: “); scanf(“%d”,&x); printf(“Enter value of y: “); scanf(“%d”,&y); if(x>y) { y=x-y; x=x-y; y=x+y; } else if(y>x) { x=y-x; y=y-x; x=y+x; } printf(“nx=%d”,x); printf(“ny=%d”,y); getch(); }

C Program to Check Number is Even or Odd

Here you will get C program to check given number is even or odd. We will use following simple logic in this program. If a number is divisible by 2 then it is even. If a number is not divisible by 2 then it is odd.

  Output Enter any number:17 The number is… Read More »

C program to find greatest number among three numbers

#include<stdio.h> #include<conio.h> void main() { int x,y,z,max; clrscr(); printf(“Enter The Three Numbers:”); scanf(“%d%d%d”,&x,&y,&z); max=x; if(y>max&&y>z) max=y; else if(z>max) max=z; printf(“nThe Greatest Number among %d %d %d is %d”,x,y,z,max); getch(); }

C program to find out whether a given year is a leap year or not

#include<stdio.h> #include<conio.h> void main() { int year; clrscr(); //to clear the screen printf(“Enter any year(4-digit):”); scanf(“%d”,&year); if(year%100==0) {   if(year%400==0)      printf(“Leap Year”); } else   if(year%4==0) printf(“nLeep Year”); else printf(“nNot leap year”); getch(); //to stop the screen }

C program to find whether a given character is an alphabet,digit or any special character(using ASCII values)

#include<stdio.h>#include<conio.h> void main(){    char ch;    clrscr();    //to clear the screen    printf(“Enter any character:”);    scanf(“%c”,&ch);     if((ch>=’A’&&ch<=’Z’)||(ch>=’a’&&ch<=’z’))        printf(“nYou have entered an alphabet”);    else        if(ch>=’0’&&ch<=’9′)            printf(“nYou have entered a digit”);        else            printf(“nYou have entered a special character”);     getch();    //to stop the screen}

C program to convert temperature from Fahrenheit to Celsius or Celsius to Fahrenheit

#include<stdio.h> #include<conio.h> void main() { double temp,ctemp; int ch; clrscr();    //to clear the screen     printf(“Temprature Converrsion Menu”); printf(“nt1.Fahrenheit to Celsius”); printf(“nt2.Celsius to Fahrenheit”); printf(“nEnter your choice(1/2):”); scanf(“%d”,&ch); if(ch==1) { printf(“Enter Temperature in Fahrenheit:”); scanf(“%lf”,&temp); ctemp=(temp-32)/1.8; printf(“nTemprature in celcius is %lf”,ctemp); } else if(ch==2) { printf(“Enter Temperature in Celsius:”); scanf(“%lf”,&temp); ctemp=(1.8*temp)+32; printf(“nTemperature in Fahrenheit is… Read More »

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();}