DAY 7 选择排序 二维数组 字符型数组

选择排序

  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <time.h>
  4 
  5 int main(void)
  6 {
  7     int a[6] = {0};
  8     int i = 0;
  9     int j = 0;
 10     int min = 0;
 11     int temp = 0;
 12     int len = sizeof(a) / sizeof(a[0]);
 13 
 14     srand(time(NULL));
 15     printf("Before : ");
 16     for (i = 0; i < len; i++)
 17     {
 18         a[i] = rand() % 100;
 19         printf("%d ", a[i]);
 20     }
 21     printf("\n");
 22 
 23     for (j = 0; j < len - 1; j++)
 24     {
 25         min = j;
 26         for (i = j + 1; i < len; i++)                                                                                                                                                                                                                             
 27         {
 28             if (a[i] < a[min])
 29             {
 30                 min = i;
 31             }
 32         }
 33 
 34         if (min != j)
 35         {
 36             temp = a[min];
 37             a[min] = a[j];
 38             a[j] = temp;
 39         }
 40     }
 41 
 42     printf("After : ");
 43     for (i = 0; i < len; i++)
 44     {
 45         printf("%d ", a[i]);
 46     }
 47     printf("\n");
 48 
 49     return 0;
 50 }

计算输入字符串中大写字母,小写字母,空格,数字的个数

  1 #include <stdio.h>
  2 
  3 int main(void)
  4 {
  5     char str[64] = {0};
  6     int i = 0;
  7     int j = 0;
  8     int n = 0;
  9     int m = 0;
 10     int k = 0;
 11 
 12     gets(str);
 13 
 14     while (str[i] != '\0')
 15     {
 16 
 17         if ('A' <= str[i] && 'Z' >= str[i])
 18         {
 19             k++;
 20         }
 21         else if ('a' <= str[i] && 'z' >= str[i])
 22         {
 23             j++;
 24         }
 25         else if (str[i] == ' ')
 26         {
 27             n++;
 28         }
 29         else if ('0' <= str[i] && '9' >= str[i])
 30         {
 31             m++;
 32         }
 33         i++;                                                                                                                                                                                                                                                      
 34     }
 35 
 36     printf("k = %d\nj = %d\nn = %d\nm = %d\n", k, j, n, m);
 37 
 38     return 0;
 39 }

strlen,strcpy,strcmp,strcat练习

  1 #include <stdio.h>
  2 #include <string.h>
  3 
  4 int main(void)
  5 {
  6     char str[64] = {0};
  7     char dst[64] = {0};
  8     int ret = 0;
  9     int len = 0;
 10 
 11     gets(str);
 12     gets(dst);
 13     //strcpy(str, "Thank");
 14     //strcpy(dst, "you");
 15     //strcat(str, dst);
 16 
 17     len = strlen(str);
 18 
 19     ret = strcmp(str, dst);
 20 
 21     printf("len = %d\n", len);                                                                                                                                                                                                                                    
 22     printf("ret = %d\n", ret);
 23 
 24     if (!strcmp(str, dst))
 25     {
 26         printf("Character sting is same\n");
 27     }
 28     if (0 < ret)
 29     {
 30         printf("str > dst\n");
 31     }
 32     if (0 > ret)
 33     {
 34         printf("str < dst\n");
 35     }
 36     //puts(str);
 37 
 38     return 0;
 39 }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值