demo_3_17

  1 #define _CRT_SECURE_NO_WARNINGS 1
  2 #include <stdio.h>
  3 #include <stdlib.h>
  4 #include <ctype.h>
  5 #include <string.h>
  6 void fun(char *p)
  7 {
  8     int i = 0;
  9     while (p[i])
 10     {
 11         if (p[i] == ' '&&islower(p[i - 1])) p[i - 1] = p[i - 1] - 'a' + 'A';
 12         i++;
 13     }
 14 }
 15 int main()
 16 {
 17     char s1[100] = "ab cd EFG !";
 18     fun(s1);
 19     printf("%s\n", s1);
 20     system("pause");
 21     return 0;
 22 }
 23 
 24 int f(int x)
 25 {
 26     int y;
 27     if (x == 0 || x == 1) return (3);
 28     y = x*x - f(x - 2);
 29     return y;
 30 }
 31 int main()
 32 {
 33     int z;
 34     z = f(3);
 35     printf("%d\n", z);
 36     system("pause");
 37     return 0;
 38 }
 39 
 40 int fun(int x[], int n)
 41 {
 42     static int sum = 0, i;
 43     for (i = 0; i < n; i++)
 44     {
 45         sum += x[i];
 46     }
 47     return sum;
 48 }
 49 int main()
 50 {
 51     int a[] = { 1, 2, 3, 4, 5 }, b[] = { 6, 7, 8, 9 }, s = 0;
 52     s = fun(a, 5) + fun(b, 4);
 53     printf("%d\n", s);
 54     system("pause");
 55     return 0; 
 56 }
 57 
 58 
 59 #include <string.h>
 60 struct A
 61 {
 62     int a;
 63     char b[10];
 64     double c;
 65 };
 66 struct A f(struct A t);
 67 int main()
 68 {
 69     struct A a = { 1001, "ZhangDa", 1098.0 };
 70     a = f(a);
 71     printf("%d,%s,%6.1f\n", a.a, a.b, a.c);
 72     system("pause");
 73     return 0;
 74 }
 75 struct A f(struct A t)
 76 {
 77     t.a = 1002;
 78     strcpy(t.b, "ChangRong");
 79     t.c = 1202.0;
 80     return t;
 81 }
 82 
 83 
 84 int main()
 85 {
 86     FILE *fp;
 87     int k, n, a[6] = { 1, 2, 3, 4, 5, 6 };
 88     fp = fopen("d2.dat", "w");
 89     fprintf(fp, "%d%d%d\n", a[0], a[1], a[2]);
 90     fprintf(fp, "%d%d%d\n", a[3], a[4], a[5]);
 91     fclose(fp);
 92     fp = fopen("d2.dat", "r");
 93     fscanf(fp, "%d%d", &k, &n);
 94     printf("%d%d\n", k, n);
 95     fclose(fp);
 96     system("pause");
 97     return 0;
 98 }
 99 
100 int main()
101 {
102     int k = 5;
103     while (--k)
104     {
105         printf("%d", k -= 3);
106     }
107     printf("\n");
108     system("pause");
109     return 0;
110 }
111 
112 int main()
113 {
114     int i, j;
115     for (i = 3; i >= 1; i--)
116     {
117         for (j = 1; j <= 2; j++)
118         {
119             printf("%d ", i + j);
120         }
121         printf("\n");
122     }
123     system("pause");
124     return 0;
125 }
126 
127 int main()
128 {
129     int k = 5, n = 0;
130     do
131     {
132         switch (k)
133         {
134         case 1:
135         case 3:n += 1; k--; break;
136         default:n = 0; k--;
137         case 2:
138         case 4:n += 2; k--; break;
139         }
140         printf("%d ", n);
141     } while (k > 0 && n < 5);
142     system("pause");
143     return 0; 
144 }
145 
146 
147 void f(int *q)
148 {
149     int i = 0;
150     for (; i < 5; i++) (*q)++;
151 }
152 int main()
153 {
154     int a[5] = { 1, 2, 3, 4, 5 }, i;
155     f(a);
156     for (i = 0; i < 5; i++) printf("%d,", a[i]);
157     system("pause");
158     return 0;
159 }
160 
161 struct S
162 {
163     int n;
164     int a[20];
165 };
166 void f(int *a, int n)
167 {
168     int i;
169     for (i = 0; i < n - 1; i++)
170     {
171         a[i] += i;
172     }
173 }
174 int main()
175 {
176     int i;
177     struct S s = { 10, { 2, 3, 1, 6, 7, 5, 4, 10, 9 } };
178     f(s.a, s.n);
179     for (i = 0; i < s.n; i++)
180     {
181         printf("%d,", s.a[i]);
182     }
183     system("pause");
184     return 0;
185 }
186 
187 
188 typedef struct
189 {
190     char name[9];
191     char sex;
192     float score[2];
193 }STU;
194 void f(STU A)
195 {
196     STU b = { "Zhao", 'm', 85.0, 90.0 };
197     int i;
198     strcpy(c.name, b.name);
199     a.sex = b.sex;
200     for (i = 0; i < 2; i++)
201     {
202         a.score[i] = b.score[i];
203     }
204 }
205 int main()
206 {
207     STU c = { "Qian", 'f', 95.0, 92.0 };
208     f(c);
209     printf("%s,%c,%2.0f,%2.0f\n", c.name, c.sex, c.score[0],c.score[1]);
210     system("pause");
211     return 0;
212 }
213 
214 int main()
215 {
216     char a = 4;
217     printf("%d\n", a = a << 1);
218     system("pause");
219     return 0;
220 }
221 
222 int main()
223 {
224     int x = 12;
225     double y = 3.141593;
226     printf("%d%8.6f\n", x, y);
227     system("pause");
228     return 0;
229 }
230 
231 int main()
232 {
233     int i, j, x = 0;
234     for (i = 0; i < 2; i++)
235     {
236         x++;
237         for (j = 0; j <= 3; j++)
238         {
239             if (j % 2) continue;
240             x++;
241         }
242         x++;
243     }
244     printf("%d\n", x);
245     system("pause");
246     return 0;
247 }

 

posted @ 2022-03-17 22:53  小团熙  阅读(44)  评论(0)    收藏  举报