Current location - Recipe Complete Network - Complete cookbook of home-style dishes - C language menu programming
C language menu programming
# include & ltstdio.h & gt

# include & ltmath.h & gt

void armstrong(int a)

{

int I;

int n = 1;

int b = a;

int s = 0;

And (b/=10) n++;

b = a;

for(I = 0; I & ltn;; i ++){

s += (int)pow(b% 10,n);

b/= 10;

}

if(s == a){

Printf("%d is the number of daffodils! \n ",a);

} Otherwise {

Printf("%d is not daffodil! \n ",a);

}

}

void prime(int a)

{

int I;

If (a & lt2) {

Printf("%d is not a prime number! \n ",a);

Return;

}

for(I = 2; I & lta;; i ++){

if(a % i == 0) {

Printf("%d is not a prime number! \n ",a);

Return;

}

}

Printf("%d is a prime number! \n ",a);

}

void max(int a,int b,int c)

{

If (b & gta)a = b;;

if(c & gt; a)a = c;

Printf ("Maximum value: %d\n", a);

}

Void factorial (int a)

{

int I;

int f = 1;

for(I = a; I> 1; I-)

f * = I;

The factorial of printf("% d ") is: %d\n", a, f);

}

int main(int argc,char **argv)

{

int a,b,c;

Int type;

int run = 1;

Printf ("This program can do some mathematical calculations: \ n");

printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n "

* 1. Determines whether a number is a daffodil number. *\n "

"* 2. Judge whether a number is a prime number. *\n "

"* 3. Find the maximum value of three numbers. *\n "

"* 4. Find the factorial of a number. *\n "

"* 0. Exit. *\n "

“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n”);

Do {

Printf ("Please press the menu to select (0-4):");

Scanf("%d ",& type);

Switch (type)

Case 0:

while( 1){

getchar();

Printf ("Are you sure you want to quit? (y/n)");

a = getchar();

Switch (a)

Case "y":

run = 0;

Break;

Case "n":

run = 1;

Break;

Default value:

Break;

}

if((a = = ' y ')| |(a = = ' n '))break;

}

Break;

Case 1:

Printf ("Please enter a number:");

scanf("%d ",& ampa);

Armstrong (a);

Break;

Case 2:

Printf ("Please enter a number:");

scanf("%d ",& ampa);

Prime number (a);

Break;

Case 3:

Printf ("Please enter three numbers:");

Scanf("%d%d%d ",& i, & ampb & amp;; c);

max(a,b,c);

Break;

Case 4:

Printf ("Please enter a number:");

scanf("%d ",& ampa);

Factorial (a);

Break;

Default value:

Break;

}

}while (running);

Returns 0;

}