Submitted by: Submitted by moonswamy1
Views: 168
Words: 334
Pages: 2
Category: Other Topics
Date Submitted: 10/13/2012 11:54 PM
write a program to produce ASCII equivalent of a given number.
Soln:
#include
#include
void main()
{
clrscr();
char c;
printf("\nenter the character: ");
scanf("%c",&c);
printf("\nits ASCII equivalent is: %d",c);
getch();
}
Output:
enter the character: A
its ASCII equivalent is: 65
1. write a program to find divisor or factorial of a given number.
Soln
#include
#include
void main()
{
clrscr();
float num,i,fact=1;
printf("\nenter the number: ");
scanf("%f",&num);
i=num;
while(i>0)
{
fact=fact*i;
i--;
}
printf("\nfactorial is: %f",fact);
getch();
}
Output:
enter the number: 5
factorial is: 120.000000
2. write a program to evaluate the following algebraic expressions:
-(ax+b)/(ax-b)
-2.5log(x) + |x^2-y^2| + sqrt(2xy)
-x^5 + 10x^4 + 8x^3 + 4x +2
Soln:
#include
#include
#include
void main()
{
clrscr();
double a,x,b,y,ans1,ans2,ans3;
printf("\nenter a,b,x,y: ");
scanf("%lf%lf%lf%lf",&a,&b,&x,&y);
ans1=((a*x)+b)/((a*x)-b);
printf("\n(ax+b)/(ax-b) = %lf",ans1);
ans2=(2.5*log10(x))+( sqrt( (pow(x,2)-pow(y,2) ) * (pow(x,2)-pow(y,2)) )) +(sqrt(2*x*y));
printf("\n2.5*log(x) + |x^2-y^2| + sqrt(2*x*y) = %lf",ans2);
ans3=pow(x,5)+(10*(pow(x,4)))+(8*(pow(x,3)))+(4*x)+2;
printf("\nx^5 + 10x^4 + 8x^3 + 4x + 2 = %lf",ans3);
getch();
}
Output:
enter a,b,x,y: 2
3
4
5
(ax+b)/(ax-b) = 2.200000
2.5*log(x) + |x^2-y^2| + sqrt(2*x*y) = 16.829705
x^5 + 10x^4 + 8x^3 + 4x + 2 = 4114.000000
3. write a program to find the sum of a geometric series.
Soln.
#include
#include
#include
void main()
{
clrscr();
float r,a,temp,sum=0;
int n;
printf("\nenter the first term,...