第5回課題の解答例
課題1
#include <stdio.h>
int main()
{
int i;
float height[5] = {175.2, 182.6, 166.5, 167.8, 170.0};
float max = 0.0;
for (i=0; i<5; i++)
{
if (max<height[i])
{
max = height[i];
}
}
printf("max=%.1f\n", max);
return 0;
}
課題2
#include <stdio.h>
#define N 5
int main()
{
int v[N], w[N], total;
int i;
printf("v?\n");
for (i=0; i<N; i++)
{
scanf("%d", &v[i]);
}
printf("w?\n");
for (i=0; i<N; i++)
{
scanf("%d", &w[i]);
}
total = 0.0;
for (i=0; i<N; i++)
{
total += v[i]*w[i];
}
printf("inner product: %d\n", total);
return 0;
}
課題3
#include <stdio.h>
int main()
{
char moji[1000];
int i=0;
scanf("%s", moji);
while (moji[i]!='\0')
{
i++;
}
printf("%d\n", i);
return 0;
}