标题:关于c指针函数的问题
取消只看楼主
gunuanguang
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-9-17
结帖率:0
已结贴  问题点数:10 回复次数:0 
关于c指针函数的问题
最近在学习c语言指针部分,用到指针函数,写了如下程序,运行有错误。但我明明觉得不错哇!望高手赐教!!
#include <stdio.h>


void main()
{
    double add(double,double);    //declare add,sub,mul,div functions
    double sub(double,double);
    double mul(double,double);
    double div(double,double);
   
    double (*oper_fun[])(double,double)={add,sub,mul,div};

    while(1)
    {   
        double a,b,c;
        printf("This is a simple calculator,it has 5 functions as follows!\n");
        printf("1.add\t2.sub\t3.mul\t4.div\t");
        printf("Please enter as such format:number number operation\n");
        scanf("%f%f%d",&a,&b,&c);
        printf("Result is:%f\n",oper_fun[ c - 1](a,b));
    }


}

    double add(double x,double y)    //add function
    {return x+y;}
    double sub(double x,double y)    //sub function
    {return x-y;}
    double mul(double x,double y)    //mul function
    {return x*y;}
    double div(double x,double y)    //div function
    {return x/y;}

搜索更多相关主题的帖子: double simple include calculator div 
2012-10-01 21:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-382424-1-1.html




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

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