Try the following program (next slide) and modify it so that it displays:
- $$A^B$$,
- the hypotenuse of a right triangle of sides A and B,
- the tangent of A using only the sin and cos functions,
- the rounded value (in minus) of A / B,
- The rounded value (in minus) to three positions behind the comma of A/B.
#include <stdio.h>
void main()
{
double A;
double B;
double RES;
/* Reading A and B */
printf("Enter A value : ");
scanf("%lf", &A);
printf("Enter B value : ");
scanf("%lf", &B);
/* Calculation */
RES = A*A;
/* display the result */
printf("The square of A is %f \n", RES);
/* Calculation */
RES = B*B;
/* display the result */
printf("The square of B is %f \n", RES);
getch();
}
Difficulty level

Video recording
This exercise is mostly suitable for students
#include <stdio.h>
#include <math.h>
void main()
{
double A;
double B;
double RES;
/* Reading A and B */
printf("Enter A value : ");
scanf("%lf", &A);
printf("Enter B value : ");
scanf("%lf", &B);
/* Calculation */
RES = A*A;
/* display the result */
printf("The square of A is %f \n", RES);
/* Calculation */
RES = B*B;
/* display the result */
printf("The square of B is %f \n", RES);
/* Calculation */
RES = pow(A,B);
/* display the result */
printf("A exponant B is %f \n", RES);
/* Calculation */
RES = sqrt(pow(A,2)+pow(B,2));
/* display the result */
printf("The hypotenuse of the rectangle is %f \n", RES);
/* Calculation */
RES = sin(A)/cos(A);
/* display the result */
printf("The tangent of A is %f \n", RES);
/* Calculation */
RES = floor(A/B);
/* display the result */
printf("The rounded value of A/B is %f \n", RES);
/* Calculation */
RES = floor(1000*(A/B))/1000;
/* display the result */
printf("The rounded value (in minus) to three positions behind the comma of A/B is %f \n", RES);
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
