#include<stdio.h>
#include<string.h>
#include<assert.h>
#include<math.h>
1.//my_memmove制作
void* my_memmove(void* dest, void* src, size_t num)
{
assert(dest && src);
void* ret = dest;
if (dest < src)
{
//前->后
while (num--)
{
*(char*)dest = *(char*)src;
dest = (char*)dest + 1;
src = (char*)src + 1;
}
}
else
{
while (num--)
{
*((char*)dest + num) = *((char*)src + num);
}
}
return ret;
}
void test3()
{
int arr1[] = { 1,2,3,4,5,6,7,8,9 };
my_memmove(arr1 + 2, arr1, 20);
int i = 0;
for (i = 0; i < 10; i++)
{
printf("%d", arr1[i]);
}
}
int main()
{
test3();
return 0;
}
//2.小乐乐该数字(把奇函数改成1,偶函数改成0)
int main()
{
int input = 0;
int sum = 0;
int i = 0;
scanf("%d", &input);
while (input)
{
int bit = input % 10;
if (bit % 2 == 1)
{
bit = 1;
}
else
{
bit = 0;
}
sum += bit * pow(10, i);
i++;
}
printf("%d\n", sum);
return 0;
}
//3.带空格的直角三角形图案
int main()
{
int n = 0;
while (scanf("%d", &n) == 1)
{
int i = 0;
int j = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if (i + j < n - 1)
{
printf(" ");
}
else
{
printf("* ");
}
}
printf("\n");
}
}
return 0;
}
//4.网购
int main()
{
double price = 0.0;
int m = 0;
int d = 0;
int flag = 0;
scanf("%lf %d %d %d", & price, &m, &d, &flag);
if (m == 11 && d == 11)
{
price = price * 0.7 - flag * 50;
}
else if (m == 12 && d == 12)
{
price = price * 0.8 - flag * 50;
}
if (price < 0.0)
{
printf(".2lfd\n", 0);
}
else
printf("%.2lf\n", price);
}
5.杨辉三角
int main()
{
int arr[10][10] = { 0 };
int i = 0;
int j = 0;
for (i = 0; i<10; i++)
{
for (j = 0; j <=i; j++)
{
if (j == 0)
{
arr[i][j] = 1;
}
if (i == j)
{
arr[i][j] = 1;
}
if(i>=2 && j>=1)
{
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
}
}
}
for (i = 0; i< 10; i++)
{
for (j = 0; j <=i; j++)
{
printf("%3d", arr[i][j]);
}
printf("\n");
}
return 0;
}