gpt4 book ai didi

c - 获取进程返回-1073741819 (0xC0000005)错误而不是答案

转载 作者:行者123 更新时间:2023-11-30 19:04:02 29 4
gpt4 key购买 nike

当我尝试获取答案时,出现以下错误: 进程返回“-1073741819 (0xC0000005)”。我的目标很简单:我从用户那里获取 4 个数字,1 个用于菜单,另外 3 个用于进行数学运算,但我无法得到答案:它卡住了。

我的代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{
int menu,t1,t2,sonuc1;
double r1,sonuc,sonuc2;
printf("\t*************Menu*****************\n");
printf("\n");
printf("1.\t SADECE TAM SAYILARI TOPLA\n");
printf("2.\t TAM SAYILARI TOPLA REEL SAYI ILE CARP\n");
printf("3.\t REEL SAYININ KARESİNİ ALARAK 1.TAM SAYI İLE ÇARP\n");
printf("4.\t CIKIS\n");
printf("Seciniz:");
scanf("%d",&menu);
if(menu == 4){
printf("Hoscakal");
return 0;
}
else if (menu !=1 && menu !=2 && menu !=3){
printf("Gecersiz Deger!");
return 0;
}
printf("\nBirinci tam sayiyi giriniz: ");
scanf("%d",&t1);
printf("\nIkinci tam sayiyi giriniz: ");
scanf("%d",&t2);
if (t2==0){
t2 = 1;
}
printf("\nReel sayiyi giriniz: ");
scanf("%lf",r1);
if(r1>0 || r1 == 0){
r1 = -1;
}
if(menu == 1){
sonuc1 = (t1+t2);
printf("Sonuc: %d",sonuc1);
}
else if(menu == 2) {
sonuc = (t1+t2)*r1;
printf("Sonuc: %lf",sonuc);
}
else if(menu == 3) {
sonuc2 = (r1*r1)*t1;
printf("Sonuc: %lf",sonuc2);
}
}

输出:output

最佳答案

scanf("%lf",r1);

scanf%lf 格式说明符需要一个 double *,但您传入的是一个 double >。格式说明符和给定参数之间的不匹配会调用 undefined behavior ,在这种情况下会导致崩溃。

将其更改为:

scanf("%lf",&r1);

关于c - 获取进程返回-1073741819 (0xC0000005)错误而不是答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53070750/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com