发新话题
打印

我的疑问

我的疑问

哪位高手可以帮我看看以下几道题,谢了:
# include<stdio.h>
# include<iostream.h>
{
     int a=10;
     int b=20;
     printf("a=%d\n",a);
     cout<<"b="<<b<<endl;
           
       }
这道题目我在"集成学习环境(C语言)"与"Turbo C for Windows 集成实验环境共享版C++中运行时分别出现"
C:\Program Files\集成学习环境(C语言)4.2\bin>tcc.exe -epractice.exe -IINCLUDE -LLIB turboc.c .\LIB\ExtGraph.lib   
Turbo C  Version 2.0  Copyright (c) 1987, 1988 Borland International
turboc.c:
Error turboc.c 2: Unable to open include file 'iostream.h'
Error turboc.c 3: Declaration syntax error"

与"Declaration terminate incorrectly"的提示.
(2)#include "stdio.h"
#include <math.h>
  void  myFunc(int m)
  {
    int n;
    if(m==0)
    for(n=0;n<8;n++)
    {
      t=n*d;
      printf("%f\n",sin(t));
     }
     if(m==1)
     for(n=0;n<8;n++)
     {
       t=n*d;
       printf("%f\n",cos(t));
       }
     }
     void main()
     {
       int m,n;
       float d,t,Pi=3.141593;
       d=(2*Pi)/8;
       printf("打印0~2*Pi的8个等分角的三角函数\n");
       printf("请选择一个整数:0-打印正弦值,1-打印余弦值\n");
       cin<<m;
       myFunc(m);
      
       }
这道题目我在"集成学习环境(C语言)"与在Turbo C for Windows 集成实验环境共享版C++中运行时运行时结果提示均为:
Warning turboc.c 26: Code has no effect in function main
Warning turboc.c 26: Possible use of 'm' before definition in function main
Warning turboc.c 27: Possible use of 'm' before definition in function main
Warning turboc.c 29: 'd' is assigned a value which is never used in function main
*** 3 errors in Compile ***


        Available memory 392194


--编译并连接结束--
当我将程序改为如下后,在两个不同环境中运行的结果 虽然相同,请问是否正确的,为什么会出现两种都不是我预期的答案,正确的答案应该是什么?
#include "stdio.h"
#include <math.h>
  void  myFunc(int m)
  {
    int n,t,d;
    if(m==0)
    for(n=0;n<8;n++)
    {
      t=n*d;
      printf("%f\n",sin(t));
     }
     if(m==1)
     for(n=0;n<8;n++)
     {
       t=n*d;
       printf("%f\n",cos(t));
       }
     }
     void main()
     {
       int m,n,cin;
       float d,t,Pi=3.141593;
       d=(2*Pi)/8;
       printf("打印0~2*Pi的8个等分角的三角函数\n");
       printf("请选择一个整数:0-打印正弦值,1-打印余弦值\n");
       cin<<m;
      myFunc(m);
}
在Turbo C for Windows 集成实验环境共享版C++运行结果:
  打印0~2*Pi的8个等分角的三角函数
  请选择一个整数:0-打印正弦值,1-打印余弦值
  0.000000
  0.801495
  0.958590
  0.344981
  -0.545992
  0.764252
  -0.059874
  0.835862

在"集成学习环境(C语言)"运行结果:

0.000000
  0.801495
  0.958590
  0.344981
  -0.545992
  0.764252
  -0.059874
  0.835862

TOP

发新话题