3.17 3.18study

时间:2022-08-27 01:01:41
#include <stdio.h>
#include <string.h>

/*
void print(int a)
{
int i = 0;
printf("奇数位: \n");
for (i = 30; i >= 0; i -= 2)
{
printf("%d ",(a>>i)&1);
}
printf("\n");
printf("偶数位: \n");
for (i = 31; i >= 0; i -= 2)
{
printf("%d ",(a>>i)&1);
}
printf("\n");
}

int main()
{
int m = 0;
scanf("%d",&m);
print(m);
return 0;
}
*/

/*
void print(int* p, int sz)
{
int i = 0;
for (i = 0; i < sz; i++)
{
printf("%d ", *(p + i));
}
}

int main()
{
int arr[] = { 1,2,3,4,5,6,7,8,9 };
int sz = sizeof(arr) / sizeof(arr[0]);
print(arr,sz);

return 0;
}
*/

/*
void print_table(int n)
{
int i = 0;
for (i = 1; i <= n; i++)
{
int j = 0;
for (j = 1; j <= i; j++)
{
printf("%d*%d=%-2d ",i,j,i*j);
}
printf("\n");
}
}

int main()
{//打印乘法口诀表
int n = 0;
scanf("%d",&n);
print_table(n);


return 0;
}
*/

/*
int my_strlen(char* str)
{
int count = 0;
while (*str != '\0')
{
count++;
str++;
}
return count;
}

void reverse_string(char arr[])
{
int left = 0;
int right = my_strlen(arr) - 1;
while (left < right)
{
int tmp = arr[left];
arr[left] = arr[right];
arr[right] = tmp;
left++;
right--;
}
}
int main()
{//逆序字符串
char arr[] = "abcdef";//fedcba
reverse_string(arr);
printf("%s\n",arr);
return 0;
}
*/

/*
int my_strlen(char* str)
{
int count = 0;
while (*str != '\0')
{
count++;
str++;
}
return count;
}

void reverse_string(char* arr)
{
char tmp = arr[0];
int len = my_strlen(arr);
arr[0] = arr[len - 1];
arr[len - 1] = '\0';
if(my_strlen(arr+1)>=2)
{
reverse_string(arr + 1);
}
arr[len - 1] = tmp;

}
int main()
{//逆序字符串
char arr[] = "abcdefg";//fedcba
reverse_string(arr);
printf("%s\n", arr);
return 0;
}
*/

/*
int DigitSum(unsigned int num)
{
if (num > 9)
{
return DigitSum(num / 10) + num % 10;
}
else
{
return num;
}
}

int main()
{//运用递归,输入非负整数,返回组成它的数字之和
unsigned int num = 0;
scanf("%d",&num);
int ret = DigitSum(num);
printf("ret= %d\n",ret);

return 0;
}
*/

/*
double Pow(int n,int k)
{
//n^k=n*n^(k-1)
if (k < 0)
{
return (1.0 / (Pow(n, -k)));
}
else if (k == 0)
{
return 1;
}
else
{
return n * Pow(n, k - 1);
}
}

int main()
{//实现n的k次方,递归方法
int n = 0;
int k = 0;
scanf("%d%d",&n,&k);

double ret = Pow(n,k);
printf("ret= %lf\n",ret);

return 0;
}
*/


/*
//struct 结构体关键字 Stu-结构体标签 struct Stu-结构体类型
//struct Stu
//{//描述一个学生--名字、年龄、电话、性别
// //定义结构体类型
// char name[20];
// short age;
// char tele[12];
// char sex[5];
//}s1,s2,s3;//s1,s2,s3是三个全局的结构体变量

typedef struct Stu
{
char name[20];
short age;
char tele[12];
char sex[5];
}Stu;

int main()
{
struct Stu s1 = {"张三",20,"15249287076","男"};//创建结构体变量,s为局部的结构体变量
struct Stu s2 = {"旺财",30,"15599999999","保密"};


return 0;
}
*/

/*
struct S
{
int a;
char c;
char arr[20];
double d;
};

struct T
{
char ch[10];
struct S s;
char *pc;
};

int main()
{
char arr[] = "hello bit\n";
struct T t = { "hehe",{100,'w',"hello world",3.14},arr};
printf("%s\n",t.ch);//hehe
printf("%s\n",t.s.arr);//hello world
printf("%lf\n",t.s.d);
printf("%s\n",t.pc);
return 0;
}
*/

/*
typedef struct Stu
{
char name[20];
short age;
char tele[12];
char sex[5];
}Stu;

void Print1(Stu tmp)
{
printf("name:%s\n",tmp.name);
printf("age:%d\n",tmp.age);
printf("tele:%s\n",tmp.tele);
printf("sex:%s\n",tmp.sex);
}

void Print2(Stu* ps)
{
printf("name:%s\n",ps->name);
printf("age:%d\n", ps->age);
printf("tele:%s\n", ps->tele);
printf("sex:%s\n", ps->sex);

}
int main()
{
Stu s = { "李四",40,"15599999999","男" };
//打印结构体数据
//Print1与Print2相比,Print2更好
Print1(s);//s为实参,tmp为形参,实参传递给形参时需要开辟空间,消耗空间和时间
Print2(&s);//
//结构体传参的时候要传结构体的地址
return 0;
}
*/