我不知道我的代码有什么问题我正在使用 Visual Studio,它说我没有标识符,我不能 100% 确定这意味着什么我基本上必须为 pow 编写一个新函数我不太了解它但是如果有人可以查看我的代码,那将非常有帮助,谢谢
// Programmer: Your Name
// Date: Date
// Program Name: The name of the program
// Chapter: Chapter # - Chapter name
// Description: 2 complete English sentences describing what the program does,
// algorithm used, etc.
#define _CRT_SECURE_NO_WARNINGS // Disable warnings (and errors) when using non-secure versions of printf, scanf, strcpy, etc.
#include <stdio.h> // Needed for working with printf and scanf
#include <math.h>
#include <string.h>
int main(void)
{
// Constant and Variable Declarations
double power(double num, int power) {
double result = 1;
if (power > 0) {
int i = 0;
for (i = 0; i < power; i++) {
result *= num;
}
return result;
}
else {
if (power < 0) {
power *= -1;
int i = 0;
for (i = 0; i < power; i++) {
result *= num;
}
}
return 1 / result;
}
}
int main(void)
{
double number;
int p;
printf("Enter a number to raise to a power : ");
scanf("%lf", &number);
printf("Enter the power to raise %.2lf to : ", number);
scanf("%d", &p);
printf("%.2f raised to the power of %d is : ", p);
double result = power(number, p);
double mathPow = pow(number, p);
printf("\n%-20s%-20s\n", "My Function", "Pow() Function");
printf("%-20.2f%-20.2f\n", result, mathPow);
return 0;
}
// *** Your program goes here ***
return 0;
} // end main()