From cd6b19e43c437db94ef76c7d16a699cc2a0a322a Mon Sep 17 00:00:00 2001 From: smallkun Date: Thu, 13 Mar 2025 16:46:35 +0800 Subject: [PATCH] Auto commit --- 2207/天天乐学答案/合卷-1.md | 78 ++--- 2207/天天乐学答案/合卷-2.md | 132 +++---- 2208/天天乐学答案/C语言-1.md | 588 +++++++++++++++++++++++++++++++ 2208/天天乐学答案/C语言-2.md | 549 +++++++++++++++++++++++++++++ 2208/天天乐学答案/C语言-3.md | 657 +++++++++++++++++++++++++++++++++++ 2208/天天乐学答案/C语言-4.md | 579 ++++++++++++++++++++++++++++++ 6 files changed, 2478 insertions(+), 105 deletions(-) create mode 100644 2208/天天乐学答案/C语言-1.md create mode 100644 2208/天天乐学答案/C语言-2.md create mode 100644 2208/天天乐学答案/C语言-3.md create mode 100644 2208/天天乐学答案/C语言-4.md diff --git a/2207/天天乐学答案/合卷-1.md b/2207/天天乐学答案/合卷-1.md index 9310451..bbdd1ee 100644 --- a/2207/天天乐学答案/合卷-1.md +++ b/2207/天天乐学答案/合卷-1.md @@ -1,9 +1,9 @@ -### C语言-1 +### C-1 ```c /*------------------------------------------------------------------------------ -(1)【程序设计】下列给定程序中,fun函数的功能是:分别统计字符串中大写字母和小写字母的个数。 -例如,给字符串s输入:AAaaBBbb123CCcccd,则应输出:upper=6,lower=8。 +1ơиУfunĹǣֱͳַддĸСдĸĸ +磬ַs룺AAaaBBbb123CCcccdӦupper6lower8 ------------------------------------------------------------------------------*/ #include void fun ( char *s, int *a, int *b) @@ -36,15 +36,15 @@ main( ) -### C语言-2 +### C-2 ```c /*------------------------------------------------------------------------ -题目:函数fun的功能:将字符串str中第k个字符开始的n个字符逆序重排, -例如:输入1,5 输出54321abcde - 输入3,6 输出12cba543de -注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,仅在 - Program-End之间填入若干语句。不要删除标志否则不得分。 +ĿfunĹܣַstrеkַʼnַţ +磺1,5 54321abcde + 3,6 12cba543de +ע⣺Դ¡Ķmainиݣ + Program-End֮䡣Ҫɾ־򲻵÷֡ ----------------------------------------------------------------------*/ #include #include @@ -70,7 +70,7 @@ int main( ) { fun(str,k,n); puts(str); } else - printf("所输入的k,n值不合适!\n"); + printf("k,nֵʣ\n"); return 0; } @@ -80,11 +80,11 @@ int main( ) -### C语言-3 +### C-3 ```c /*------------------------------------------------------------------ -功能:编程统计一个字符串中的字母、数字、空格和其它字符的个数。 +ܣͳһַеĸ֡ոַĸ ---------------------------------------------------------------------*/ #include void fun(char s[],int b[]) @@ -126,18 +126,18 @@ main () -### C语言-4 +### C-4 ```c /*------------------------------------------------------------------------ -程序功能:从键盘输入三个整数,比较三个数并显示相应信息,具体如下: -(1)如果三个数都相等,显示"***"; -(2)如果三个数中只有某两个数相等,显示"@@"; -(3)如果三个数互不相等,则显示"&"。 -(输出要换行) +ܣӼȽʾӦϢ£ +1ȣʾ"***" +2ֻijȣʾ"@@" +3ȣʾ"&" +ҪУ ------------------------------------------------------------------------ -注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,仅在 - Program-End之间删除【?】填入若干语句。不要删除标志否则不得分。 +ע⣺Դ¡Ķmainиݣ + Program-End֮ɾ?䡣Ҫɾ־򲻵÷֡ ----------------------------------------------------------------------*/ #include int main() @@ -174,17 +174,17 @@ CREATE TABLE t_hotel_manager( hid INT NOT NULL, mname VARCHAR(10) NOT NULL, mage INT NOT NULL, - mgender ENUM('男', '女', '未知'), + mgender ENUM('', 'Ů', 'δ֪'), telephone VARCHAR(11) ); #2 -#使用MODIFY添加主键字段为自动增长 +#ʹMODIFYֶΪԶ ALTER TABLE t_hotel_manager MODIFY mid INT AUTO_INCREMENT; -#设置自增起始值 +#ʼֵ ALTER TABLE t_hotel_manager AUTO_INCREMENT = 1000; #3 INSERT INTO t_hotel_manager() -VALUES(DEFAULT, 10001, '王璐', 32, '女', NULL); +VALUES(DEFAULT, 10001, '', 32, 'Ů', NULL); #4 CREATE TABLE t_hotel_bak AS SELECT * @@ -192,7 +192,7 @@ FROM t_hotel; #5 UPDATE t_client c SET c.integral = c.integral + 100 -WHERE c.cname LIKE '姚%'; +WHERE c.cname LIKE 'Ҧ%'; #6 tj11 SELECT c.cname, SUM(r.price) FROM t_booking b, t_client c, t_room r @@ -204,10 +204,10 @@ LIMIT 9, 1; #7 tj12 SELECT h.hname, r.price FROM t_hotel h, t_room r -WHERE h.hid = r.hid AND r.rname = '大床房' AND r.price = ( +WHERE h.hid = r.hid AND r.rname = '󴲷' AND r.price = ( SELECT MAX(price) FROM t_room - WHERE rname = '大床房' + WHERE rname = '󴲷' ); #8 tj13 @@ -217,7 +217,7 @@ LEFT JOIN t_booking b ON r.rid = b.rid INNER JOIN t_hotel h ON r.hid = h.hid WHERE b.bid IS NULL; -#9 视图 +#9 ͼ CREATE VIEW v_tongji AS SELECT h.hname, SUM(r.price) FROM t_hotel h, t_booking b, t_room r @@ -230,20 +230,20 @@ GROUP BY h.hid; ### MySQL-2 ```sql -#1添加主键 +#1 ALTER TABLE tb_student ADD PRIMARY KEY(student_id); -#2设置默认值 -ALTER TABLE tb_student ALTER gender SET DEFAULT '男'; +#2Ĭֵ +ALTER TABLE tb_student ALTER gender SET DEFAULT ''; -#3 插入记录 +#3 ¼ INSERT INTO tb_student() -VALUES(10025, '张三', DEFAULT, '2012-10-01', 1001); +VALUES(10025, '', DEFAULT, '2012-10-01', 1001); -#4 更新记录 +#4 ¼¼ UPDATE tb_teacher t SET t.teacher_age = 36 -WHERE t.teacher_name = '王老师'; +WHERE t.teacher_name = 'ʦ'; #5 tj11 SELECT MAX(t.teacher_age) @@ -254,7 +254,7 @@ SELECT c.class_name, s.student_name, s.gender FROM tb_teacher t, tb_student s, tb_class C where s.class_id = c.class_id AND c.teacher_id = t.teacher_id; -#7 视图 +#7 ͼ CREATE VIEW v_teacher AS SELECT c.class_name, t.teacher_name, COUNT(*) FROM tb_teacher t, tb_student s, tb_class C @@ -269,11 +269,11 @@ BEFORE UPDATE ON tb_teacher FOR EACH ROW BEGIN IF NEW.teacher_age < 30 THEN - SET NEW.age = '青年'; + SET NEW.age = ''; ELSEIF NEW.teacher_age < 50 THEN - SET NEW.age = '中年'; + SET NEW.age = ''; ELSE - SET NEW.age = '老年'; + SET NEW.age = ''; END IF; END $$ DELIMITER ; diff --git a/2207/天天乐学答案/合卷-2.md b/2207/天天乐学答案/合卷-2.md index 7788050..985cc29 100644 --- a/2207/天天乐学答案/合卷-2.md +++ b/2207/天天乐学答案/合卷-2.md @@ -1,17 +1,17 @@ -### C语言-1 +### C-1 ```c /*--------------------------------------------------------- -【程序设计】程序将由数字字符组成的字符串转换为10进制实数, - 例如将"123.4567"转换为123.45670。 +ơַɵַתΪ10ʵ + 罫"123.4567"תΪ123.45670 - 输出如下: + £ 123.45670 0.12345 4567.00000 ------------------------------------------------------------------------ -注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,仅在 - Program-End之间填入若干语句。不要删除标志否则不得分。 +ע⣺Դ¡Ķmainиݣ + Program-End֮䡣Ҫɾ־򲻵÷֡ ---------------------------------------------------------*/ #include #include @@ -49,14 +49,14 @@ int main() ``` -### C语言-2 +### C-2 ```c /* ------------------------------------------------------- -【程序填空】 +ա --------------------------------------------------------- -打印以下图案: +ӡͼ ***** ***** ***** @@ -90,13 +90,13 @@ void main() ``` -### C语言-3 +### C-3 ```c /*------------------------------------------------------- -功能:功能:输入三角形的三边长,判断能否构成三角形,若能,利用海伦公式计 - 算该三角形的面积,计算结果保留3位小数。 - l=(a+b+c)/2,s=sqrt(l*(l-a)*(l-b)*(l-c)) +ܣܣε߳жܷ񹹳Σܣú׹ʽ + ε3λС + l=(a+b+c)/2s=sqrt(l*(l-a)*(l-b)*(l-c)) --------------------------------------------------------*/ #include #include @@ -105,7 +105,7 @@ main() float a,b,c,s,l; scanf("%f,%f,%f",&a , &b , &c); if(a+b #include @@ -195,18 +195,18 @@ main() ``` -### C语言-6 +### C-6 ```c /*------------------------------------------------------------------------------ -【程序设计】编写函数rtrim,用来删除字符串尾部的空格,首部和中间的空格不删除。例如:字符串为:" A BC DEF ", -删除后的结果是" A BC DEF"。要求函数形参采用指针变量。 -测试输入: A BC DEF -测试输出: A BC DEF -说明:测试输入中,A前有4个空格,F后有5个空格 +ơдrtrimɾַβĿոײмĿոɾ磺ַΪ" A BC DEF " +ɾĽ" A BC DEF"Ҫββָ +룺 A BC DEF + A BC DEF +˵УAǰ4ոF5ո ------------------------------------------------------------------------ -注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,否则不得分。 -仅在Program-End之间填入若干语句。不要删除标志否则不得分。 +ע⣺Դ¡Ķmainиݣ򲻵÷֡ +Program-End֮䡣Ҫɾ־򲻵÷֡ ------------------------------------------------------------------------------*/ #include #include @@ -225,11 +225,11 @@ void rtrim(char *p) while(*p != '\0'){ p++; } - p--;//定位到结束符前的位置 - while(*p==' '){//如果当前指针位置是空格则指针向前移 + p--;//λǰλ + while(*p==' '){//ǰָλǿոָǰ p--; } - p++;//移动当前位置后一个空格位 + p++;//ƶǰλúһոλ *p='\0'; @@ -238,17 +238,17 @@ void rtrim(char *p) ``` -### C语言-7 +### C-7 ```c /*------------------------------------------------------------------------------ -【程序设计】输入字符串(不包含空格),将字符串按字符从小到大排序,然后输出字符串中除去ASCII码值能被3整除的字符。 -输入输出如下: +ơַո񣩣ַַСȻַгȥASCIIֵܱ3ַ +£ hello world -处理后的字符串为: dehw +ַΪ dehw ------------------------------------------------------------------------ -注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,否则不得分。 -仅在Program-End之间填入若干语句。不要删除标志否则不得分。 +ע⣺Դ¡Ķmainиݣ򲻵÷֡ +Program-End֮䡣Ҫɾ־򲻵÷֡ ------------------------------------------------------------------------------*/ #include #include @@ -267,7 +267,7 @@ void main() t=str[j];str[j]=str[j+1];str[j+1]=t; } } - printf("处理后的字符串为:"); + printf("ַΪ"); /**********Program**********/ j=0; for(i=0;i @@ -314,27 +314,27 @@ int main() int n,sum; scanf("%d",&n); sum=getsum(n); - printf("结果是%d\n",sum); + printf("%d\n",sum); } ``` -### C语言-9 +### C-9 ```c /*------------------------------------------------------------------------------ -【程序设计】有两个降序排列的集合A和B,A中无重复元素,B中也无重复元素, -求集合B-A的差集(即:这些元素属于集合B但不属于集合A),存放于数组c中,并输出。 -输入输出如下: -请输入3个整数: +ơеļABAظԪأBҲظԪأ +󼯺B-AIJЩԪڼBڼAcУ +£ +3 3 2 1 -请输入5个整数: +5 9 6 5 3 2 -结果为: +Ϊ 9 6 5 ------------------------------------------------------------------------ -注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,否则不得分。 -仅在Program-End之间填入若干语句。不要删除标志否则不得分。 +ע⣺Դ¡Ķmainиݣ򲻵÷֡ +Program-End֮䡣Ҫɾ־򲻵÷֡ ------------------------------------------------------------------------------*/ #include @@ -342,11 +342,11 @@ void main() { int a[3],b[5],c[5]; int t=0,i,j=0; - printf("请输入3个整数:\n"); + printf("3\n"); for(i=0;i<3;i++){ scanf("%d",&a[i]); } - printf("请输入5个整数:\n"); + printf("5\n"); for(i=0;i<5;i++){ scanf("%d",&b[i]); } @@ -366,28 +366,28 @@ void main() while(j<5){ c[t++]=b[j++]; } - printf("结果为:\n"); + printf("Ϊ\n"); for(i=0;i #include @@ -406,7 +406,7 @@ void main() } /********** End **********/ b[j]='\0'; - printf("去掉数字后的字符串为:"); + printf("ȥַֺΪ"); puts(b); } ``` diff --git a/2208/天天乐学答案/C语言-1.md b/2208/天天乐学答案/C语言-1.md new file mode 100644 index 0000000..05e2f97 --- /dev/null +++ b/2208/天天乐学答案/C语言-1.md @@ -0,0 +1,588 @@ +### C-1 +```c +/* +------------------------------------------------------- +ա +--------------------------------------------------------- +ӡͼ +***** + ***** + ***** + ***** + ***** +*/ +#include +void main() +{ + int i =0 , j =0 , k=0; + + /**********Program**********/ + for(i=0;i<5;i++){ + for(j=0;j +main() +{ + int i,j,k; +/**********Program**********/ + for(i=-3;i<=3;i++){ + for(j=0;j<(i<0?-i:i);j++){ + printf(" "); + } + for(k=0;k<7-j*2;k++){ + printf("*"); + } + printf("\n"); + } + + + + +/********** End **********/ +} +``` + +### C-5 +```c +/*------------------------------------------------------ +ĿӼһn,2 n-1ܱn +磺10 2 5 + 99 3 9 11 33 +--------------------------------------------------------*/ +#include "stdio.h" + int main ( ) +{ +int n,i; +printf("input a number:"); +scanf ("%d", &n); +/**********Program**********/ + for(i=2;i + main () + { + int i; + for(i=100;i<200;i++) +/**********Program**********/ + if(i%4==2 && i%7==3 && i%9==5) + + + + +/********** End **********/ + printf ("%d",i); + } + +``` + +### C-7 +```c +/*------------------------------------------------------- +ա--------------------------------------------------------- +ܣ人⳵շѵij򣬵3ں3ʱշ12Ԫ301֮1IJÿշ2Ԫ +עʹswitchʵ +--------------------------------------------------------*/ +#include +main(){ + int m,n; + scanf("%d",&m); + + /**********Program**********/ + n=0; + switch(m){ + default: n+=(m-3)*2; + case 1: + case 2: + case 3:n+=12; + } + + /********** End **********/ + + printf("շΪ%d",n); +} +``` + +### C-8 +```c +/*------------------------------------------------------- +ܣӼ2ӣ𰸣ȷʾ"right"ʾ"error" +--------------------------------------------------------*/ +#include "stdio.h" +main( ) +{ + int a,b,c; + printf("please input a and b:\n"); + scanf("%d,%d",&a , &b); + printf("please input the answer:\n"); + scanf("%d",&c); +/**********Program**********/ + if(a+b==c) + + + + +/********** End **********/ + printf("right\n"); + else + printf("error\n"); +} +``` + +### C-9 +```c +/*------------------------------------------------------- +ܣܣε߳жܷ񹹳Σܣú׹ʽ + ε3λС + l=(a+b+c)/2s=sqrt(l*(l-a)*(l-b)*(l-c)) +--------------------------------------------------------*/ +#include +#include +main() +{ + float a,b,c,s,l; + scanf("%f,%f,%f",&a , &b , &c); + if(a+b +main() +{ + int fib[15],i; + fib[0]=1;fib[1]=1; +/**********Program**********/ + for(i=2;i<15;i++){ + fib[i]=fib[i-1]+fib[i-2]; + } + + + + +/********** End **********/ + + for(i=0;i<15;i++) + { + printf("%d\t",fib[i] ); + if ( i%5==4 ) printf("\n"); + } +} +``` + +### C-11 +```c +/*------------------------------------------------------- +1. ж101-200֮жٸжķIsPrimeһֱȥ2sqrt()ܱ֮ --------------------------------------------------------*/ +#include +#include +int IsPrime (int n) +{ + int i=2; + for(i=2;i<=sqrt(n);i++) +/**********Program**********/ + if(n%i==0){ + return 0; + } + + + + +/********** End **********/ + return 1; +} + +int main( ) +{ + int i ; + for(i=100;i<=200;i++ ) + { + if ( IsPrime( i) ) + { + printf("% d",i); + } +} +return 0; +} + + ``` + +### C-12 +```c +/*------------------------------------------------------- + +ܣ1001000֮ĸλܱ֮15ʱÿ10һС +ÿռ5ַ + 159 168 177 186 195 249 258 267 276 285 + 294 339 348 357 366 375 384 393 429 438 + 447 456 465 474 483 492 519 528 537 546 + 555 564 573 582 591 609 618 627 636 645 + 654 663 672 681 690 708 717 726 735 744 + 753 762 771 780 807 816 825 834 843 852 + 861 870 906 915 924 933 942 951 960 +-------------------------------------------------------*/ +#include +main() +{ + int m,n,k,i=0; + for(m=100;m<=1000;m++) + { + k=0; + n=m; +/**********Program**********/ + while(n){ + k+=n%10; + n/=10; + } + if(k%15==0){ + i++; + printf("%5d", m); + + if(i%10==0){ + printf("\n"); + } + } + + + +/********** End **********/ + + } +} +``` + +### C-13 +```c +/*------------------------------------------------------- +Ŀ ӡͼ + +********* + ******* + ***** + *** + * +--------------------------------------------------------*/ +#include +void main() +{ + int i,j,k; + for( i=0 ; i<5; i++ ) + { + printf("\n"); +/**********Program**********/ + for(j=0;j +void main() +{ + int i,j,k; +/**********Program**********/ + for(i=0;i<3;i++){ + for(j=0;j +main() +{ + int a,b; + scanf("%d%d",&a , &b ); + printf("a=%d,b=%d\n",a,b); +/**********Program**********/ + a = a+b; + b = a-b; + a = a-b; + + + + +/********** End **********/ + printf("a=%d,b=%d\n", a,b); +} +``` + +### C-16 +```c +/*------------------------------------------------------- +Ŀ뽫123-321֮żۼս +--------------------------------------------------------*/ +#include +int main() +{ + int i; + long sum = 0; + for(i = 123; i <= 321; i++ ) + { +/**********Program**********/ + if(i%2==0){ + sum += i; + } +/********** End **********/ + } + printf ("ܺΪ : %ld.\n",sum); + return 0; +} + +``` + +### C-17 +```c +/*------------------------------------------------------- +Ŀ123321֮ĿԱ7ʹforѭ +--------------------------------------------------------*/ +#include +void main() +{ + int a=0; +/**********Program**********/ + for(a=123;a<=321;a++){ + if(a%7==0){ + + + + +/********** End **********/ + printf("%d\n",a); + } + } +} +``` + +### C-18 +```c +/*------------------------------------------------------- +ܣʮҳƽһӡ +--------------------------------------------------------*/ +#include +void main() +{ + int i; + float x,y,z=0; + printf("\n10"); + for(i=1;i<=10;i++) + { +/**********Program**********/ + scanf("%f", &x); + if(x*x > z){ + z = x*x; + y = x; + } +/********** End **********/ + } + printf("ƽһǣ%f\n",y); +} +``` + +### C-19 +```c +/*------------------------------------------------------- +ܣӼһλiλ֮͡ + 31421ӡΪ11ʹwhileѭ +--------------------------------------------------------*/ +#include +main() +{ + int i,sum=0,a; + scanf("%d",&i); +/**********Program**********/ + while(i){ + sum += i%10; + i/=10; + } + + + + +/********** End **********/ + printf("%d\n",sum); +} +``` + +### C-20 +```c +/*------------------------------------------------------- +ܣдʹSwitch )գǸĵڼ졣жǷΪ + ǣܱ 4 Dzܱ100ܱİ +--------------------------------------------------------*/ +#include"stdio.h" +main() +{ + int year,month,day,days=0,i,d; + printf("--:"); + scanf("%d-%d-%d",&year,&month,&day); + for(i=1;i +main() +{ + int i,n,p; + p=1; + printf("һn:"); + scanf("%d",&n); +/**********Program**********/ + for(i=2;i<=n;i++){ + p*=i; + } + +/********** End **********/ + printf("1*2*...*%d = %d\n",n,p); +} + + +``` + +### C-2 +```c +/*------------------------------------------------------- +̼еĽֱֵһľֵС10-5ΪֹҪС10λ: ʹwhile +-------------------------------------------------------*/ +#include +#include +main() +{ + int i,f; + double t,s; + f=1; + s=0; + i=1; + t=1.0; +/**********Program**********/ + while(fabs(t/i)>1e-5){ + s+=t/i*f;//ֵ + f*=-1;//ת + i+=2; + } + +/********** End **********/ + s=s*4; + printf("ԲʵĽֵΪ%.10f\n",s); +} +``` + +### C-3 +```c +/*------------------------------------------------------- +̼еĽֱֵһľֵС10-5Ϊֹʹwhile: +-------------------------------------------------------*/ +#include +#include +#define N 1e-5 +main() +{ + int i,f; + double t,s; + f=1; + s=0; + i=1; + t=1.0; +/**********Program**********/ + while(fabs(t/i)>N){ + s+=t/i*f;//ֵ + f*=-1;//ת + i+=2; + } + + + + +/********** End **********/ + s=s*4 ; + printf("ԲʵĽֵΪ%f\n",s); +} +``` + +### C-4 +```c +/*------------------------------------------------------- +ܣʵ1-10110֮ij˻ʹwhile +--------------------------------------------------------*/ +#include +main( ) +{ + int i=1, sum=1; +/**********Program**********/ + while(i<10){ + sum*=i; + i++; + } + +/********** End **********/ + printf("the sum of odd is :%d\n",sum); +} + +``` + +### C-5 +```c +/*------------------------------------------------------- +ܣӼɸѧijɼͳƲ߳ɼ +ͳɼ븺ʱ롣ʹwhileѭ +--------------------------------------------------------*/ +#include +main() +{ + int x,max,min; + printf("please input x:\n"); + scanf("%d",&x); + max=x; + min=x; +/**********Program**********/ + while(x > 0){ + if(x > max){ + max = x; + } + if(x < min){ + min = x; + } + scanf("%d", &x); + } + + + + +/********** End **********/ + printf("max=%d,min=%d\n",max,min); +} +``` + +### C-6 +```c +/*------------------------------------------------------- +̼㣺ʹfor㣬s=1+2+3++n nɼ룩 +-------------------------------------------------------*/ +#include +main() +{ + int i,n,sum; + sum=0; + printf("һn:"); + scanf("%d",&n); +/**********Program**********/ + for(i=1;i<=n;i++){ + sum+=i; + } + +/********** End **********/ + printf("1+2+...+%d = %d\n",n,sum); +} + + +``` + +### C-7 +```c +/*------------------------------------------------------- +ܣдȽabĴСҰѴ߸maxС߸min +--------------------------------------------------------*/ +#include"stdio.h" +main() +{ + int a,b,min,max; + printf("a,b:"); + scanf("%d,%d",&a,&b); +/**********Program**********/ + if (a > b) { + max = a; + min = b; + } else { + max = b; + min = a; + } +/********** End **********/ + printf("min=%d,max=%d\n",min,max); +} + +``` + +### C-8 +```c +/*------------------------------------------------------- +ܣx,y,zС +--------------------------------------------------------*/ +#include +main() +{ + int x,y,z,t; + scanf("%d%d%d",&x , &y , &z); +/**********Program**********/ + if (x > y) { + t = x; + x = y; + y = t; + } + if (y > z) { + t = y; + y = z; + z = t; + } + if (x > y) { + t = x; + x = y; + y = t; + } +/********** End **********/ + printf("small to big: %d %d %d\n",x,y,z); +} +``` + +### C-9 +```c +/*------------------------------------------------------- +ܣӼn,nĺ͡(ʹforѭ +--------------------------------------------------------*/ +#include +void main() +{ + int n,i,s; + s=0; + scanf("%d",&n); +/**********Program**********/ + for(i=1;i<=n;i++){ + if(i%2==1){ + s+=i; + } + } + +/********** End **********/ + printf("s=%d\n",s); +} +``` + +### C-10 +```c +/*------------------------------------------------------- +̼㣺s=1!+3!+5!+n! nɼ,ʹforѭ +-------------------------------------------------------*/ +#include +main() +{ + int i,j,n; + long p,sum; + sum=0; + printf("һn:"); + scanf("%d",&n); +/**********Program**********/ + p = 1; + for ( i = 1;i <= n; i++ ) { + p *= i; + if ( i%2 == 1 ) { + sum += p; + } + } + +/********** End **********/ + printf("1!+3!+...+%d!= %d\n",n,sum); +} +``` + +### C-11 +```c +/*------------------------------------------------------- +̼eֵ +whileֱһֵС10-5Ϊֹ +e=0+1+1/1+1/1/2+1/1/2/3... +-------------------------------------------------------*/ +#include +main() +{ + int i; + double t,e; + i=1; + t=1.0; + e=0; +/**********Program**********/ + e = 2; + i = 2; + while(t/i > 1e-5){ + e += t/i; + t /= i++; + } + +/********** End **********/ + printf("e=%f\n",e); +} + +``` + +### C-12 +```c +/*------------------------------------------------------- +̼eֵ forǰ50֮͡ +e=0+1+1/1+1/1/2+1/1/2/3... +-------------------------------------------------------*/ +#include +main() +{ + int i; + double t,e; + t=1.0; + e=0; + for(i=1;i<=50;i++) + { +/**********Program**********/ + e += t; + t /= i; +/********** End **********/ + } + printf("ǰ50֮Ϊ%f\n",e); +} + +``` + +### C-13 +```c +/*------------------------------------------------------- +ܣһԲ뾶rr>0ʱ㲢Բ(area)ܳ(circumference)ʾϢ +--------------------------------------------------------*/ +#include +#define PI 3.14 +main() +{ + float r,s,l; + printf("please input r:\n"); + scanf("%f",&r); + if (r>=0) + { +/**********Program**********/ + s = PI * r*r; + l = 2*PI*r; + +/********** End **********/ + printf("the area is %f\n",s); + printf("the circumference is %f\n",l); + } + else + printf("input error!\n"); +} + +``` + +### C-14 +```c +/*------------------------------------------------------- +ܣдλ100-999Ȼ456L654 +--------------------------------------------------------*/ +#include +void main() +{ + int n,ge,shi,bai; + printf("һλ"); + scanf("%d",&n); + if((n<100)||(n>999)) + printf("\n"); + else + { +/**********Program**********/ + ge = n % 10; + shi = n % 100 / 10; + bai = n / 100; + + +/********** End **********/ + printf("Ϊ%d%d%d\n",ge,shi,bai); + } +} + +``` + +### C-15 +```c +/*------------------------------------------------------- +̼㣺s=1!+2!+3!+n! nɼ룬ʹforѭ +-------------------------------------------------------*/ +#include +main() +{ + int i,j,n; + long p,sum; + sum=0; + printf("һn:"); + scanf("%d",&n); +/**********Program**********/ + p = 1; + for( i = 1;i <= n; i++ ){ + p *= i; + sum += p; + } + +/********** End **********/ + printf("1!+2!+...+%d!= %d\n",n,sum); +} +``` + +### C-16 +```c +/*------------------------------------------------------- +̼㣺s=1-3+5-7+-99ʹforѭ +-------------------------------------------------------*/ +#include +main() +{ + int i,f,sum; + f=1; + sum=0; +/**********Program**********/ + for(i=1;i<=99;i++){ + if(i%2==1){ + sum += i*f; + f*=-1; + } + + } + +/********** End **********/ + printf("1-3+5-7+...-99 = %d\n",sum); +} + +``` + +### C-17 +```c +/*------------------------------------------------------- +ܣдһ򵥼ʽΪa op b ab + μop Ϊȡֵֻ+-*/ +עʽ + 룺3+4 + 3.000000+4.000000=7.000000 +--------------------------------------------------------*/ +#include +main() +{ + float a,b; + char op; + printf("Please enter a,b and op:"); + scanf("%f,%c,%f",&a,&op,&b); + switch(op) + { +/**********Program**********/ + case '+':printf("%f+%f=%f\n", a, b, a+b);break; + case '-':printf("%f-%f=%f\n", a, b, a-b);break; + case '*':printf("%f*%f=%f\n", a, b, a*b);break; +/********** End **********/ + case '/':if(b!=0) + printf("%f/%f=%f\n",a,b,a/b); + else + printf("error!\n");break; + default:printf("error!\n");break; + } +} + +``` + +### C-18 +```c +/*------------------------------------------------------- +ܣд򣬰Ĵӡ +--------------------------------------------------------*/ +#include"stdio.h" +main() +{ + int a,b,c,m; + scanf("%d,%d,%d", &a,&b,&c); +/**********Program**********/ + m = a; + if( b > m ){ + m = b; + } + if ( c > m ) { + m = c; + } + +/********** End **********/ + printf ("m=%d\n",m); +} +``` + +### C-19 +```c +/*------------------------------------------------------- +ܣʹforѭӡͼΣ + + * + *** + ***** +******* + ***** + *** + * +--------------------------------------------------------*/ +#include +main() +{ + int i,j,k; +/**********Program**********/ + for(i=-3;i<=3;i++){ + for(j=0;j<(i<0?-i:i);j++){ + printf(" "); + } + for(k=0;k<7-j*2;k++){ + printf("*"); + } + printf("\n"); + } +/********** End **********/ +} + +``` + +### C-20 +```c +/*------------------------------------------------------- +ܣҳnСǵֵ +--------------------------------------------------------*/ +#include +int main() +{ + int a,n,i,min,max; + scanf("%d",&n); + scanf("%d",&a); + min=a; + max=a; + for(i=1;i max){ + max = a; + } + if(a < min){ + min = a; + } +/********** End **********/ + } + printf("The maximum number is %d.\n",max); + printf("The minimum number is %d.\n",min); +} + +``` + diff --git a/2208/天天乐学答案/C语言-3.md b/2208/天天乐学答案/C语言-3.md new file mode 100644 index 0000000..0b6cbef --- /dev/null +++ b/2208/天天乐学答案/C语言-3.md @@ -0,0 +1,657 @@ +### C-1 +```c +/*------------------------------------------------------- +һڣһһеĵڼ죨ƽ꣩ +-------------------------------------------------------*/ +#include +main() +{ + int y,m,d,s,f; + s=0; + printf("һڣYYYY-MM-DD"); + scanf("%d-%d-%d",&y,&m,&d); + if(y%4==0&&y%100!=0||y%400==0) + f=1; + else + f=0; + switch(m-1) + { +/**********Program**********/ + case 11: s+=30; + case 10: s+=31; + case 9: s+=30; + case 8: s+=31; + case 7: s+=31; + case 6: s+=30; + case 5: s+=31; + case 4: s+=30; + case 3: s+=31; + case 2: s+=f+28; + case 1: s+=31; +/********** End **********/ + } + s=s+d ; + printf("%d-%d-%dһеĵ%d\n",y,m,d,s); +} + +``` + +### C-2 +```c +/*------------------------------------------------------- +s=a+aa+aaa+aaaa+aaaֵaΪһ֣3+33+333+3333+33333ҪaԼָnɼ,ʾa=3,n=5עʹfor + -------------------------------------------------------*/ +#include +main() +{ + int a,n,s,i,t; + s=t=0; + printf("a:"); + scanf("%d",&a); + printf("͵n:"); + scanf("%d",&n); +/**********Program**********/ + t = a; + for(i=0;i +main() +{ + int n,s,t; + s=0; + printf("һ"); + scanf("%d",&n); +/**********Program**********/ + //1011 ĩβʼ γ + //s֮ǰǰ*1 + while(n){ + s += s + n%2; + n /= 2; + } +/********** End **********/ + printf("%d\n",s); + +} +``` + +### C-4 +```c +/*------------------------------------------------------- +жmǷ,mɼ롣(ʹfor +-------------------------------------------------------*/ +#include +#include +main() +{ + int m,i,k; + printf("һ :"); + scanf("%d",&m); + k=sqrt(m); +/**********Program**********/ + for(i=2;i<=k;i++){ + if(m % i == 0){ + break; + } + } +/********** End **********/ + if(i>k) + printf("%d\n",m); + else + printf("%d\n",m); +} +``` + +### C-5 +```c +/*------------------------------------------------------- +жmǷ,mɼ롣(ʹforѭ +-------------------------------------------------------*/ +#include +main() +{ + int m,i; + printf("һ :"); + scanf("%d",&m); +/**********Program**********/ + for(i=2;i +main() +{ + int i,j; +/**********Program**********/ + for(i=1;i<10;i++){ + for(j=1;j<=i;j++){ + printf("%dx%d=%-4d", i, j, i*j); + } + printf("\n"); + } + + + + +/********** End **********/ + +} +``` + +### C-7 +```c +/*------------------------------------------------------- +Ӽ5ֵСֵƽֵ(עʹforѭ +-------------------------------------------------------*/ +#include +main() +{ + int n,s,max,min,i; + double avg; + scanf("%d",&n); + s=max=min=n; + for(i=2;i<=5;i++) + { + scanf("%d",&n); +/**********Program**********/ + if(n > max){ + max = n; + } + if(n < min){ + min = n; + } + s+=n; + + +/********** End **********/ + } + avg=s/5.0; + printf("max=%d,min=%d,avg=%f\n",max,min,avg); + +} +``` + +### C-8 +```c +/*------------------------------------------------------- +дӹԪ20003000ţÿ10ŻһС + -------------------------------------------------------*/ +#include +main() +{ + int year,count; + count=0; + for(year=2000;year<=3000;year++) + { + if(year%4==0&&year%100!=0 || year%400==0) { + printf("%-6d",year); +/**********Program**********/ + count++; + if(count%10==0){ + printf("\n"); + } + } +/********** End **********/ + } +} + + +``` + +### C-9 +```c +/*------------------------------------------------------- +һգҪһǸĵڼ졣磺200032Ǹĵ62죩 +-------------------------------------------------------*/ +#include +main() +{ + int i, year,month,day,days; + days=0; + printf("һڣʽΪyyyy-mm-dd"); + scanf("%d-%d-%d",&year,&month,&day); + for(i=1;i +#include +main() +{ + int i,j,k,m,sum; + double avg; + k=0; + sum=0; + for(i=2;k<100;i++) + { + m=sqrt(i); +/**********Program**********/ + for(j=2;j<=m;j++){ + if(i%j==0){ + break; + } + } + if(j>m){ + printf("%5d", i); + k++; + sum+=i; + if(k%10==0){ + printf("\n"); + } + } + + +/********** End **********/ + } + avg=sum/100.0; + printf("\naverage=%f\n",avg); +} + +``` + +### C-11 +```c +/*------------------------------------------------------- +100200ʱÿռ5ַȣ10һСҪ + + 101 103 107 109 113 127 131 137 139 149 + 151 157 163 167 173 179 181 191 193 197 + 199 +-------------------------------------------------------*/ +#include +#include +main() +{ + int i,j,k,m; + k=0; + for(i=101;i<200;i+=2 ) + { + m=sqrt(i); +/**********Program**********/ + for(j=2;j<=m;j++){ + if(i%j==0){ + break; + } + } + if(j > m){ + printf("%5d", i); + k++; + if(k%10==0){ + printf("\n"); + } + } +/********** End **********/ + } +} +``` + +### C-12 +```c +/*------------------------------------------------------- +ʹforѭ99˷Ҫʽͼʾ: ע˻ռĸַ +1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9 +2x1=2 2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18 +3x1=3 3x2=6 3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27 +4x1=4 4x2=8 4x3=12 4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36 +5x1=5 5x2=10 5x3=15 5x4=20 5x5=25 5x6=30 5x7=35 5x8=40 5x9=45 +6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36 6x7=42 6x8=48 6x9=54 +7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 7x8=56 7x9=63 +8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 8x9=72 +9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81 +-------------------------------------------------------*/ +#include +main() +{ + int i,j; +/**********Program**********/ + for(i=1;i<10;i++){ + for(j=1;j<10;j++){ + printf("%dx%d=%-4d", i, j, i*j); + } + printf("\n"); + } + + + + +/********** End **********/ + +} + +``` + +### C-13 +```c +/*------------------------------------------------------- +дӡһnеΣnɼ +룺5 + + * + *** +***** + *** + * +-----------------------------------------------------*/ +#include +#include +main() +{ + int i,j,k,n; + printf("һ()n:"); + scanf("%d",&n); + for(i=-n/2; i<=n/2;i++) + { +/**********Program**********/ + for(j=0;j +main() +{ + int a,b,c,i; +/**********Program**********/ + for(i=100;i<500;i++){ + a = i%10; + b = i%100/10; + c = i/100; + + if(a*a*a + b*b*b + c*c*c == i) +/********** End **********/ + printf("%d\n",i); + } +} + +``` + +### C-15 +```c +/*------------------------------------------------------- +쳲еǰǣ1123581321Уֱijֵ10000Ϊֹÿ4 + +1 1 2 3 +5 8 13 21 +34 55 89 144 +233 377 610 987 +1597 2584 4181 6765 +-------------------------------------------------------*/ +#include +main() +{ + int a,b,c,i; + a=b=1; + printf("%d\t%d\t",a,b); + for(i=3;;i++) + { + c=a+b; + if(c>10000) + break; + printf("%d\t",c); +/**********Program**********/ + if(i%4==0){ + printf("\n"); + } + a = b; + b = c; + } +/********** End **********/ +} +``` + +### C-16 +```c +/*------------------------------------------------------- +쳲еǰǣ1123581321еǰ20ÿ4 + +1 1 2 3 +5 8 13 21 +34 55 89 144 +233 377 610 987 +1597 2584 4181 6765 +-------------------------------------------------------*/ +#include +main() +{ + int a,b,c,i; + a=b=1; + printf("%d\t%d\t",a,b); + for(i=3;i<=20;i++) + { + c=a+b; + printf("%d\t",c); +/**********Program**********/ + if(i%4==0){ + printf("\n"); + } + a = b; + b = c; +/********** End **********/ + } +} + +``` + +### C-17 +```c +/*------------------------------------------------------- +ʹforѭ99˷Ҫʽͼʾ:עʽ %dx%d=%-4d) +1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9 +2x1=2 2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 +3x1=3 3x2=6 3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 +4x1=4 4x2=8 4x3=12 4x4=16 4x5=20 4x6=24 +5x1=5 5x2=10 5x3=15 5x4=20 5x5=25 +6x1=6 6x2=12 6x3=18 6x4=24 +7x1=7 7x2=14 7x3=21 +8x1=8 8x2=16 +9x1=9 + -------------------------------------------------------*/ +#include +main() +{ + int i,j; +/**********Program**********/ + for(i = 1;i<10;i++){ + for(j=1;j<=10-i;j++){ + printf("%dx%d=%-4d", i, j, i*j); + } + printf("\n"); + } + + +/********** End **********/ +} + +``` + +### C-18 +```c +/*------------------------------------------------------- +ʹforѭ99˷Ҫʽͼʾ: + 1x9=9 + 2x8=16 2x9=18 + 3x7=21 3x8=24 3x9=27 + 4x6=24 4x7=28 4x8=32 4x9=36 + 5x5=25 5x6=30 5x7=35 5x8=40 5x9=45 + 6x4=24 6x5=30 6x6=36 6x7=42 6x8=48 6x9=54 + 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 7x8=56 7x9=63 + 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 8x9=72 +9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81 +-------------------------------------------------------*/ +#include +main() +{ + int i,j; + for(i=1;i<=9;i++) + { + for(j=1;j<10-i;j++) + { + printf("\t"); + } +/**********Program**********/ + for(j=10-i;j<10;j++){ + printf("%dx%d=%-4d", i, j, i*j); + } + + + printf("\n"); + } +/********** End **********/ + +} + +``` + +### C-19 +```c +/*------------------------------------------------------- +ʹforѭ99˷Ҫʽͼʾ: +1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9 + 2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18 + 3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27 + 4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36 + 5x5=25 5x6=30 5x7=35 5x8=40 5x9=45 + 6x6=36 6x7=42 6x8=48 6x9=54 + 7x7=49 7x8=56 7x9=63 + 8x8=64 8x9=72 + 9x9=81 +-------------------------------------------------------*/ +#include +main() +{ + int i,j; + for(i=1;i<=9;i++) + { + for(j=1;j +#include +main() +{ + int i,j; + for(i=-3;i<=3;i++) + { +/**********Program**********/ + for(j=0;j<7-abs(i)*2;j++){ + printf("%d", j+1); + } + printf("\n"); +/********** End **********/ + } + +} +``` + diff --git a/2208/天天乐学答案/C语言-4.md b/2208/天天乐学答案/C语言-4.md new file mode 100644 index 0000000..0f7c580 --- /dev/null +++ b/2208/天天乐学答案/C语言-4.md @@ -0,0 +1,579 @@ +### C-1 +```c +/*------------------------------------------------------- +߳жܷ񹹳Σܹʾ +׹ʽ +һΣֱ߳ΪabcSһ¹ʽ +S=p(p-a)(p-b)(p-c) +ʽpΪܳܳһ룩P=(a+b+c)/2 +-------------------------------------------------------*/ + +#include +#include +/**********Program**********/ +double S(int a, int b, int c){ + return (a+b+c)/2; +} + +double AREA(double t, int a, int b, int c){ + return sqrt(t*(t-a)*(t-b)*(t-c)); +} + +/********** End **********/ +main() +{ + int a,b,c; + double t,area; + printf("ʾε߳"); + scanf("%d%d%d",&a,&b,&c); + if(a+b>c&&a+c>b&&b+c>a) + { + t=S(a,b,c); + area=AREA(t,a,b,c); + printf("εǣ%f\n",area); + } + else + printf("ܹ\n"); +} +``` + +### C-2 +```c +/*------------------------------------------------------- +һ100ԪƱɵֵ10Ԫ5Ԫ2Ԫ1ԪСÿλ40СҪÿһСҪУпܵĻϡ(עʹforѭ + +10ԪƱ1ţ5ԪƱ5ţ2ԪƱ31ţ1ԪƱ3 +10ԪƱ1ţ5ԪƱ6ţ2ԪƱ27ţ1ԪƱ6 +10ԪƱ1ţ5ԪƱ7ţ2ԪƱ23ţ1ԪƱ9 + + + + +ܹ34ֻ +-------------------------------------------------------*/ +#include +main() +{ + int a,b,c,d,s; + s=0; +/**********Program**********/ + for(a=1;a<10;a++){ + for(b=1;b<20;b++){ + for(c=1;c<50;c++){ + for(d=1;d<100;d++){ + if(a*10+b*5+c*2+d == 100 && a+b+c+d==40){ + s++; +/********** End **********/ + printf("10ԪƱ%dţ5ԪƱ%dţ2ԪƱ%dţ1ԪƱ%d\n",a,b,c,d); + } + } + } + } + } + printf("\nܹ%dֻ\n",s); +} + +``` + +### C-3 +```c +/*------------------------------------------------------- +̽һֽעʹwhileѭ +磺 + 90 + 90=2*3*3*5 +-------------------------------------------------------*/ +#include +main() +{ + int n,i; + printf("һ"); + scanf("%d",&n); + printf("%d=",n); + i=2; +/**********Program**********/ + while(n > i){ + if(n%i==0){ + printf("%d*", i); + n/=i; + }else{ + i++; + } + } + +/********** End **********/ + printf("%d\n",n); +} +``` + +### C-4 +```c +/*------------------------------------------------------- +ŵŴ1500ʿ̣սˣվ3һţ2ˣվ5һţ4ˣվ7һţ6ˡ̼㻹жʿ (עʹforѭ +-------------------------------------------------------*/ +#include +main() +{ + int i; +/**********Program**********/ + for(i=1000;i<1100;i++){ + if(i%3==2 && i%5==4 && i%7==6) + +/********** End **********/ + printf("%dʿ\n",i); + } +} +``` + +### C-5 +```c +/*------------------------------------------------------- +ٵһƥһٵ32ֻС1ÿƥҪԻ̼dm)(zm)С(xm)жƥ עʹforѭ + +2ƥ30ƥ,С68ƥ +5ƥ25ƥ,С70ƥ +8ƥ20ƥ,С72ƥ +11ƥ15ƥ,С74ƥ +14ƥ10ƥ,С76ƥ +17ƥ5ƥ,С78ƥ +-------------------------------------------------------*/ +#include +void main() { + int dm,zm,xm; +/**********Program**********/ + for(dm=1;dm<66;dm++){ + for(zm=1;zm<100;zm++){ + for(xm=2;xm<200;xm+=2){ + if(dm*3+zm*2+xm/2 == 100 && dm+zm+xm==100) + +/********** End **********/ + printf("%dƥ%dƥ,С%dƥ\n",dm,zm,xm); + } + } + } +} +``` + +### C-6 +```c +/*------------------------------------------------------- +ͬ㾭мأͬʮͷоʮ㣬øΣ̼㼦Ӹжֻעʹforѭ + +23ֻ,12ֻ +-------------------------------------------------------*/ +#include +main() +{ + int j,t; +/**********Program**********/ + for(j=1;j<35;j++){ + for(t=1;t<35;t++){ + if(j*2+t*4==94 && j+t == 35) + +/********** End **********/ + printf("%dֻ,%dֻ\n",j,t); + } + } +} +``` + +### C-7 +```c +/*------------------------------------------------------- +1000ڵνָһӣ1䱾֮͵28=1+2+4+7+14 +-------------------------------------------------------*/ +#include +main() +{ + int i,j,s; + for(i=2;i<=1000;i++) + { + s=0; +/**********Program**********/ + for(j=1;j +main() +{ + int i,k; + k=0; + for(i=100;i<=999;i++) + { +/**********Program**********/ + if(i%3 ==0 && i%5==0 && i%7==0){ + + + + +/********** End **********/ + printf("%5d",i); + k++; + if(k%5==0) + printf("\n"); + } + } +} +``` + +### C-9 +```c +/*------------------------------------------------------- +һжǷΪνҶԳƵ +עʹwhileѭ +-------------------------------------------------------*/ +#include +main() +{ + int n,t,s; + s=0; + scanf("%d",&n); + t=n; +/**********Program**********/ + while(n){ + s*=10; + s+=n%10; + n/=10; + } + + + + +/********** End **********/ + if( t==s ) + printf("yes\n"); + else + printf("no\n"); +} + +``` + +### C-10 +```c +/*------------------------------------------------------- +Ǯټ㾭һм +һֵǮ壬ĸһֵǮֵǮһǮټʼ̡ĸΣ +ҪÿһּҪУgjĸmjСxjжֻ +(עʹforѭ + +4ֻĸ18ֻС78ֻ +8ֻĸ11ֻС81ֻ +12ֻĸ4ֻС84ֻ +-------------------------------------------------------*/ +#include +void main() +{ + int gj,mj,xj; +/**********Program**********/ + for(gj=1;gj<20;gj++){ + for(mj=1;mj<34;mj++){ + for(xj=3;xj<300;xj+=3){ + if(gj+mj+xj==100 && gj*5+mj*3+xj/3 == 100) + +/********** End **********/ + printf("%dֻĸ%dֻС%dֻ\n",gj,mj,xj); + } + } + } +} +``` + +### C-11 +```c +/*------------------------------------------------------- +㾭һ⣺ﲻ֪֮ʣ֮ʣ֮ʣXΣ (עʹwhileѭ +-------------------------------------------------------*/ +#include +main() +{ + int i; + i=1; +/**********Program**********/ + while(1){ + + + + if(i%3==2&&i%5==3&&i%7==2) +/********** End **********/ + { + printf("%d\n",i); + break; + } + i++; + } +} +``` + +### C-12 +```c +/*------------------------------------------------------- +61.ܡӳңӵһժɸӣ һ룬񫣬ֶһڶֽʣµӳԵһ룬ֶһԺÿ춼ԡʮʱ ֻһˡһժ˶ٸӡ(עʹforѭ +-------------------------------------------------------*/ +#include + void main() { + int i,t; + t=1; +/**********Program**********/ + for(i=0;i<9;i++){ + t=(t+1)*2; + } + +/********** End **********/ + printf("һ칲ժ%dֻ\n",t); + } +``` + +### C-13 +```c +/*------------------------------------------------------- +дsum)1+2+3++nĺͣnɼ롣 +-------------------------------------------------------*/ +#include +int sum(int n); +main() +{ + int n,s; + printf("һn:"); + scanf("%d",&n); + s=sum(n); + printf("1+2+...+%d=%d\n",n,s); +} +/**********Program**********/ +int sum(int n){ + int s = 0, i; + for(i=1;i<=n;i++){ + s += i; + } + return s; +} + + + + +/********** End **********/ +``` + +### C-14 +```c +/*------------------------------------------------------- +áתԼɼ롣(עʹwhileѭ +-------------------------------------------------------*/ +#include +main() +{ + int m,n,t; + printf(""); + scanf("%d%d",&m,&n); + t=m%n; +/**********Program**********/ + while(t){ + m = n; + n = t; + t = m%n; + } +/********** End **********/ + printf("Լǣ%d\n",n); +} +``` + +### C-15 +```c +/*------------------------------------------------------- +һ100ȫƽ268һȫƽ10000󣩡 + +21 +261 +1581 +-------------------------------------------------------*/ +#include +#include +main() +{ + int i,j,k; + for(i=1;i<=10000;i++) + { +/**********Program**********/ + if(pow((int)sqrt(i+100), 2) == i+100 && pow((int)sqrt(i+268), 2) == i+268){ + + +/********** End **********/ + printf("%d\n",i); + } + } +} +``` + +### C-16 +```c +/*------------------------------------------------------- +һӣ1⣩֮͡6235 +(עʹforѭ +-------------------------------------------------------*/ +#include +main() +{ + int n,i,s; + printf("һn"); + scanf("%d",&n); + s=0; +/**********Program**********/ + for(i=2;i +main() +{ + int i,odd,even; + odd=even=0; +/**********Program**********/ + for(i=1;i<=100;i++){ + if(i%2){ + odd+=i; + }else{ + even+=i; + } + } + +/********** End **********/ + printf("֮Ϊ%d,ż֮Ϊ%d\n",odd,even); +} +``` + +### C-18 +```c +/*------------------------------------------------------- +100-1000еĻһ10(עÿռ5ַ + 101 111 121 131 141 151 161 171 181 191 + 202 212 222 232 242 252 262 272 282 292 + 303 313 323 333 343 353 363 373 383 393 + 404 414 424 434 444 454 464 474 484 494 + 505 515 525 535 545 555 565 575 585 595 + 606 616 626 636 646 656 666 676 686 696 + 707 717 727 737 747 757 767 777 787 797 + 808 818 828 838 848 858 868 878 888 898 + 909 919 929 939 949 959 969 979 989 999 +-------------------------------------------------------*/ +#include +main() +{ + int i,s,t,k; + k=0; +/**********Program**********/ + for(i=100;i<1000;i++){ + s = 0; + t = i; + while(t){ + s*=10; + s+=t%10; + t/=10; + } + if(s == i){ + printf("%5d", i); + k++; + if(k%10==0){ + printf("\n"); + } + } + } + + + + +/********** End **********/ +} +``` + +### C-19 +```c +/*------------------------------------------------------- +1234ĸֿɶٸظֵλЩλעʹforѭ + +1234 +1243 +1324 + + + +24ظֵλ +-------------------------------------------------------*/ +#include +main() +{ + int a,b,c,d,count; + count=0; +/**********Program**********/ + for(a=1;a<5;a++) + for(b=1;b<5;b++) + for(c=1;c<5;c++) + for(d=1;d<5;d++) + if(a!=b && a!=c && a!=d && b!=c && b!=d && c!=d){ + printf("%d%d%d%d\n", a, b, c, d); + count++; + } +/********** End **********/ + printf("%dظֵλ\n",count); +} +``` + +### C-20 +```c +/*------------------------------------------------------- +һС100£ÿεԭһߣ10ʱľ뼰10εĸ߶ȡ +עʹforѭ +-------------------------------------------------------*/ + +#include +main() +{ + int i; + double h,s; + s=100; + h=50; +/**********Program**********/ + for(i=0;i<9;i++){ + s+=h*2; + h/=2; + } + + + + +/********** End **********/ + printf("10ʱľΪ%fף10εĸ߶Ϊ%f\n",s,h); +} + +``` +