Write a function EXP that calculates the value \(X^N\) for a real value X (double type) and a positive integer value N (type int): EXP returns the value \(X^N\) as result.
Write a program that tests the function using values read from the keyboard.
Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>
#include <conio.h>
double EXP(double X, int N)
{
double RES;
for (RES = 1.0; N>0; N--)
RES *= X;
return RES;
}
void main()
{
double X;
int N;
printf("Enter X: ");
scanf("%lf", &X);
printf("Enter N: ");
scanf("%d", &N);
printf("EXP(%.2f , %d) = %.2f\n", X, N, EXP(X, N));
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Multiplication table