#include<stdio.h> #include<conio.h> int fact(int); void main() { int x,n; printf("Enter the value of n :"); scanf("%d",&n); x=fact(n); printf("n%d",x); getch(); } int fact(int n) { if(n==0) return(1); return(n*fact(n-1)); }
About Me
- Amit Singh Thakur
- Raipur, Chhattisgarh, India
- Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.
Friday, August 30, 2013
Find Factorial of Number Using Recursion
C Program : To obtain solution of second order quadratic equation
#include<stdio.h> #include<conio.h> #include<math.h> void main() { float a,b,c; float desc,root1,root2; clrscr(); printf("Enter the Values of a : "); scanf("%f",&a); printf("Enter the Values of b : "); scanf("%f",&b); printf("Enter the Values of c : "); scanf("%f",&c); desc = sqrt(b*b-4*a*c); root1 = (-b + desc)/(2.0*a); root2 = (-b - desc)/(2.0*a); printf("First Root : %f",root1); printf("Second Root : %f",root2); getch(); }
Output :
Enter the Values of a : 1 Enter the Values of a : -5 Enter the Values of a : 6 First Root : 3.000000 Second Root : 2.000000
Program : C Program to find sum of two numbers
#include<stdio.h> #include<conio.h> void main() { int a,b,sum; clrscr(); printf("Enter two no: "); scanf("%d%d",&a,&b); sum = a+b; printf("Sum : %d",sum); getch(); }
Output :
Enter two no: 5 6 Sum : 11
C Program to find area and circumference of circle
#include<stdio.h> int main() { int rad; float PI=3.14,area,ci; printf("Enter radius of circle: "); scanf("%d",&rad); area = PI * rad * rad; printf("Area of circle : %f ",area); ci = 2 * PI * rad; printf("Circumference : %f ",ci); return(0); }
Output :
Enter radius of a circle : 1 Area of circle : 3.14 Circumference : 6.28
Explanation of Program :
In this program we have to calculate the area and circumference of the circle. We have following 2 formulas for finding circumference and area of circle.
Area of Circle = PI * R * R
and
Circumference of Circle = 2 * PI * R
In the above program we have declared the floating point variable PI whose value is defaulted to 3.14.We are accepting the radius from user.
printf("Enter radius of circle: "); scanf("%d",&rad);
C Program to find the simple interest
#include<stdio.h> #include<conio.h> void main() { int amount,rate,time,si; clrscr(); printf("Enter Principal Amount : "); scanf("%d",&amount); printf("Enter Rate of interest : "); scanf("%d",&rate); printf("Enter Period of Time : "); scanf("%d",&time); si = (amount * rate * time)/100; printf("Simple Intrest : %d",si); getch(); }
Output :
Enter Principal Amount : 500 Enter Rate of interest : 5 Enter Period of Time : 2 Simple Interest : 50
Program to convert temperature from degree centigrade to Fahrenheit
#include<stdio.h> #include<conio.h> void main() { float celsius,fahrenheit; clrscr(); printf("Enter temp in Celsius : "); scanf("%f",&celsius); fahrenheit = (1.8 * celsius) + 32; printf("Temperature in Fahrenheit : %f ",fahrenheit); getch(); }
Output :
Enter temp in Celsius : 32 Temperature in Fahrenheit : 89.59998
C Program to calculate sum of 5 subjects and find percentage
#include<stdio.h> #include<conio.h> void main() { int s1,s2,s3,s4,s5,sum,total=500; float per; clrscr(); printf("nEnter marks of 5 subjects : "); scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5); sum = s1 + s2 + s3 + s4 + s5; printf("nSum : %d",sum); per = (sum * 100) / total; printf("nPercentage : %f",per); getch(); }
Output :
Enter marks of 5 subjects : 80 70 90 80 80 Sum : 400 Percentage : 80.00
Subscribe to:
Posts (Atom)