问题在于:http://cps125.scs.ryerson.ca/labs/homework8.gif
这是我的尝试:
#include <stdio.h>
void tenfold(int (*array1)[9], int (*array2)[9])
{
int i;
for (i = 0; i < 9; i++) {
if ((*array1)[i] > 0) {
(*array2)[i] = 10 * (*array1)[i];
} else {
(*array2)[i] = (*array1)[i];
}
}
}
int main()
{
int array1[9] = { 3, 4, 5, 6, 7, -8, -9, 1, 2 }, array2[9], i;
tenfold(&array1, &array2);
for (i=0; i < 9; i++) {
printf("%lf ", array2[i]);
}
return 0;
}
这是输出:
44100667367791664000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000.000000 441006673677917200000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000.000000 4410066736779177 60000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000.000000 4410066736779183200000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000.000000 44100667367791888000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000.000000 44100691391845304000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000.000000 441006913918452980000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000.000000 4410066736779155 20000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000.000000 4410066736779160800000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000.000000
答案 0 :(得分:4)
这里至少存在一个问题:
printf("%lf ", array2[i]);
%lf
字面意思是“长浮动”,但是你想打印整数:
printf("%i\n", array2[i]);
还要记住printf等待\n
刷新。
编辑:正如newacct指出的那样,%f
和%lf
最后都是double
,因为varargs将float
提升为double
。
答案 1 :(得分:0)
无需在函数tenfold
将其定义为以下
void tenfold(int array1[9], int array2[9])
使用*
和array1
进入函数array2
tenfold
void tenfold(int array1[9], int array2[9])
{
int i;
for (i = 0; i < 9; i++) {
if ((array1)[i] > 0) {
(array2)[i] = 10 * (array1)[i];
} else {
(array2)[i] = (array1)[i];
}
}
}
当您在tenfold
中调用main
函数时:
tenfold(array1, array2);
答案 2 :(得分:0)
“%lf”是float的格式,而不是int。