我遇到了麻烦,返回我定义的结构,我的函数 scan_sci 假设从输入源获取一个以科学计数法表示正数的字符串,并将其分解为组件以存储在 scinot_t 结构中。示例输入为 0.25000e4
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct{
double mantissa;
int exp;
}sci_not_t;
int scan_sci (sci_not_t *c);
int main(void){
sci_not_t inp1, inp2;
printf("Enter the mantissa in the range [0.1, 1.0) then its exponent: ");
scan_sci(&inp1);
printf("Enter second number with same specifications as above: ");
scan_sci(&inp2);
system("PAUSE");
return 0;
}
int scan_sci (sci_not_t *c){
int status;
double a;
int b;
status = scanf("%lf %d", &c->mantissa, &c->exp);
a = c->mantissa;
b = c->exp;
*c = pow(a,b);
if (status == 2 && (c->mantissa >= 0.1 && c->mantissa < 1.0) ){
status = 1;
}else{
printf("You did not enter the mantissa in the correct range \n");
status = 0;
}
return (status);
}
sci_not_t sum(sci_not_t c1, sci_not_t c2){
return c1 + c2;
}
sci_not_t product(sci_not_t c1, sci_not_t c2){
return c1 * c2;
}