| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 557 人关注过本帖
标题:一个简单计算机C语言程序
只看楼主 加入收藏
gchs2012
Rank: 1
等 级:新手上路
帖 子:5
专家分:4
注 册:2011-10-26
结帖率:0
收藏
已结贴  问题点数:5 回复次数:1 
一个简单计算机C语言程序
/*
 purpose:sin和cos函数的实现
 author:Zhang can
 created:2011/10/27 15:19:15
*/

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
    int nfun=1;
    double dsin=0.0,dcos=0.0,dtemp=1.0,darc=0.0;                 /* 变量声明初始化 */
    int k=0;
    double pi=3.1415926,dmin=0.000001,ddegree=0.0;
    double dloper,droper,dresult;
    while(nfun!=9)
    {
        system("cls");                                           //clrscr();
        printf("  ----------------------------\n");              /* 构造功能菜单 */
        printf("      加法运算---------->1\n");
        printf("      减法运算---------->2\n");
        printf("      除法运算---------->3\n");
        printf("      乘法运算---------->4\n");
        printf("      sinx运算---------->5\n");
        printf("      cosx运算---------->6\n");
        printf("      退出-------------->9\n");
        printf("  ----------------------------\n");
        printf(" 请输入功能选择:");                              /* 在屏幕上显示提示信息 */
        scanf("%d",&nfun);
        switch(nfun)
        {
            case 1:                                               /* 加法运算过程 */                           
                   printf(" 请输入两个操作数:");            
                   scanf("%lf%lf",&dloper,&droper);
                   dresult=dloper+droper;
                   printf(" 计算结果为:%8.3lf\n",dresult);
                   printf(" 按任意键返回菜单.\n");
                   getch();
                   break;
            case 2:                                               /* 减法运算过程 */
                   printf(" 请输入两个操作数:");
                   scanf("%lf%lf",&dloper,&droper);
                   dresult=dloper-droper;
                   printf(" 计算结果为:%8.3lf\n",dresult);
                   printf(" 按任意键返回菜单.\n");
                   getch();
                   break;
            case 3:                                               /* 除法运算过程 */
                   printf(" 请输入两个操作数:");
                   scanf("%lf%lf",&dloper,&droper);
                   if(droper==0)
                   {
                       printf(" 右操作数不能为0\n");
                       return;
                   }
                   else
                   dresult=dloper/droper;
                   printf(" 计算结果为:%8.3lf\n",dresult);
                   printf(" 按任意键返回菜单.\n");
                   getch();
                   break;
            case 4:                                                /* 乘法运算过程 */
                   printf(" 请输入两个操作数:");
                   scanf("%lf%lf",&dloper,&droper);
                   dresult=dloper*droper;
                   printf(" 计算结果为:%8.3lf\n",dresult);
                   printf(" 按任意键返回菜单.\n");
                   getch();
                   break;
            case 5:                                                /* sinx运算过程 */
                   printf(" 请输入弧度:");
                   scanf("%lf",&ddegree);
                   dtemp=ddegree*pi/180;                           /* 进行角度度量转换 */
                   darc=ddegree*pi/180;
                   while(fabs(dtemp)>dmin)                         /* 特勒展开项是否达到精度 */
                   {
                       dsin+=dtemp;                                /* sin函数的特勒展开式 */
                       k+=2;                                       /* 利用前次运算结果计算特勒展开项的值 */
                       dtemp=(-1)*dtemp*darc*darc/((k+1)*k);
                   }
                   printf("  sin(%f)=%lf\n",ddegree,dsin);
                   printf(" 按任意键返回菜单.\n");
                   getch();
                   break;
            case 6:                                                /* cosx运算过程 */
                   printf(" 请输入弧度:");
                   scanf("%lf",&ddegree);                          /* 输入计算的弧度数据 */
                   darc=ddegree*pi/180;                            /* 进行角度度量转换 */
                   while(fabs(dtemp)>dmin)                         /* 特勒展开项是否达到精度 */
                   {
                       dcos+=dtemp;                                /* cos函数的特勒展开式 */
                       k+=2;
                       dtemp=(-1)*dtemp*darc*darc/((k-1)*k);       /* 利用前次运算结果计算特勒展开项的值 */
                   }
                   printf(" cos(%f)=%lf\n",ddegree,dcos);
                   printf(" 按任意键返回菜单.\n");
                   getch();
                   break;
            case 9:
                   break;
            default:
                    printf(" 输入的选项编码错误!按任意键返回菜单.\n");
                    getch();
        }
    }
}
搜索更多相关主题的帖子: 计算机 声明 created include purpose 
2011-10-28 16:47
福利费
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:109
专家分:197
注 册:2010-9-26
收藏
得分:5 
  system("cls");                                           //clrscr();
把//clrscr();
改成/*clrscr();*/就可以了
2011-10-28 17:06
快速回复:一个简单计算机C语言程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016653 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved