该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
c语言最简根式
就是感觉写的不太好,大佬能不能把我代码改一下(我就是个编程菜鸟
还有怎么能让输入输出的数无限大(无限大)
#include
#include
#include
#include
int a, b, c, t, *kaif, *kaif2, r = 1;
void main()
{
int wait;
puts("欢迎来到开方神器");
puts("由于开最简二次根式(注意:仅用于整数范围内)");
puts("功能键 清屏:1 退出 :2 ");
while (1)
{
puts("\n请输入原根式:");
printf(":✓");
scanf(" %d", &wait);
if (wait == 2)
exit(1);
if (wait == 1)
clrscr();
else
{
kaigen(wait);
wait = 0;
}
}
}
int kaigen(wait)
{
b = (int)sqrt(wait);
a = wait / 4;
kaif2 = malloc(sizeof(int) * a);
kaif = malloc(sizeof(int) * b);
for (a = 2; a < b + 1; a++)
kaif[a - 2] = a * a;
for (a = 0; a < b - 1; a++)
{
if (wait % kaif[a] == 0)
{
wait /= kaif[a];
kaif2[c] = sqrt(kaif[a]);
// printf("%d\n",kaif[a]);
// printf("%d\n",kaif2[c]);
t++;
a = -1;
c++;
}
}
for (c = 0; c < t; c++)
{
// printf("%d,",kaif2[c]);
r *= kaif2[c];
}
printf("\n化简得:");
if (wait == 1)
printf("%d\n", r);
else
{
if (r != 1)
printf("%d", r);
if (wait != 0)
printf("✓");
printf("%d\n", wait);
}
free(kaif);
free(kaif2);
// printf("%d\n",kaif[0]);
// printf("%d\n",kaif2[2]);
c = 0;
t = 0;
r = 1;
}