314
views
views
PROGRAMMING FOR PROBLEM SOLVING - Mohan Babu University - B.Tech Mentor
C Program for Arithmetic Operations and Expression Evaluation
PROBLEM:
a) Write a C program to perform the arithmetic operations on two integer numbers.
b) Write a program to evaluate the following expressions by reading the necessary values from the keyboard.
i. (ax + b)/(ax – b)
ii. 2.5 log x + Cos 320+ | x2+ y2 |
iii. ax5 + bx3 + c
iv. aekt
Write a C program to perform the arithmetic operations on two integer numbers.
a) Solution
#include
#include
#include
void main()
{ int a,b,c,d,e,f,g;
clrscr();
printf("Enter the values of a and b:");
scanf("%d %d",&a,&b);
c=a+b;
d=a-b;
e=a*b;
f=a/b;
g=a%b;
printf("\nAddition of numbers is: %d",c);
printf("\nSubtraction of numbers is: %d",d);
printf("\nMultiplucation of numbers is: %d",e);
printf("\nDivision of numbers is: %d",f);
printf("\nRemainder of numbers is: %d",g);
getch();
}
(ax + b)/(ax – b)
b) (i) Solution
#include
#include
#include
void main()
{
int a,b,x;
float y;
clrscr();
printf("Enter the values of a,b,x:");
scanf ("%d %d %d",&a,&b,&x);
y=((a*x+b)/(a*x-b));
printf("\nThe result is: %f",y);
getch();
}
2.5 log x + Cos 320+ | x2+ y2 |
b) (ii) Solution
#include
#include
#include
void main()
{
int x,y;
float c;
clrscr();
printf("Enter the values of x,y:");
scanf("%d %d",&x,&y);
c=(2.5*log(x)+cos(32*3.14/180)+abs(x*x+y*y)+sqrt(2*x*y));
printf("\nThe result is: %f",c);
getch();
}
ax5 + bx3 + c
b) (iii) Solution
#include
#include
#include
void main()
{
int x,y;
clrscr();
printf("Enter the values of x:");
scanf ("%d",&x);
y=(pow(x,5)+10*(pow(x,4))+8*(pow(x,3))+4*x+2);
printf("\nThe result is: %d",y);
getch();
}
aekt
b) (iv) Solution
#include
#include
#include
void main()
{
int a,k,t;
float f;
clrscr();
printf("Enter the values of a,k,t:");
scanf ("%d %d %d",&a,&k,&t);
f=(a*exp(k*t));
printf("\nThe result is: %f",f);
getch();
}
Comments
0 comment