按照代码,再一次循环应该会再一次执行scanf_s("%c", over)指令,但是他却直接跳过了,还有最终输出结果明明左右都有一个换行符,但右边的换行符却不起作用,以下为代码和图
#include <stdio.h>long double power(int di, int zhi);int main(void){ while (1) { int di, zhi; long double conclution; char over;printf("input random to next(q to quit)\n"); scanf_s("%c", &over);if (over == 113) { break; } else { printf("\nPlease input the number(int): "); if (scanf_s("%d^%d", &di, &zhi) == 0) { printf("\n\n\n\n\n\n\n\n\n\n\nPlease input correctly!\n\n\n\n\n\n\n\n\n\n\n"); } else { conclution = power(di, zhi);printf("\n%.16f\n", conclution); } } }return 0;}long double power(int di, int zhi){ int i; long double power;if (zhi > 0) { for (i = 1, power = 1.0; i <= zhi; i++) { power *= (long double)di; } } else { for (i = 0, power = di; i >= zhi; i--) { power /= (long double)di; } }return power; }
自定义的函数为自制的一个幂函数
#include <stdio.h>long double power(int di, int zhi);int main(void){ while (1) { int di, zhi; long double conclution; char over;printf("input random to next(q to quit)\n"); scanf_s("%c", &over);if (over == 113) { break; } else { printf("\nPlease input the number(int): "); if (scanf_s("%d^%d", &di, &zhi) == 0) { printf("\n\n\n\n\n\n\n\n\n\n\nPlease input correctly!\n\n\n\n\n\n\n\n\n\n\n"); } else { conclution = power(di, zhi);printf("\n%.16f\n", conclution); } } }return 0;}long double power(int di, int zhi){ int i; long double power;if (zhi > 0) { for (i = 1, power = 1.0; i <= zhi; i++) { power *= (long double)di; } } else { for (i = 0, power = di; i >= zhi; i--) { power /= (long double)di; } }return power; }
自定义的函数为自制的一个幂函数