C/C++の宿題を片付けます 96代目at TECH
C/C++の宿題を片付けます 96代目 - 暇つぶし2ch434:デフォルトの名無しさん
07/09/27 17:36:19
>>428 関数名が悪い
#include <stdio.h>
#include <stdlib.h>
float calc(float,float,int);
int main()
{
int i,s;
float a,b;
char mode[]="+-*/";
printf("1つ目の数=>");scanf("%f",&a);
printf("2つ目の数=>");scanf("%f",&b);
printf("演算子\n");
for(i = 0;i < sizeof(mode)-1;i++){
printf("%d.%c\n",i+1,mode[i]);
}
printf("=>");scanf("%d",&s);

printf("%f %c %f = %f",a,mode[s-1],b,calc(a,b,s));
return 0;
}

float calc(float a,float b,int s)
{
switch(s){
case 1:return a+b;
case 2:return a-b;
case 3:return a*b;
case 4:if(b == 0){printf("0では割れない");exit(1);
}else{return a/b;}
default:printf("演算子指定が正しくない");exit(1);
}
}


次ページ
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch