【发布时间】:2021-06-18 08:39:19
【问题描述】:
我必须编写一个将数字从 1 乘到 N 的 C 程序。 N 被扫描。在乘法之前,我必须将每个数字增加 2。 例如:N = 3 => (1+2)(2+2)(3+2) = 60 我只需要使用while循环和打印和扫描功能。
示例程序:
Enter the value of N: 4
The result of multiplication: 360
这是我的代码,我不确定这有什么问题。请帮忙。
#include <stdio.h>
int N;
int count=1, ii, result;
printf("Enter the value of N:");
scanf("%d", &N);
while (count<=N)
{
count ii = count + 2;
ii = ii * ii ; //three
count++;
}
result = ii;
printf("The result of multiplication: %d", result);
return 0;
}
【问题讨论】:
-
看起来你在找
(N+2)! / 2 -
提示:
x *= x是x = x * x的简写形式。 -
count ii = ...没有任何意义,因为count和ii都是变量。
标签: c loops while-loop