# Prime number, palindrome number, intimacy number, narcissus number

```#include<stdio.h>

void huiwen();
void sushu();
void qinmi();
void shuixian();
int main()
{
int n;
while(1)
{
printf("\n Enter 0 for exit\n Input 1 to find the number of palindromes\n Input 2 to find prime number\n Enter 3 for intimacy\n Enter 4 to find the number of daffodils\n: ");
scanf("%d",&n);
switch(n)
{
case 0:printf("Sign out\n"); return;
case 1:huiwen(); break;
case 2:sushu(); break;
case 3:qinmi(); break;
case 4:shuixian(); break;
}
}

return 0;
}

void huiwen()
{
int a,b,c,d,i,n;
printf("Please enter N Find the number of palindromes in the range:");
scanf("%d",&n);
printf("1 reach%dThe number of palindromes in is:",n) ;
if(n<10)
{
for(i=1;i<=n;i++)
printf("%d  ",i);
}
if(n>=10&&n<100)
{
for(i=0;i<10;i++)
printf("%d  ",i);
for(i=10;i<=n;i++)
{
a=i/10;
b=i%10;
if(a==b)
printf("%d  ",i);
}
}
if(n>=100&&n<1000)
{
for(i=0;i<10;i++)
printf("%d  ",i);
for(i=10;i<=100;i++)
{
a=i/10;
b=i%10;
if(a==b)
printf("%d  ",i);
}
for(i=100;i<=n;i++)
{
c=i/100;
d=i%10;
if(c==d)
printf("%d  ",i);
}
}
}

void sushu()
{
int i,j,n;
printf("Please enter N Prime the numbers in the range:");
scanf("%d",&n);
printf("1 reach%dThe prime numbers between are:",n);
for(i=2;i<=n;i++)
{
for(j=2;j<=i-1;j++)
{
if(i%j==0)
break;
}
if(j>=i)
printf("%d  ",i);
}
}

void qinmi()
{
int a,b,j,i,n;
printf("Please enter N The number within the range is the intimacy number:") ;
scanf("%d",&n);
printf("Intimacy:");
for(a=1;a<n;a++)
{
for(b=0,i=1;i<=a/2;i++)
if(!(a%i))
b+=i;
for(j=0,i=1;i<=b/2;i++)
if(!(b%i))
j+=i;
if(j==a&&a<b)
printf("%dAnd%d  ",a,b);
}
}

void shuixian()
{
int a,b,c,i,n;
printf("Please enter N The number of Narcissus in the range\n:");//N The number of Narcissus is above three digits
scanf("%d",&n);
printf("The number of Narcissus is:");
if(n<1000&&n>100)
for(i=100;i<=n;i++)
{
a=i/100;
b=(i/10)%10;
c=i%10;
if(a*a*a+b*b*b+c*c*c==i)
printf("%d  ",i);
}
}
```

① The modular programming method is adopted, and each special number is calculated by a function.
② The main program designs a function menu, and calls each sub function through the menu. The format is as follows:
0. Exit
1. Number of palindromes
2. Prime number
3. Intimacy
4. Number of Narcissus
③ Design and output the judgment and output function of various special numbers between 1 and n
(3) Design Tips
Intimacy number: if the sum of all factors of integer A (including 1, excluding A itself) is equal to integer B, and the sum of all factors of integer B (including 1, excluding B itself) is equal to integer A, then integers A and B are called intimacy numbers

Tags: Programming

Posted on Sat, 02 May 2020 04:20:16 -0700 by markmil2002