考试错误练习

#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main(){
 int a;
 int b;
 int tmp;
 int i;
 printf("input a and b:");
 scanf("%d%d", &a, &b);
 if (a<b){
  tmp = a;
  a = b;
  b = tmp;
 }
 for (i = a; i>0; i++){
  if (i%a == 0 && i%b == 0){
   printf("%d", i);
   break;
  }
 }
 system("pause");
 return 0;}

#include<stdio.h>
#include<stdlib.h>
int cnt = 0;
       int fib(int n){
 cnt++;
 if (n == 0)
  return 1;
 else if (n == 1)
  return 2;
 else
  return fib(n - 1) + fib(n - 2);

    int main(){
 fib(8);
 printf("%d\n", fib(8));
 system("pause");
 return 0;
}
#include<stdio.h>
#include<stdlib.h>
    int a = 1;
void test(){
 int a = 2;
 a += 1;
}
int main(){
 test();
 printf("%d\n", a);
 system("pause");
 return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main(){//陷入死循环
 int x = 1;
 do{
  printf("%2d\n", x++);
 } while (x--);
 system("pause");
 return 0;
}
#define  _CRT_SECURE_NO_WARNINGS
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include<stdlib.h>
void ReserveStr(char *arr, int start, int end)
{
 char ch;
 if (arr == NULL)
  return;
 while (start<end)
 {
  ch = arr[start];
  arr[start] = arr[end];
  arr[end] = ch;
  start++;
  end--;
 }
}
void ReserveWord(char *arr)
{
 int start = 0;
 int end = 0;
 int len = strlen(arr);
 if (arr == NULL)
  return;
 ReserveStr(arr, 0, len - 1);
 while (start<len)
 {
  end = start;
  if (arr[start] != ' ')
  {
   while (arr[end] != ' '&&arr[end] != '\0')
   {
    end++;
   }
   ReserveStr(arr, start, end - 1);
   start = end;
  }
  else
  {
   start++;
  }
 }
}
int main()
{
 char str[100];
 gets(str);
 ReserveWord(str);
 printf("%s", str);
 system("pause");
 return 0;
}

猜你喜欢

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