1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 #include <string.h> 5 6 #define NUM 3 7 #define N 10 8 struct person 9 { 10 //声明结构体类型 11 char name[20]; 12 char phone[10]; 13 }; 14 15 struct stu 16 { 17 int num; 18 char *name; 19 char sex; 20 float score; 21 }boy = {102,"张三",‘M‘,78.5}; 22 23 typedef struct date 24 { 25 int year; 26 int month; 27 int day; 28 }DATE; 29 typedef struct student 30 { 31 long studentID; 32 char studentName[10]; 33 char studentSex; 34 DATE birthday; 35 int score[4]; 36 }STUDENT; 37 int main1444444() 38 { 39 #if( 0 ) 40 struct person man[NUM]; //定义结构体数组 41 int i; 42 for ( i = 0; i < NUM; i++) 43 { 44 //初始化 45 printf("input name:\n"); 46 gets(man[i].name); 47 printf("input phone:\n"); 48 gets(man[i].phone); 49 } 50 printf("\t\tname\t\t\t\t\tphone\n\n"); 51 for ( i = 0; i < NUM; i++) 52 { 53 printf("%20s\t\t\t%20s\n",man[i].name,man[i].phone); 54 } 55 system("pause"); 56 #endif //结构体数组 57 58 #if( 0 ) 59 struct stu *pstu; 60 pstu = &boy; 61 printf("Number = %d\nName = %s\n",boy.num,boy.name); 62 printf("Sex = %c\nScore = %f\n\n",boy.sex,boy.score); 63 64 //指向结构体类型数据的指针访问的形式 65 printf("Number = %d\nName = %s\n",(*pstu).num,(*pstu).name); 66 printf("Sex = %c\nScore = %f\n\n",(*pstu).sex,(*pstu).score); 67 printf("Number = %d\nName = %s\n",pstu -> num,pstu ->name); 68 printf("Sex = %c\nScore = %f\n\n",pstu ->sex,pstu ->score); 69 #endif //指向结构体类型数据的指针 70 71 #if(0) 72 STUDENT stu1,stu2; 73 int i; 74 printf("Input a record:\n"); 75 scanf("%ld",&stu1.studentID); 76 scanf("%s",stu1.studentName); 77 scanf(" %c",&stu1.studentSex); 78 scanf("%d",&stu1.birthday.year); 79 scanf("%d",&stu1.birthday.month); 80 scanf("%d",&stu1.birthday.day); 81 for ( i = 0; i < 4; i++) 82 { 83 scanf("%d",&stu1.score[i]); 84 } 85 stu2 = stu1; 86 printf("&stu2 = %p \n",&stu2); 87 printf("%10ld%8s%3c%6d/%02d/%02d%4d%4d%4d%4d", 88 stu1.studentID,stu1.studentName,stu1.studentSex,stu1.birthday.year,stu1.birthday.month,stu1.birthday.day, 89 stu1.score[0], 90 stu1.score[1], 91 stu1.score[2], 92 stu1.score[3] 93 ); 94 #endif 95 96 #if(0) 97 //int a[10]={10,8,6,4,3},x,i,k=-1; 98 //printf("input inser num\n"); 99 //scanf("%d",&x); 100 //for ( i = 0; i < 5; i++) 101 //{ 102 // 103 // if(a[i]>=x&&x>=a[i+1]) 104 // { 105 // k = i;break; 106 // }else continue; 107 108 //} 109 110 //for ( i = 4; i >= k; i--) 111 //{ 112 // a[i+1] = a[i]; 113 //} 114 //a[k] = x; 115 // 116 //for ( i = 0; i < 6; i++) 117 //{ 118 // printf("%3d",a[i]); 119 //} 120 121 int a[10]={1,2,3,4,5,7,8,9,10,11}; 122 int b[12],i,j=0,n; 123 for(i=0;i<10;i++) 124 printf("%d ",a[i]); 125 scanf("%d",&n); 126 127 for(i=0;i<10;i++) 128 { 129 if(a[i]<n) 130 { 131 b[i]=a[i]; 132 j++; 133 continue;} 134 else if(a[i]>=n&&n>a[i-1]) 135 b[i]=n; 136 while(i<=10){ 137 b[i+1]=a[i++]; 138 } 139 } 140 /*if(a[9]<n)b[10]=n;*/ 141 if(j>=10) b[10] = n; 142 for(i=0;i<11;i++) 143 printf("%d ",b[i]); 144 //int a[11] , i , j , x , temp; 145 //printf("请输入10个数\n"); 146 //for ( i = 0; i < 10; i++) 147 // scanf("%d",&a[i]); 148 //for ( j = 0; j < 9; j++) 149 //{ 150 // for ( i = 0; i < 9-j; i++) 151 // { 152 // if(a[i]<a[i+1]) //排序交换 153 // { 154 // temp = a[i+1]; 155 // a[i+1] = a[i]; 156 // a[i] = temp; 157 // } 158 // } 159 //} 160 //for ( i = 0; i < 10; i++) 161 //{ 162 // printf("%4d",a[i]); 163 //} 164 //printf("\n"); 165 //printf("请再输入一个整数:\n"); 166 //scanf("%d",&x); 167 //for ( i = 0 , j = 0; i < 10; i++) 168 //{ 169 // if(a[i] >= x && x >= a[i+1]) 170 // { 171 // j = i; break; 172 // }else 173 // { 174 // continue; 175 // } 176 //} 177 //for ( i = 0; i < j+1; i++) 178 //{ 179 // printf("%4d",a[i]); //输出插入点前的数字 180 //} 181 //temp = a[j+1]; 182 //a[j+1] = x; 183 //printf("%4d",a[j+1]);//输出插入点的数字 184 //a[j+1] = temp; 185 //for ( i = 0; i < 9-j; i++) //移位交换 186 //{ 187 // a[10-i] = a[9-i]; 188 //} 189 //for ( i = 0; i < 9-j; i++) 190 //{ 191 // printf("%4d",a[i+j+2]); //输出插入点后的数字 192 //} 193 //printf("\n"); 194 #endif //将一个数插入到一个从大到小的有序数组 195 196 197 198 #if(0) 199 int i , j , k = 5; 200 for ( i = 0; i < 5; i++) 201 { 202 //for ( j = 0; j < 4-i; j++) 203 //{ 204 // printf(" "); 205 //} 206 for ( j = 0; j < i+1; j++) 207 { 208 printf("*"); 209 } 210 printf("\n"); 211 } 212 printf("\n"); 213 for ( i = 0; i < 5; i++) 214 { 215 //for ( j = 0; j < 4-i; j++) 216 //{ 217 // printf(" "); 218 //} 219 for ( j = 4 - i; j < 5; j++) 220 { 221 printf("*"); 222 } 223 printf("\n"); 224 } 225 printf("\n"); 226 for ( i = 0; i < 5; i++) 227 { 228 //for ( j = 0; j < 4-i; j++) 229 //{ 230 // printf(" "); 231 //} 232 for ( j = i; j >= 0 ; j--) 233 { 234 printf("*"); 235 } 236 printf("\n"); 237 } 238 printf("\n"); 239 for ( i = 0; i < 5; i++) 240 { 241 //for ( j = 0; j < 4-i; j++) 242 //{ 243 // printf(" "); 244 //} 245 for ( j = 5; j >= 5 - i ; j--) 246 { 247 printf("*"); 248 } 249 printf("\n"); 250 } 251 printf("\n"); 252 253 /***********************************************************************************/ 254 for ( i = 0; i < 5; i++) 255 { 256 for ( j = 0; j < 5-i; j++) 257 { 258 printf("*"); 259 } 260 printf("\n"); 261 } 262 printf("\n"); 263 264 for ( i = 0; i < 5; i++) 265 { 266 //for ( j = 0; j <= i-1; j++) 267 //{ 268 // printf(" "); 269 //} 270 for ( j = i; j < 5; j++) 271 { 272 printf("*"); 273 } 274 printf("\n"); 275 } 276 printf("\n"); 277 278 for ( i = 0; i < 5; i++) 279 { 280 for ( j = 5; j >i; j--) 281 { 282 printf("*"); 283 } 284 printf("\n"); 285 } 286 printf("\n"); 287 288 for ( i = 0; i < 5; i++) 289 { 290 //for ( j = 0; j <= i-1; j++) 291 //{ 292 // printf(" "); 293 //} 294 for ( j = 4 - i; j >= 0; j--) 295 { 296 printf("*"); 297 } 298 printf("\n"); 299 } 300 printf("\n"); 301 /***********************************************************************************/ 302 for ( i = 0; i < k; i++) 303 { 304 for ( j = 0; j <= k - 2 - i; j++) 305 putchar(‘ ‘); 306 for ( j = 0; j <= 2*i; j++) 307 putchar(‘*‘); 308 putchar(‘\n‘); 309 } 310 #endif //打印图形 311 312 313 314 //int a[10] ,i , j , max; 315 //max = a[0]; 316 //for ( i = 0; i < 10; i++) 317 //{ 318 // scanf("%d",&a[i]); 319 // for ( j = 0; j < i ; j++) 320 // { 321 // while (a[i] == a[j]) 322 // { 323 // printf("请重新输入\n"); 324 // scanf("%d",&a[i]); 325 // } 326 // } 327 //} 328 //for ( i = 0; i < 10; i++) 329 //{ 330 // printf("%3d",a[i]); 331 //} 332 //char s[80] ,c1 , c2=‘ ‘; 333 //int i = 0 , num = 0; 334 //gets(s); 335 //while (s[i]!=‘\0‘) 336 //{ 337 // c1 = s[i]; 338 // if(i == 0) c2 =‘ ‘; 339 // else c2 = s[i-1]; 340 // if(c1 != ‘ ‘&& c2 == ‘ ‘ ) num ++; 341 // i++; 342 //} 343 //printf("There are %d words \n",num); 344 345 346 return 0; 347 }