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 + …

Perfect Number in C 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 #include<stdio.h> #include<math.h> int main() { float root1,root2,a,b,c,d,imaginaryPart,realPart; printf(“Quadratic Equation is ax^2+bx+c=0”); printf(“\nEnter values of a,b and c:”); scanf(“%f%f%f”,&a,&b,&c); d=(b*b)-(4*a*c); if(d>0) { printf(“\nTwo real and distinct roots”); root1=(-b+sqrt(d))/(2*a); root2=(-b-sqrt(d))/(2*a); printf(“\nRoots are %f and %f”,root1,root2); } else if(d==0) { printf(“\nTwo real and equal roots”); root1=root2=-b/(2*a); …

C Program to Find Roots of Quadratic Equation Read More »

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 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 for Leap Year

Before knowing the C program for leap year lets first understand what exactly is a leap year. What is a Leap Year? In a normal year there are 365 days while in a leap year there are 366 days. Here the extra day is the 29th feb. How to Check Year is a Leap Year …

C Program for Leap Year Read More »

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 …

C program to convert temperature from Fahrenheit to Celsius or Celsius to Fahrenheit Read More »