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 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 odd

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 »