c programming 高手請入

2010-10-18 5:12 pm
#include <stdio.h>
int main()
{

int numberoftermstobeaded,n;
int thefirstnumber,a;
int thedifferencebetweeneachnumber,d;
float sum;

n=100;
a=1;
d=1;

sum=(n/2)(2*a+(n-1)d);

printf("the sum of 1 to 100 is %f/n",sum );






getchar();
return 0;
}


我唔明咩叫做 a can not be used as a function

回答 (2)

2010-10-19 1:48 am
✔ 最佳答案
編寫程序和平時寫的方程式不一樣,編譯器需要100%明確。
例如相乘不能寫成 (a)(b),一定要用星號,寫成 (a)*(b),有些舊點的編譯器甚至連加多個括都可能error。只接受 a*b。
sum=(n/2)(2*a+(n-1)d);
應該要寫成 sum = (n/2)*(2*a+(n-1)*d) ;
2010-10-18 8:42 pm
sum=(n/2)(2*a+(n-1)d);

This line is incorrect. There is a missing operator. Maybe it should be:
sum = (n/2) (2*a + (n-1) d );


收錄日期: 2021-04-26 11:27:52
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20101018000051KK00232

檢視 Wayback Machine 備份