- 博客(17)
- 收藏
- 关注
原创 汉诺塔
Problem Description 汉诺塔(又称河内塔)问题是印度的一个古老的传说。 开天辟地的神勃拉玛在一个庙里留下了三根金刚石的棒A、B和C,A上面套着n个圆的金片,最大的一个在底下,其余一个比一个小,依次叠上去,庙里的众僧不倦地把它们一个个地从A棒搬到C棒上,规定可利用中间的一根B棒作为帮助,但每次只能搬一个,而且大的不能放在小的上面。 僧侣们搬得汗流满面,可惜当n很大时这辈子恐怕就很搬...
2018-11-11 19:46:34
202
原创 完美的素数
Problem Description 素数又称质数。指一个大于1的自然数,除了1和此整数自身外,不能被其他自然数整除的数。我们定义:如果一个素数是完美的素数,当且仅当它的每一位数字之和也是一个素数。现在给你一个正整数,你需要写个程序判断一下这个数按照上面的定义是不是一个完美的素数。 Input 输入包含多组测试数据。 每组测试数据只包含一个正整数 n (1 < n <= 10^6)。...
2018-11-11 15:33:53
373
原创 C语言实验——打印金字塔
输入n值,打印下列形状的金字塔,其中n代表金字塔的层数。 Input 输入只有一个正整数n。 Output 打印金字塔图形,其中每个数字之间有一个空格。 Sample Input 3 Sample Output 1 1 2 1 1 2 3 2 1 #include<stdio.h> int main() { int i,j,m,p,q; scanf("%d",&m); for...
2018-11-11 11:07:07
590
原创 C语言实验——余弦
Problem Description 输入n的值,计算cos(x)。 Input 输入数据有多行,每行两个数,包括x和n。第一数据为x,第二个数据为n。 Output 输出cos(x)的值,保留4位小数。 Sample Input 0.0 100 1.5 50 Sample Output 1.0000 0.0707 #include<stdio.h> #include<math...
2018-11-10 13:45:04
559
原创 图形打印问题
Problem Description 图形的规则如下 ,要求输入n的值,按照图形的打印规则打印出相关的图形: Input 输入整数n。 Output 按图形的规律打印出相关的图形。 Sample Input 4 Sample Output + ++ ++ ++ ++ +*+ + #include <stdio.h> #include <stdlib.h> int main...
2018-11-10 11:58:10
458
原创 C语言实验——for循环打印图形(循环结构)
题目描述 通过使用双重for循环语句,打印下列图形: #include<stdio.h> int main() { int n,i,t; for(i=1;i<=4;i++) { for(t=1;t<=4-i;t++) printf(" “); for(t=1;t<=2i-1;t++) printf("”); printf("\n"); } for(i=3;i>...
2018-11-08 23:45:33
3409
原创 斐波那契数列
编写计算斐波那契(Fibonacci)数列的第n项函数fib(n)(n<40)。 数列: f1=f2==1; fn=fn-1+fn-2(n>=3)。 #include <stdio.h> int main() { int f1,f2,f; int n,i; scanf("%d",&n); f1=1; f2=1; for(i=3;i<=n;i++) { f=f2...
2018-11-07 16:41:42
318
原创 C语言实验——判断素数(循环结构)
Problem Description 从键盘上输入任意一个正整数,然后判断该数是否为素数。 如果是素数则输出"This is a prime." 否则输出“This is not a prime.” Input 输入任意一个正整数n(1 <= n <= 1000000)。 Output 判断n是否为素数,并输出判断结果: 如果n是素数则输出"This is a prime." 否则输...
2018-11-07 12:17:16
631
原创 最大公约数和最小公因数
Problem Description 输入两个正整数,求它们的最大公约数与最小公倍数。 Input 输入两个正整数,两个整数之间用空格分开。 数据保证在 int 范围内。 Output 第一行输出最大公约数; 第二行输出最小公倍数。 答案保证在 int 范围内。 #include<stdio.h> int main() { int a,b,t,i,bei; scanf("%d %d"...
2018-11-07 12:00:08
552
原创 while语句 while(----!=EOF)的意思
#include<stdio.h> int main() //把main函数定义成int类型 { int a,b; while(scanf("%d %d",&a, &b) != EOF) // 输入结束时,scanf函数返回值为EOF,即没有数据输入时则退出while循环 printf("%d\n",a+b); return 0; //返回值为0 } ...
2018-11-06 10:01:32
3335
原创 C语言实验——时间间隔
从键盘输入两个时间点(24小时制),输出两个时间点之间的时间间隔,时间间隔用“小时:分钟:秒”表示。 如:3点5分25秒应表示为–03:05:25.假设两个时间在同一天内,时间先后顺序与输入无关。 提示:本题非常重要的一点是将时间全部转换成相同单位进行计算,得出结果再转换为时分秒的形式 include<stdio.h> int main() { int h1, h2, m1, m2, ...
2018-11-05 21:38:06
1479
原创 C语言实验——输入数字星期,输出英文(switch语句)
#include<stdio.h> int main() { int n; scanf("%d",&n); switch(n) { case 1: printf(“Monday”); break; case 2: printf(“Tuesday”); break; case 3: printf(“Wednesday”); break; case 4: printf(“Thurs...
2018-11-05 17:54:01
1626
原创 某年某月的天数
问题描述 输入年和月,判断该月有几天? 输入 输入年和月,格式为年\月. 输出量 输出该月的天数. 样本输入 2009\1 样本输出 31 注意char c。有一个\要输入 #include <stdio.h> int main() { int year,month; int isLeap=0; int days; char c; scanf("%d",&year); scan...
2018-11-05 16:38:51
779
原创 从键盘输入一个大写字母,转换成小写字母
#include <stdio.h> int main() { char n; printf(“请输入一个大写字母:”); scanf("%c",&n); n=n+32; putchar(n); putchar(’\n’); return 0; }
2018-11-05 16:01:04
16073
原创 闰年 时间过得真快啊,又要过年了,同时,我们的人生也增长了一年的阅历,又成熟了一些.可是,你注意过今年是不是闰年呢,明年呢?
#include<stdio.h> int main() { int a; scanf ("%d",&a); if((a%40&&a%100)||(a%4000)) printf(“Yes”); else printf(“No”); return 0; }
2018-11-05 15:46:58
2058
原创 从键盘输入三个整数a、b、c,要求将输出的数据按从大到小排序后输出。
#include&lt;stdio.h&gt; int main() { int a,b,c,t; scanf("%d%d%d",&amp;a,&amp;b,&amp;c); if(a&gt;b) { t=a; a=b; b=t; } if(a&gt;c) { t=a; a=c; c=t; } if(b&gt;c)
2018-11-05 15:36:28
33272
1
原创 从键盘上输入任意一个整数,然后输出它的绝对值!
#include&lt;stdio.h&gt; int main() { int x; scanf("%d",&amp;x); if(x&lt;0) x=-x; printf("%d",x); return 0; }
2018-11-05 13:06:17
22579
1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅