[ create a new paste ] login | about

Link: http://codepad.org/KIB6aUQm    [ raw code | output | fork ]

C, pasted on Jan 14:
#include<stdio.h>

void input(void);
void show0(void);
void show1(void);
void show2(void);
void show3(void);


int main(void)
{
	void (*pM[4])(void);
	int num;
	int x, y;

	pM[0] = show0;
	pM[1] = show1;
	pM[2] = show2;
	pM[3] = show3;


	printf("どの演算をしますか?(0:加算 1:減算 2:最大値 3:最小値)\n");
	scanf("%d", &num);

	if(0 <= num && num <= 3)
		(*pM[num])();

	return 0;
}

int x, y;

void input(void);

void input(void){
printf("1つ目の整数数値入力\n");
scanf("%d", &x);

printf("2つ目の整数数値入力\n");
scanf("%d", &y);
}

void show0(void)
{
input();
	printf("加算結果は%dです\n", x + y);
}

void show1(void)
{
input();
	printf("減算結果は%dです\n", x - y);
}
void show2(void)
{
input();
	if (x > y)
		printf("最大値は%dです\n", x);
	else
		printf("最大値は%dです\n", y);
}
void show3(void)
{
input();

	if (y < x)
		printf("最小値は%dです\n", y);
	else
		printf("最小値は%dです\n", x);
}


Output:
1
どの演算をしますか?(0:加算 1:減算 2:最大値 3:最小値)


Create a new paste based on this one


Comments: