01 2020 档案
摘要:https://pintia.cn/problem-sets/12/problems/358这个题目和十进制数转换成二进制数类似。 用一个两位数来思考递归的过程,就容易多了。 void printdigits(int n) { if (n < 10) { printf("%d\n", n); } e
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/357 这个题目对于理解递归很有帮助,递归第一个结束的程序是出口。 1 void dectobin(int n) 2 { 3 if (n <= 1) 4 { 5 printf("%d", n); 6 } 7 els
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/356 1 int f(int n) 2 { 3 int ret; 4 5 if (n == 0) 6 { 7 ret = 0; 8 } 9 else if (n == 1) 10 { 11 ret = 1; 12
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/355 1 int Ack(int m, int n) 2 { 3 int ret; 4 5 if (m == 0) 6 { 7 ret = n + 1; 8 } 9 else if (n == 0 && m >
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/353 1 double calc_pow(double x, int n) 2 { 3 double ret; 4 5 if (n == 0) 6 { 7 ret = 1; 8 } 9 else 10 { 11
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/352 1 double fact(int n) 2 { 3 double product; 4 if (n == 0) 5 { 6 product = 1; 7 } 8 else 9 { 10 product =
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/351 1 int search(int n) 2 { 3 int count = 0; 4 int num_sqrt; //平方根的整数部分 5 int single, ten, hundred; 6 for (
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/350 1 int sum(int n) 2 { 3 if (n <= 0) 4 { 5 return 0; 6 } 7 else 8 { 9 return n + sum(n - 1); 10 } 11 }
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/347 1 #include <stdio.h> 2 #include <stdlib.h> 3 struct friend 4 { 5 char name[11]; 6 int birthday; 7 char
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/349 1 int set_grade(struct student *p, int n) 2 { 3 int i, count; 4 5 count = 0; 6 for (i = 0; i < n; i++)
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/348 1 struct complex multiply(struct complex x, struct complex y) 2 { 3 struct complex ret; 4 5 ret.real =
阅读全文
摘要:1 /*修改学生成绩,结构指针作为函数参数*/ 2 #include <stdio.h> 3 struct student 4 { 5 int num; 6 char name[10]; 7 int computer, english, math; 8 double average; 9 }; 10
阅读全文
摘要:1 #include <stdio.h> 2 int main(void) 3 { 4 int a; 5 char c; 6 7 scanf("%d", &a); 8 c = getchar(); 9 putchar(c); 10 11 return 0; 12 } 输入1,然后回车 整数1读入到变
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/346 这个程序的算法不难,因为没有学透标准输入和输出,特别是gets()函数。如果不用getchar()读取多余的'\n',程序就会运行错误。 1 #include <stdio.h> 2 #include <s
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/345 解决舍入问题。 1 #include <stdio.h> 2 #include <math.h> 3 4 int main(void) 5 { 6 struct p 7 { 8 double x; 9 do
阅读全文
摘要:https://pintia.cn/problem-sets/12/problems/342 1 bool palindrome(char *s) 2 { 3 int n, i, k; 4 bool ret; 5 6 n = strlen(s); 7 i = 0; 8 k = n - 1; 9 wh
阅读全文