#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
int Add(int x, int y)
{
int z = 0;
z = x + y;
return z;
}
int main()
{
int a = 30;
int b = 50;
int sum = Add(a , b);
printf("%d\n", sum);
return 0;
}
void Swap1(int x, int y)
{
int tmp = 0;
tmp = x;
x = y;
y = tmp;
}
void Swap2(int* pa, int* pb)
{
int tmp = 0;
tmp = *pa;
*pa = *pb;
*pb = tmp;
}
int main()
{
int a = 40;
int b = 80;
printf("a = %d b=%d\n", a, b);
Swap1(a, b);//传值调用
Swap2(&a, &b);//传址调用
printf("a = %d b=%d\n", a, b);
return 0;
}
//当实参传给形参的时候
//形参其实是实参的一份临时拷贝
//对形参的改动不会影响实参
int get_max(int x, int y)
{
if (x > y)
{
return x;
}
else
return y;
}
int main()
{
int a = 20;
int b = 10;
int max = get_max(a, b);
printf("max = %d\n", max);
return 0;
}
int is_prime(int n)
{
int j = 0;
for (j = 2; j < n; j++)
{
if (n%j == 0)
return 0;
}
return 1;
}
int main()
{
int i = 0;
for (i = 100; i <= 200; i++)
{
if (is_prime(i) == 1)
printf("%d ", i);
}
return 0;
}
int is_leap_year(int n)
{
if ((n % 4 == 0 && n % 10 != 0) || (n % 400 == 0))
return 1;
else
return 0;
}
int main()
{
int year = 0;
int a = 0;
for (year = 2000; year <= 3000; year++)
{
if (1 == is_leap_year(year))
{
printf("%d ", year);
}
}
return 0;
}
int kkkk(int arr[], int a, int se)
{
int left = 0;
int right = se - 1;
while (left <= right)
{
int mid = (left + right) / 2;
if (arr[mid] > a)
{
right = mid - 1;
}
else if (arr[mid] < a)
{
left = mid + 1;
}
else
{
return mid;
}
}
return -1;
}
int main()
{
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int a = 7;
int se = sizeof(arr) / sizeof(arr[0]);
int ret = kkkk(arr, a, se);
if (ret == -1)
{
printf("找不到\n");
}
else
printf("找到了,下标是 %d", ret);
return 0;
}
void add(int* p)
{
(*p)++;
}
int main()
{
int i = 0;
int num = 0;
while (i<=3)
{
add(&num);
printf("num = %d\n", num);
i++;
}
return 0;
}
int main()
{
printf("%d", printf("%d", printf("%d", printf("%d", printf("%d", 23)))));//链式结构
return 0;
}
标签:11,tmp,arr,main,所学,int,printf,return,分享
From: https://blog.51cto.com/u_16182079/6693366