### 打印菱形

#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>//打印菱形int main(){  int line = 0;  scanf("%d",&line);  int i = 0;  //打印上半部分  for (i = 0; i < line; i++)  {    //打印一行    int j = 0;    for (j = 0; j < line - 1-i; j++)    {      printf(" ");    }    for (j = 0; j < 2 * i + 1; j++)    {      printf("*");    }    printf("\n");  }  //打印下半部分  for (i = 0; i < line - 1; i++)  {    int j = 0;    for (j = 0; j <= i; j++)    {      printf(" ");    }    for (j = 0; j < 2 * (line-i-1)-1;j++)                           //表达式想不明白 就把情况罗列出来   用表达式来凑    {      printf("*");    }    printf("\n");  }  return 0;}

### 汽水问题

--现在有20元，每瓶汽水1元，2个空瓶可以换一瓶汽水，能喝多少瓶汽水？

#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>     //汽水问题int main(){  int money = 0;  scanf("%d",&money);  int total = money;  int empty = money;  while (empty >= 2)  {    total += empty / 2;    empty = empty / 2 + empty % 2;  }  printf("%d",total);  return 0;}

### 使数组中的整型数据奇数在前，偶数在后

#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>void move(int arr[], int sz){  int left = 0;  int right = sz - 1;  while (left < right)  {    //从前往后找偶数    while ((left<right) && arr[left] % 2 != 0)   //left <right 避免越界访问    {      left++;    }    //从后往前找奇数    while ((left <right) &&  arr[right] % 2 != 1)    {      right--;    }    if (left < right)    {      int tmp = arr[right];      arr[right] = arr[left];      arr[left] = tmp;    }    // 必须要加条件  因为2、7进去交换4和5   4.5 进去 交换5.4    /*int tmp = arr[right];    arr[right] = arr[left];    arr[left] = tmp;*/      }}  void print(int arr[], int sz){  int i = 0;  for (i = 0; i < sz; i++)  {    printf("%d",arr[i]);  }}int main(){  int arr[] = { 0,1,2,3,4,5,6,7,8,9 };  int sz = sizeof(arr) / sizeof(arr[0]);  move(arr, sz);  print(arr,sz);  return 0;}