SCANF的程序不在Visual Studio代码中执行

发布于 2025-01-24 04:51:45 字数 938 浏览 1 评论 0原文

我是C编程的新手,每当我尝试使用SCANF运行代码时,我都不会执行。

#include <stdio.h>
int main() 
{
int a,b,s;
printf("Enter the first no: \n");
scanf("%d",&a);
printf("Enter the second number: \n");
scanf("%d",&b);
s=a+b;
printf("%d",s);
}

I get this output:

[Running] cd "c:\msys64\mingw32\bin\" && gcc Prog1.c -o Prog1 && "c:\msys64\mingw32\bin\"Prog1

and this upon termination:

[Done] exited with code=1 in 6.586 seconds

The exact same code works without scanf.

#include <stdio.h>
int main()
{
int a=3,b=5,s;
printf("Enter first no: \n");
printf("Enter the second no: \n");
s=a+b;
printf("%d",s);
}

Output:

Enter first no: 
Enter the second no: 
8

This is what happens on executing in cmd prompt:

[1]: https://i.sstatic.net/o08a9.jpg

I'm new to C programming and whenever I try to run a code with the scanf it doesn't execute.

#include <stdio.h>
int main() 
{
int a,b,s;
printf("Enter the first no: \n");
scanf("%d",&a);
printf("Enter the second number: \n");
scanf("%d",&b);
s=a+b;
printf("%d",s);
}

I get this output:

[Running] cd "c:\msys64\mingw32\bin\" && gcc Prog1.c -o Prog1 && "c:\msys64\mingw32\bin\"Prog1

and this upon termination:

[Done] exited with code=1 in 6.586 seconds

The exact same code works without scanf.

#include <stdio.h>
int main()
{
int a=3,b=5,s;
printf("Enter first no: \n");
printf("Enter the second no: \n");
s=a+b;
printf("%d",s);
}

Output:

Enter first no: 
Enter the second no: 
8

This is what happens on executing in cmd prompt:

[1]: https://i.sstatic.net/o08a9.jpg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文