C言語_関数構造体の呼び出し
2340 ワード
C言語_関数構造体の呼び出し
#include
//
struct map{
// void
void (*p)();
};
/*
* ,
*/
void one();
// , ASCIL ,
void two();
// 。 ,
void three();
// , , , , , p ,
void four();
// 3.156e+7 , , ,
void five();
// 3.0e-23 ,1 950 , , , 。
void six();
// 2.54 , , (/ ), 。
void seven();
// ,1 2 ,1 8 ,1 2 ,1 3 , ,
// , , , , 。 , 。
void eight();
int main(){
//
struct map ma[30];
//
ma[0]={one};
ma[1]={two};
ma[2]={three};
ma[3]={four};
ma[4]={five};
ma[5]={six};
ma[6]={seven};
ma[7]={eight};
printf(" :
");
int size=0;
//
fflush(stdout);
// size float
scanf("%d",&size);
//
ma[size].p();
//
return 0;
};
void one(){
int size=333333333333;
float fl=444.1111111111111111111111111;
printf("%d %f %f
",size,fl,-fl);
};
//
void two(){
int vb;
/*
* scanf() ,int char 。 &
*/
scanf("%d",&vb);
printf("%c
",vb);
};
void three(){
printf("Startled by the sudden sound,Sally shouted,
By the Great Pumpkin,what was that! \a");
};
void four(){
float a;
scanf("%f",&a);
printf("%f %e %a
",a,a,a);
};
void five(){
int age;
printf(" :
");
// stdout, stdout
fflush(stdout);
scanf("%d",&age);
printf(" :%e",age*3.156e+7);
};
void six(){
printf(" :
");
fflush(stdout);
int size;
scanf("%d",&size);
printf(" %d %e :
",size,size*950/3.0e-23);
};
void seven(){
printf(" (/ )
");
fflush(stdout);
float height;
scanf("%f",&height);
printf(" :%f\ !
",height*2.54f);
};
void eight(){
printf(" !
");
fflush(stdout);
float bow;
scanf("%f",&bow);
float bow1=bow;
float pintuo=bow/2;
bow*=8;
float angsi=bow;
bow*=2;
float tangshao=bow;
bow*=3;
float chashao=bow;
printf("%f %f ,%f ,%f ,%f !
",bow1,pintuo,angsi,tangshao,chashao);
};