Neeraj Mishra

A crazy computer and programming lover. He spend most of his time in programming, blogging and helping other programming geeks.

C program to find factorial of any number using recursion

#include<stdio.h> #include<conio.h> void main() { int fac,n; int factorial(int); clrscr(); printf(“Enter any number:”); scanf(“%d”,&n); fac=factorial(n); printf(“Factorial=%d”,fac); getch(); } int factorial(int x) { int f; if(x==1||x==0) return 1; else f=x*factorial(x-1); return f; }

C Program to Find LCM and HCF of Two Numbers

Here you will get C program to find lcm and hcf of two given numbers. #include<stdio.h> int main() { int a,b,hcf,lcm,max,min,r; printf(“Enter two numbers:”); scanf(“%d%d”,&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; printf(“\nLCM=%d\nHCF=%d”,lcm,hcf); return 0; }   Output …

C Program to Find LCM and HCF of Two Numbers Read More »

C program that compare two given dates. To store a date use a structure that contains three members namely day, month and year. If dates are equal then display a message as EQUAL otherwise UNEQUAL

#include<stdio.h> #include<conio.h> struct date { int day; int month; int year; }; void main() { struct date d1,d2; clrscr(); printf(“Enter first date(dd/mm/yyyy):”); scanf(“%d%d%d”,&d1.day,&d1.month,&d1.year); printf(“nEnter second date(dd/mm/yyyy):”); scanf(“%d%d%d”,&d2.day,&d2.month,&d2.year); if((d1.day==d2.day)&&(d1.month==d2.month)&&(d1.year==d2.year)) printf(“nEQUAL”); else printf(“nUNEQUAL”); getch(); }

C program to add two numbers using structure

#include<stdio.h> #include<conio.h> struct sum { int a; int b; }; void main() { int sum1; struct sum s; clrscr(); printf(“Enter two numbers:”); scanf(“%d%d”,&s.a,&s.b); sum1=s.a+s.b; printf(“nSum=%d”,sum1); getch(); }