需要有关程序的帮助!!! [英] Need help with the program!!!

查看:64
本文介绍了需要有关程序的帮助!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我是C语言的初学者.所以我在程序中遇到了两个数字并显示总和的问题.这是代码!

Hello everyone! I''m the beginner in C. So i have the problem with the program to take two numbers and display the sum. Here is the code!

#include <stdio.h>
main()
{
      int a,b,sum;
      printf("\nType your frist number: ");
      scanf("%d" , &a);
      printf("\nType your second number: ");
      scanf("%d", &b);
      sum=a+b;
      printf("\n The sum of two number you have just type is %d", sum);
      printf("\nPress enter to continue");
}



我在Dev-C ++中成功编译了它.问题是:当我运行它并输入2个数字时.该程序不会在结果行中停止:两个数字之和...."供我查看结果.该行显示后立即终止.

我在Windows 7 64bit上运行Dev-C ++(版本4.9.9.2).

非常感谢您,我的英语不好. (我来自越南,您知道^^)



I compile it successfully in Dev-C++. The problem is: when i run it and input 2 numbers. The program won''t stop at the result line: "The sum of two number...." for me to view the result. It terminate immediately after that line show up.

I running Dev-C++ (version 4.9.9.2) on Windows 7 64bit.

Thank you very much and sorry for my bad English. (I''m from Vietnam, you know ^^)

推荐答案

只需添加
getch();
在最后一个printf之后.
Just add
getch();
after the last printf.


在您输入两个数字之后,没有代码可以使程序停止在任何地方.

如果要让它运行其他计算,请使用while循环,直到满足特定条件(此处均为空):
There is no code that let the program stop anywhere after you have entered the two numbers.

If you want to let it run for another calculation, use a while loop until a specific condition is met (both numbers null here):
main()
{
    int a,b,sum;
    do
    {
        printf("\nType your frist number: ");
        scanf("%d" , &a);
        printf("\nType your second number: ");
        scanf("%d", &b);
        sum=a+b;
        printf("\n The sum of two number you have just type is %d", sum);
        printf("\nEnter null for both numbers to terminate");
    }
    while (a != 0 || b != 0);
}


这篇关于需要有关程序的帮助!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆