首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

有个return和getchar()的有关问题

2012-03-19 
有个return和getchar()的问题C/C++ code#include stdio.hmain(){int i,j,nlong sum0,temp0printf(P

有个return和getchar()的问题

C/C++ code
#include <stdio.h>main(){    int i,j,n;    long sum=0,temp=0;    printf("Please input a number to n:\n");    scanf("%d",&n);    if(n<1)    {        printf("The n must no less than 1!\n");        return;    }    for(i=1;i<=n;i++)    {        temp=0;        for(j=1;j<=i;j++)            temp+=j;        sum+=temp;    }    printf("The sum of the sequence(%d) is %d\n",n,sum);    getchar();    getchar();}

1.if后有个return是什么意思,
2.最后的getchar()是有什么作用,这样常见吗?

[解决办法]
1 就是退出的意思
2 防止运行程序后,屏幕一闪而过看不到结果。

这题目好像前几天有人问过。
[解决办法]
楼上说的有道理
[解决办法]
问题1 n必须>=1 否则退出程序
问题2 getchar()用来当system("pause");

热点排行