macdeMac:代码 mac$ cc 05-循环.c
05-循环.c:2:1: warning: type specifier missing, defaults to 'int'
[-Wimplicit-int]
main()
^~~~
05-循环.c:4:13: error: non-ASCII characters are not allowed outside of
literals and identifiers
int i,n;
^~
05-循环.c:4:13: error: expected ';' at end of declaration
int i,n;
^
;
05-循环.c:7:16: warning: format specifies type 'float *' but the argument has
type 'int *' [-Wformat]
scanf("%f",&n);//输入数值
~~ ^~
%d
05-循环.c:14:5: warning: implicit declaration of function 'system' is invalid
in C99 [-Wimplicit-function-declaration]
system("pause");
^
3 warnings and 2 errors generated.
肖伟 发表于 2014-7-28 14:04
macdeMac:代码 mac$ cc 05-循环.c
05-循环.c:2:1: warning: type specifier missing, defaults to 'int' ...
谢谢,已经解决了
#include <stdio.h>
int main()
{
//定义一个接受正整数的变量
int n=0;
printf("请输入计算的位数(正整数)\n");
scanf("%d",&n);
int sum =0;//存储和
int number = 0;//默认被加的数据
while (number<n) {
number++;
if (number%2==0) {
sum-=number;
}
if(number%2!=0){
sum+=number;
}
}
printf("%d\n",sum);
return 0;
}
#include <stdio.h>
int main()
{
//定义一个接受正整数的变量
int n=0;
printf("请输入计算的位数(正整数)\n");
scanf("%d",&n);
int sum =0;//存储和
int number = 0;//默认被加的数据
while (number<n) {
number++;
if (number%2==0) {
sum-=number;
}
if(number%2!=0){
sum+=number;
}
}
printf("%d\n",sum);
return 0;
}