我对 C 很陌生,所以我的问题可能看起来很初步,对此感到抱歉!我想在 C 中创建一个具有 N 行(在下面的代码中 N = 100)和 1 列的二维矩阵,通过将恒定量乘以每个元素(基于其索引)来生成下一个元素。这是我尝试过的代码,但它不起作用:
#include<stdio.h>
int main()
{
float a[100];
int i;
for (i = 0; i < 100; i++)
{
a[i] = 3.08e-7+(i-1)*0.9e-7;
printf("%d\n", a[i]);
}
return 0;
}
如果有人能给我提示,我将非常感激。
最佳答案
我假设您不想在循环的第一次迭代中乘以 -1。请尝试以下操作:
#include<stdio.h>
int main()
{
float a[100];
int i;
for (i = 1; i <= 100; i++)
{
a[i-1] = 3.08e-7 + i * 0.9e-7;
printf("%f\n", a[i-1]);
}
return 0;
}
关于c - 用C中的for循环制作矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27441007/