即時試圖計算帶結構的分數,編譯器說,初始化器列表不能轉換,究竟是什麼問題?這裏是我的代碼計算結構中的分數c
#include <stdio.h>
struct fraction{
int z = 0;
int n = 1;
};
struct fraction addition(struct fraction b1, struct fraction b2) {
struct fraction result;
result.z = b1.z*b2.n + b2.z*b1.n;
result.n = b1.n*b2.n;
return result;
}
void Print(struct fraction b) {
printf("%d/%d\n", b.z, b.n);
}
int main() {
int i;
struct fraction b1 = { 1,1 }, b2 = { 1,2 };
try {
for (i = 1; i <= 6; i++) {
Print(addition(b1, b2));
}
}
catch (int exception) {
printf("Program closed!");
}
}
了由單向循環是調和級數,但我不是用它做呢。感謝您的幫助提前
'int z = 0; int n = 1;' - >'int z; int n;'。 – BLUEPIXY
C或C++?標題說「C」,標籤說「C++」。 –
@ Sparkm4n我刪除了你的C標籤。因爲你的代碼顯然是C++而不是C。但是後來我注意到你的標題是C.請說明你正在使用哪種語言。它們並不相同,每種語言的答案可能不同。 – kaylum