随笔分类 -  c语言习题

摘要:1 /* 2 百文买鸡 3 公鸡5/只 母鸡3/只 小鸡3只/文 4 求百文百只里面的组合 5 */ 6 int main() 7 { 8 int cock, hen, chick; 9 for (cock = 0; cock < 100 / 5;cock++) 10 { 11 for (hen = 阅读全文
posted @ 2020-04-12 15:53 新生代农民工 阅读(126) 评论(0) 推荐(0)
摘要:/* 循环写阶乘*/ 4 5 #include<stdio.h> 6 int main() 7 { 8 int sum = 1; 9 int i; 10 for (i = 1; i < 100;i++) 11 { 12 sum *= i; 13 } 14 printf("%d", sum); 15 阅读全文
posted @ 2020-04-12 15:46 新生代农民工 阅读(131) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12 }; //设置数组 5 int i, k,max,low,row; 6 max = 0; 7 low = 0; 8 阅读全文
posted @ 2020-03-18 19:52 新生代农民工 阅读(1012) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int a[2][3] = { 1, 2, 3, 4, 5, 6 }; //定义数组 5 int b[3][2],j,k; 6 for (j = 0; j <= 1;j++) //循环交换 7 { 8 for (k = 0 阅读全文
posted @ 2020-03-18 19:39 新生代农民工 阅读(1095) 评论(0) 推荐(0)
摘要:把一串密码译成正文,密码以字符@结束,译码规则如下 ①如果是字母,则转换成下一个字母 ②如果是字母Z译成A ③无论大小写字母都译成小写字母 ④其他字符一律按原样译出 1 //第一种if写法 2 #include<stdio.h> 3 int main() 4 { 5 char ch; 6 while 阅读全文
posted @ 2020-03-17 21:22 新生代农民工 阅读(513) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 int main() 3 { 4 char ch; 5 while ((ch=getchar())!='\n') 6 { 7 if (ch>='a'&&ch<='z') 8 { 9 ch = ch - 'a' + 'A'; //只需减去字母表首字母得到多少 阅读全文
posted @ 2020-03-17 20:52 新生代农民工 阅读(754) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int x, y, a[10][10] = { 0 }; 5 for (x = 0; x < 10;x++) //把首列和对角线赋值为1,以便后面计算 6 { 7 a[x][x] = 1; 8 a[x][0] = 1; 9 阅读全文
posted @ 2020-03-16 21:41 新生代农民工 阅读(94) 评论(0) 推荐(0)
摘要:1 /* 2 这种头尾交换数值只需要循环一半 3 头尾分别交换值即可 4 */ 5 #include<stdio.h> 6 int main() 7 { 8 int a[5] = { 8, 6, 5, 4, 1 }; 9 int i,j, temp; 10 temp = 0; 11 for (i = 阅读全文
posted @ 2020-03-16 16:29 新生代农民工 阅读(173) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int a[11] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 5 int temp, c, b,temp2; 6 for (c = 0; c < 10; c++) 7 { 8 printf(" 阅读全文
posted @ 2020-03-16 15:36 新生代农民工 阅读(126) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int a, b, temp, c[10] = { 2, 5, 1, 7, 4, 8, 9, 3, 6, 0 }; 5 for (a = 0; a <= 8;a++) //从首位遍历数组最后一位数不需要遍历 6 { 7 f 阅读全文
posted @ 2020-03-16 14:35 新生代农民工 阅读(134) 评论(0) 推荐(0)
摘要:1.解释下什么是筛选法? 筛选法又称筛法,具体做法是:先把N个自然数按次序排列起来。1不是质数,也不是合数,要划去。第二个数2是质数留下来,而把2后面所有能被2整除的数都划去。2后面第一个没划去的数是3,把3留下,再把3后面所有能被3整除的数都划去。3后面第一个没划去的数是5,把5留下,再把5后面所 阅读全文
posted @ 2020-03-16 14:09 新生代农民工 阅读(1203) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int a[3][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };//随意定义数组 5 int sum1, sum2, k, j; //定义输出的变量和循环的变量 6 sum1 = 0; 7 sum2 阅读全文
posted @ 2020-03-15 19:07 新生代农民工 阅读(727) 评论(0) 推荐(0)
摘要:两个乒乓球队进行比赛,各出3人。甲队为A,B,C 3人,乙队为X,Y,Z 3人。已抽签决定比赛名单。 有人向队员打听比赛的名单,A说他不和X比,C说他不和X,Z比,请编程序找出3对赛手的名单。 1 #include<stdio.h> 2 int main() 3 { 4 char i, j, k; 阅读全文
posted @ 2020-03-15 16:47 新生代农民工 阅读(644) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int i; 5 double a, b, c, e; 6 a = 2; 7 b = 1; 8 c = 0; 9 e = 0; 10 for (i = 1; i <= 20; i++) 11 { 12 e = e + a 阅读全文
posted @ 2020-03-15 15:52 新生代农民工 阅读(181) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int i, j, k; 5 for (i = 1; i <= 4; i++) //先循环上面的4层 6 { 7 for (j = 1; j <= 4 - i; j++) //观察菱形可知每行空格比上行少一个到最后一行为0 阅读全文
posted @ 2020-03-14 22:18 新生代农民工 阅读(147) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 int main() 3 { 4 double m, x, z, y; 5 m = 100.0; 6 x = 1; 7 z = 0; 8 y = 0; 9 while (x <= 10) 10 { 11 y = m / 2; 12 z = m + y + 阅读全文
posted @ 2020-03-14 21:39 新生代农民工 阅读(112) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int day, num, n; //倒退求桃子 5 day = 9; 6 num = 1; 7 n = 0; //总共摘下的 8 while (day > 0) //吃九天即1-9 9 { 10 n = (num + 1 阅读全文
posted @ 2020-03-14 21:31 新生代农民工 阅读(110) 评论(0) 推荐(0)
摘要:1 include<stdio.h> 2 int main() 3 { 4 int a, b, d; 5 for (d = 1; d <= 1000; d++) 6 { 7 a = 0; 8 for (b = 1; b <= d / 2; b++) //对于某一整数来说,其最大因子为n/2 (若n为 阅读全文
posted @ 2020-03-14 20:25 新生代农民工 阅读(203) 评论(0) 推荐(0)
摘要:求(即求1!+2!+3!+4!+…+20!)。 阶乘求和 n!=1×2×3×...×n或者0!=1,n!=(n-1)!×n 1 #include<stdio.h> 2 int main() 3 { 4 int n, num, total; 5 total = 0; 6 for (n = 1; n < 阅读全文
posted @ 2020-03-14 17:52 新生代农民工 阅读(1095) 评论(0) 推荐(0)
摘要://题目:求Sn=a+aa+aaa+……+aa…a(n个a)之值,其中a是一个数字,n表示a的位数, //例如:2+22+222+2222+22222(此时n=5)n由键盘输入 1 #include<stdio.h> 2 int main() 3 { 4 int a, n, c, num, b; 5 阅读全文
posted @ 2020-03-14 17:13 新生代农民工 阅读(4343) 评论(0) 推荐(0)