#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX 5
void fun_one (int a, int b);
void fun_two (int a, int b);
int
fun_three (void);
int main (void)
{
int i;
int n;
printf ("Enter one integer (1000 to 10000): \n");
scanf ("%d", &i);
srand (time (NULL));
while (i > 1000 && i < 10000)
{
n = fun_three ();
printf ("%d\n", n);
fun_one (i, n);
fun_two (i, n);
printf ("Enter one integer (1000 to 10000): \n");
scanf ("%d", &i);
}
return 0;
}
int fun_three (void)
{
return (1000 + rand() % 9000);
}
void fun_one (int a, int b)
{
char i_stra[MAX];
char i_strb[MAX];
int
n, m;
int
count = 0;
itoa (a, i_stra, 10);
itoa (b, i_strb, 10);
for (n = 0; n < MAX-1; n++)
{
for (m = 0; m < MAX-1; m++)
{
if (i_strb[n] == i_stra[m])
{
count++;
break;
}
}
}
printf ("%d\n", count);
}
void fun_two (int a, int b)
{
char stra[MAX];
char strb[MAX];
int
n, m;
int
count = 0;
itoa (a, stra, 10);
itoa (b, strb, 10);
for (n = 0; n < MAX-1; n++)
{
for (m = 0; m < MAX-1; m++)
{
if (strb[n] == stra[m] && strb[n+1] == stra[m+1])
{
count++;
break;
}
}
}
printf ("%d\n", count);
}
不知道逻辑对不对。。。全当练习了。。。