不工作 [英] cos not working

查看:112
本文介绍了不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI


我是C的新手,这不起作用。我们都知道cos Pi是-1

但这里答案是1.000000 !!!!我使用MS编译所以请帮助!!!

extern void main();

extern int printf();

extern double cos();

void main(){

#define Pi 22/7

printf("%lf",cos (Pi));

返回;

}


回答

1.000000< - - 不对!!!!!


谢谢大家:)

解决方案

Miles Sorenson写道:


HI


我是C的新手,这是行不通的。我们都知道cos Pi是-1

但这里答案是1.000000 !!!!我使用MS编译所以请帮助!!!

extern void main();

extern int printf();

extern double cos();



那里有什么用的?


让我们再试一次,好吗?


#include< math.h>

#include< stdio.h>


int main(void)

{

const double pi = 22.0 / 7;


printf("%lf \ n",cos(pi) );


返回0;

}


c99 -lm test.c


结果:


-0.999999

-

Ian Collins


在文章< Ra ***************** @ newsfe01.iad>,

Miles Sorenson< ; ms ************* @ aol.comwrote:


> extern int printf();
extern double COS();



为什么你自己声明这些功能?这样做非常容易发生错误。改为包括标准标题。


> #define Pi 22/7



22/7是3.这就是你想要的吗?


> printf("%lf",cos(Pi));



cos()采用什么样的参数?一双。但是你是
传递一个整数。由于你的声明很差,

不是原型,它不会被转换为双倍,所以你是完全垃圾传递给函数的



- 理查德

-

请记得提及我/你留下的录音带。


Ian Collins写道:


Miles Sorenson写道:


> HI

我是C的新手,这不起作用。我们都知道cos Pi是-1
但这里答案是1.000000 !!!!我使用MS编译所以请帮助!!!

extern void main();
extern int printf();
extern double cos();



那里有什么用的?


让我们再试一次,好吗?


#include< math.h>

#include< stdio.h>


int main(void)

{

const double pi = 22.0 / 7;


printf("%lf \ n",cos(pi) );


返回0;

}


c99 -lm test.c


结果:


-0.999999



%f用于输出C89和C89中的类型double值C99。


中不作任何内容,作为C99中的printf格式指定符。


%lf使该程序在C89中未定义。


-

pete


HI

I''m newby with C and this is not working. we all know that cos Pi is -1
but answer here is 1.000000 !!!! i use MS compile so please help!!!

extern void main();
extern int printf();
extern double cos();
void main(){
#define Pi 22/7
printf("%lf",cos(Pi));
return;
}

answer
1.000000 <--- not right!!!!!

thanks everyone :)

解决方案

Miles Sorenson wrote:

HI

I''m newby with C and this is not working. we all know that cos Pi is -1
but answer here is 1.000000 !!!! i use MS compile so please help!!!

extern void main();
extern int printf();
extern double cos();

What are all those there for?

Let''s try again, shall we?

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

int main(void)
{
const double pi = 22.0/7;

printf("%lf\n",cos(pi));

return 0;
}

c99 -lm test.c

result:

-0.999999

--
Ian Collins


In article <Ra*****************@newsfe01.iad>,
Miles Sorenson <ms*************@aol.comwrote:

>extern int printf();
extern double cos();

Why are you declaring these functions yourself? Doing so is extremely
error prone. Include the standard headers instead.

>#define Pi 22/7

22/7 is 3. Is that what you want?

>printf("%lf",cos(Pi));

What kind of argument does cos() take? A double. But you''re
passing it an integer. Because of your poor declaration, which
isn''t a prototype, it won''t be converted to a double, so you are
passing complete rubbish to the function.

-- Richard
--
Please remember to mention me / in tapes you leave behind.


Ian Collins wrote:

Miles Sorenson wrote:

>HI

I''m newby with C and this is not working. we all know that cos Pi is -1
but answer here is 1.000000 !!!! i use MS compile so please help!!!

extern void main();
extern int printf();
extern double cos();


What are all those there for?

Let''s try again, shall we?

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

int main(void)
{
const double pi = 22.0/7;

printf("%lf\n",cos(pi));

return 0;
}

c99 -lm test.c

result:

-0.999999


%f is for outputting type double values in both C89 and C99.

The letter ''l'' is allowed, but does nothing, in "%lf"
as a printf format specifer in C99.

The %lf makes that program undefined in C89.

--
pete


这篇关于不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆