提前声明,我估计我的程序里有很多错误,但我只问其中一个,试过很多次都无法解决。如果吧主认为我是伸手党,删了就好。第一次发,不太懂规则。
/* C Wondrous function
by: Martin
date: 25/03/2014
if the current term is even
the next term is half the current term
if the current term is odd
the next term is three times the current term, plus 1
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int printWondrous (int start);
int main (int argc, char * argv[]) {
int x;
assert (x > 0);
printf("Enter a integer greater than 0/n");
scanf("%d", &x);
x = printWondrous (x);
if (x == 1) {
printf("%d\n", x);
return EXIT_SUCCESS;
} else if (x % 2 == 0) {
printf("%d ", x);
} else {
printf("%d ", x);
}
return EXIT_SUCCESS;
}
int printWondrous (int start) {
int x;
if (x % 2 == 0) {
int x = start % 2;
} else {
int x=3 * start + 1;
}
return x;
}
当我敲进编译器以后,它告诉我int printWondrous 里的两个x没有用到,完全不明白什么意思,试了各种方法也不会改。
我记得貌似要说什么努力过程,我就直接把一些想说的直接说了
1.我现在大一直接学C,所以对很多东西还不是很理解,但是课程进度快,每周又有必交的作业,所以有时候自己都不知道写些什么
2.这些都是我自己写的,有些格式是看教授例子
3.一开始有更多的错误,比如没加大括号,没定义什么的,我都一一修改了,但是这个真的不知道怎么改。。。
4.不要随便说我是什么伸手党,其实还有更重要还没学过的一部分要加进这个程序里,等我解决这个问题就去继续完成。
5.你们也应该能发现我这个程序是全英文,我在留学,我对function真的不是很懂,教授导师讲的都很难听懂,只能自己看例子琢磨。
6.最后强调,我只想知道为什么int print没有用到x
/* C Wondrous function
by: Martin
date: 25/03/2014
if the current term is even
the next term is half the current term
if the current term is odd
the next term is three times the current term, plus 1
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int printWondrous (int start);
int main (int argc, char * argv[]) {
int x;
assert (x > 0);
printf("Enter a integer greater than 0/n");
scanf("%d", &x);
x = printWondrous (x);
if (x == 1) {
printf("%d\n", x);
return EXIT_SUCCESS;
} else if (x % 2 == 0) {
printf("%d ", x);
} else {
printf("%d ", x);
}
return EXIT_SUCCESS;
}
int printWondrous (int start) {
int x;
if (x % 2 == 0) {
int x = start % 2;
} else {
int x=3 * start + 1;
}
return x;
}
当我敲进编译器以后,它告诉我int printWondrous 里的两个x没有用到,完全不明白什么意思,试了各种方法也不会改。
我记得貌似要说什么努力过程,我就直接把一些想说的直接说了
1.我现在大一直接学C,所以对很多东西还不是很理解,但是课程进度快,每周又有必交的作业,所以有时候自己都不知道写些什么
2.这些都是我自己写的,有些格式是看教授例子
3.一开始有更多的错误,比如没加大括号,没定义什么的,我都一一修改了,但是这个真的不知道怎么改。。。
4.不要随便说我是什么伸手党,其实还有更重要还没学过的一部分要加进这个程序里,等我解决这个问题就去继续完成。
5.你们也应该能发现我这个程序是全英文,我在留学,我对function真的不是很懂,教授导师讲的都很难听懂,只能自己看例子琢磨。
6.最后强调,我只想知道为什么int print没有用到x