练习24

//定义一个标识符位max的函数
#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int MAX(int a, int b){
 if (a > b){
  return a;
 }
 else
  return b;
}
int main(){
 int a,b;
 printf("请输入两个数比较");
 scanf("%d%d", &a,&b);
 int max = MAX(a, b);
 printf("%d\n", max);
 system("pause");
 return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main(){
 int num;
 int score[10] = { 98, 45, 65, 76, 78, 96, 93, 81, 94, 92 };
 num=Averaging(score);
 printf("%d\n", num);
 system("pause");
 return 0;
}
int Averaging(int score[10]){
 int num=0;
 for (int i = 0; i < 10; i++){
  num =  num+score[i];
 }

/*#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
//输出系统日期和时间
int main(){
 int command[4] = { 0, 1, 2, 3 };
 int num;
 struct tm *systime;
 printf("需要帮助请输入0\n");
 printf("请输入你的指令\n");
 while (1){
  scanf("%d", &num);
  if (command[0] == num){
   printf("输入数字1显示系统日期,输入数字2显示系统时间,输入数字3退出系统\n");
  }
  else if (command[1] == num){
   time_t nowtime;
   time(&nowtime);
   systime = localtime(&nowtime);
   printf("系统日期:%d-%d-%d\n", 1900 + systime->tm_year, systime->tm_mon, systime->tm_mday);
  }
  else if (command[2] = num){
   time_t nowtime;
   time(&nowtime);
   systime = localtime(&nowtime);
   printf("%d:%d:%d\n", systime->tm_hour, systime->tm_min, systime->tm_sec);
  }
  else if (command[3] == num){
   return 0;
  }
  printf("请输入命令符:\n");
 }
 system("pause");
 return 0;
}*/
 
#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main(){//输出成绩按大小排列
 int arr[12];
 int i,j;
 int tmp;
 printf("请输入成绩\n");
 for (i = 0; i < 12; i++){
  printf("arr[%d]=",i);
  scanf("%d", &arr[i]);
 }
 for (i = 0; i < 11; i++){
  for (j = i + 1; j < 12; j++){
   if (arr[i] < arr[j]){
    tmp = arr[i];
    arr[i] = arr[j];
    arr[j] = tmp;
   }
  }
 }
 for (i = 0; i < 12; i++){
  printf("%d\t", arr[i]);
  if (i == 3 || i == 7){
   printf("\n");
  }
 }
 system("pause");
 return 0;
}
#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main(){
 char a[10];
 char b[10];
 int i=0;
 printf("请输入字符串a:\n");
 gets(a);
 while (a[i] != '\0'){
   b[i] = a[i];
  i++;
 }
 b[i] = '\0';
 printf("打印字符串b\n");
 puts(b);
 system("pause");
 
}
#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
main()
{
 char s1[30], s2[30];
 int i = 0;
 printf("请输入字符串1:\n");
 gets(s1);
 while (s1[i] != '\0')
 {
  s2[i] = s1[i];
  i++;
 }
 s2[i] = '\0';
 printf("字符串2:\n");
 puts(s2);
 system("pause");
}

猜你喜欢

转载自www.cnblogs.com/yuzhenghan/p/12025382.html
今日推荐