2003-04-01, 10:14 PM | #1 |
註冊會員
|
請問TurboC幾個問題!!
老師出的題目,看不懂,有那位大大可以幫小弟解答呢?謝謝
1.印出從1至500中,13的倍數,每行輸出10個值,須對齊 2.求1至1000中所有為5或7的倍數之數字的總和 3.(使用無窮迴圈)輸入任意年份,判斷是否為閏年,若輸入0則結束 4.輸入三數,並求此三數中最大值與最小值的差與平均值 5.輸入一數,判斷其是否為質數 6.輸入兩數,求此二數之gcd(最大公因數) 7.輸入一數x,求其Fib(x)的值 8.輸入二數m,n,求C(m,n)的值(combination) |
送花文章: 3,
|
2003-04-12, 02:52 AM | #7 (permalink) |
|
havent touched c for a while long time, not sur its currect or not
3.(使用無窮迴圈)輸入任意年份,判斷是否為閏年,若輸入0則結束 main() { ini i; for(,,) { printf("Please enter the year"); scanf("%d",&i); if(i==0) { break } elseif(i%4==0) { printf("是閏年\n"); } else { printf("not閏年\n"); } } } |
送花文章: 0,
|
2003-04-12, 10:41 AM | #9 (permalink) |
註冊會員
|
4.輸入三數,並求此三數中最大值與最小值的差與平均值
#include <stdio.h> main() { float a,b,c,d; printf("Please enter first number:"); scanf("%f",&a); printf("Please enter 2nd number:"); scanf("%f",&b); printf("Please enter 3rd number:"); scanf("%f",&c); if ( a > b && b > c){ printf("a-c=%f \n",a-c ); printf("Average =%f" ,(a+c)/2);} if ( a > c && c > b){ printf("a-b=%f \n",a-b); printf("Average =%f" ,(a+b)/2);} if ( b > a && a > c){ printf("b-c=%f \n",b-c); printf("Average =%f" ,(b+c)/2);} if ( c > a && a > b){ printf("c-b=%f \n",c-b); printf("Average =%f" ,(b+c)/2);} if ( b > c && c > a){ printf("b-a=%f \n",b-a); printf("Average =%f ",(b+a)/2);} if ( c > b && b > a){ printf("c-a =%f \n",c-a); printf("Average =%f ",(c+a)/2);} scanf("%f",&d); } 我剛才寫的 compile過 也run過 答案正確 不過程式或許還可精簡,小弟才疏學淺,請各位大大不吝指教~~ |
送花文章: 28,
|
2003-04-12, 04:07 PM | #11 (permalink) |
註冊會員
|
5.輸入一數,判斷其是否為質數
#include <stdio.h> main() { int x,c; printf("Please enter a integer number:"); scanf("%d",&x); for(c=3;c<=x;c++) { if(x%c==0){ break; } } if(c>=x) printf("%d is a prime number",x); else printf("%d is't a prime number",x); } 我剛才寫的 compile過 也run過 答案正確 小弟才疏學淺,請各位大大不吝指教~~ |
送花文章: 28,
|
2003-04-12, 07:24 PM | #12 (permalink) |
註冊會員
|
6.輸入兩數,求此二數之gcd(最大公因數)
#include <stdio.h> main() { int A,B,n,N,c,d,e,HCF=1,flag=0; /*To declare variables*/ printf("Please enter a integer number A:"); scanf("%d",&A); /*to obtain first number A.*/ printf("Please enter a integer number B:"); scanf("%d",&B); /*to obtain 2nd number B.*/ if(A>=B) N=B; else N=A; for(n=2;n<=N;n++) { while(A%n==0 && B%n==0) { A=A/n; B=B/n; HCF = HCF * n; } if(A==1 || B==1) break; } HCF=HCF*A; HCF=HCF*B; printf("THE HIGHTEST COMMAND FACTOR IS: %d",HCF); scanf("%d",&d); } 我剛才寫的 compile過 也run過 答案正確 小弟才疏學淺,請各位大大不吝指教~~ |
送花文章: 28,
|
2003-04-12, 10:12 PM | #13 (permalink) |
註冊會員
|
7.輸入一數x,求其Fib(x)的值
#include <stdio.h>void main(){ int fib[20],x,i; printf("Please input a unmber (1 - 20):"); scanf("%d",&x); fib[0]=0; fib[1]=1; for(i=2;i<x;i++) fib[i]=fib[i-1]+fib[i-2]; printf("The fibonacci sequences are: "); for(i=0;i<x;i++) printf("%d ",fib[i]); } 我剛才寫的 compile過 也run過 答案正確 小弟才疏學淺,請各位大大不吝指教~~ |
送花文章: 28,
|