プロが教えるわが家の防犯対策術!

sin,cos,tanを0~90度を出せっていわれたのですが

#include<stdio.h>
#include<math.h>

main()
{
int N;
float x;
char*line="-------------------------------------\n";

printf(line);
printf("%3s %5s %10s %13s \n",
"kakudo", "sin","cos","tan");

for(N=0; N<=90; ++N)
{
x=N*3.14159265358979323846264338327950288/180;
if(N%10==1)
{
printf(line);
}
if(N=90)
{
tan(N)= ;
}
printf("%3d %7.6f %10.6f %13.6f \n",
N, sin(x), cos(x), tan(x));
}
printf(line);
}

で出ません。
間違いは
if(N=90){tan(N)= ;}
の部分なのですが、どうすれば出せますか?

A 回答 (4件)

すでに、間違っている箇所は分かっているのですね。


でもどう処理するか分からないということでしょうか?
forをN=90まで回さず、打ち切って別に処理すればよいのです。
-- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< --
#include <stdio.h>
#include <math.h>

int
main(void)
{
int N;
float x;
char *line = "-------------------------------------\n";

printf(line);
printf("%3s %5s %10s %13s \n", "kakudo", "sin", "cos", "tan");

for (N = 0; N < 90; ++N) {
x = N * M_PI / 180;
if (N % 10 == 1) {
printf(line);
}
printf("%3d %7.6f %10.6f %13.6f \n", N, sin(x), cos(x), tan(x));
}
x = 90 * M_PI / 180;
printf("%3d %7.6f %10.6f %13s\n", N, sin(x), cos(x), "∞");
printf(line);
return 0;
}
    • good
    • 0

おそらく、



if(N==90){tan(N)=・・・
  ~~
が正しいのではないでしょうか?
    • good
    • 0

>if(N=90)


条件式の部分で、意図しないはずの代入が行われています。
>tan(N)= ;
関数は、左辺値にはなりません。(代入できません)
引数がラジアンではありません。
tan(90°) の時に計算不能だとしたら、
その時に、
printf("%3d %7.6f %10.6f %13.6f \n",N, sin(x), cos(x), tan(x));
のように、tan(x) を含めることができません。
    • good
    • 0

N=90 という式の意味を考えてみましょう.

この回答への補足

すみません、かなり素人なので
「Nが90の時は…」と考えているのですが。

補足日時:2006/04/21 13:24
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!