|
发表于 2021-12-29 17:03:15
|
显示全部楼层
1 #include <stdio.h>
2 int main(int argc, char **argv)
3 {
4 int input[2048], odd[1024], even[1024];
5 char ch[10];
6 int i = 1, j, k = 1, m = 1, n;
7 while(1)
8 {
9 printf("please input number %d, and press Enter\n",i);
10 scanf("%d",&input[i]);
11 ch[1] = getchar();
12 printf("Do you want to continue input: Y/N\n");
13 scanf("%c",&ch[2]);
14 ch[1] = getchar();
15 if(ch[2] == 'y' || ch[2] == 'Y')
16 {
17 printf("ch2 = %c\n",ch[2]);
18 i++;
19 continue;
20 }
21 else
22 {
23 break;
24 }
25 }
26
27 for(j = 1; j <= i; j++)
28 {
29 if(input[j]%2 != 0)
30 {
31 printf("%d is a odd\n",input[j]);
32 odd[k++] = input[j]; //this arrays save odd
33 }
34 else
35 {
36 printf("%d is a even\n",input[j]);
37 even[m++] = input[j]; //this arrays save even
38 }
39 }
40
41 printf("all odd are:\n");
42 for(j = 1; j < k; j++)
43 {
44 printf("%d ",odd[j]);
45 }
46 printf("\nall even are:\n");
47 for(j = 1; j < m; j++)
48 {
49 printf("%d ",even[j]);
50 }
51 printf("\n about odd sum and even sequence, please do it by yourself !!!\n");
52
53 return 0;
54 }
|
|