C語言作業(yè)的題與答案12(內(nèi)附詳細(xì)易懂解析題目與代碼充足的大合集)

5.一球從100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 ??
第10次落地時(shí),共經(jīng)過多少米?第10次反彈多高?
理解不同,答案不同:
(1)自己的理解(碰到算一次)
#include <stdio.h>?
int main()
{float h=100;//變量最好要有意義 ,便于思考,尋找(HTML中也 一樣)?
int n=2;?
float zlc=100;?
printf("第1次時(shí)經(jīng)過的路程為100\n");
?do{ ?h=h/2;printf("第%d次時(shí)經(jīng)過的路程為%f\n",n,h);zlc=zlc+h;
?n++;
?}//a++等的式子一般要在這位置?
?//自己演示 一下程序,從而知其錯(cuò)誤與知如何做。 心中 把循環(huán)語句畫一個(gè)圈的去想 ,去想一下運(yùn)行的效果 (方法)?
while(n<=10); printf("第10次時(shí)經(jīng)過的總路程為%f\n",zlc);printf("第10次反彈高度為%f\n",h);
}
(2)官方的標(biāo)準(zhǔn)答案理解(碰到且反彈算一次)
一球從100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地時(shí),共經(jīng)過多少米?第10次反彈多高?
譚浩強(qiáng)教授版《C程序設(shè)計(jì)》(第二版)P120 6.9 ?一球從100米高度自由落下,每次落地后反跳回原高度的一半;
再落下,求它在第10次落地時(shí),共經(jīng)過多少米?第10次反彈多高?
#include<stdio.h>
int main()
{
float h=100,s=0;
int i;
for(i=1;i<=10;i++)
{
s=s+h+h/2;printf("第%d次s=%f\n",i,s);
h=h/2;
}
printf("第10次落地時(shí),共經(jīng)過%f米。\n",s);
printf("第10次反彈%f米。\n",h);
return 0;
}
《C程序設(shè)計(jì)題解與上機(jī)指導(dǎo)》(第二版):
#include<stdio.h>
int main()
{
float s=100,h=50;
int i;
for(i=2;i<=10;i++)
{
s=s+2*h;printf("第%d次通過的路程為:%f\n",i,s);
h=h/2;
}
printf("%f %f",s,h);
return 0;
}
#include <stdio.h>?
int main()
{int age=1;?
int n=1 ;?
float x;
?int he=0;?
?do{?
printf("請輸入第%d學(xué)生的年齡\n",n);
scanf ("%d",&age) ;
printf("第%d學(xué)生的年齡為%d\n",n,age);
he=he+age;
x=he/5 ;//不寫
n++;
?}
while(n<=5);printf("%d個(gè)學(xué)生的總年齡為%d\n",(n-1),he);printf("%d個(gè)學(xué)生的平均年齡為%f\n",(n-1),x);// ? ? ? ? ?printf("%d個(gè)學(xué)生的平均年齡為%f\n",(n-1),he/(n-1));
}
#include <stdio.h>?
int main()
{printf("請輸入班級總學(xué)生人數(shù)\n");
int n=1;
int ls;?
float zf=0;?
scanf ("%d",&ls) ;
?
?if(n>0){?
while(n<=ls){
printf("請輸入第%d個(gè)學(xué)生成績\n",n);
int cj;?
scanf ("%d",&cj) ;
printf("第%d個(gè)學(xué)生成績?yōu)?d\n",n,cj);
zf=zf+cj;?
n++;
?}
printf("%d個(gè)學(xué)生的總成績?yōu)?f\n,平均成績?yōu)?f\n",(n-1),zf,zf/(n-1));}
else{printf("學(xué)生成績不為負(fù)數(shù)") ;
}
}
#include <stdio.h>?
int main()
{
int n=1;
int a=80000;
?
do{
a=a+a*0.25;
n++;
?}
while(a<=280000);
printf("第%d年達(dá)280000人",n);
}
#include <stdio.h>?
int main()
{
int n=1;
int a=3000;
?
do{
a=a+a*0.05;
n++;
?}
while(a<=5000);
printf("第%d年達(dá)5000元",n);
}
山上有一口缸可以裝50升水,現(xiàn)在有15升水.
老和尚叫小和尚下山挑水,每次可以挑5升.
問:小和尚要挑幾次水才可以把水港挑滿
#include <stdio.h>?
int main()
{
int n=0;
int a=15;
?
do{
a=a+5;
n++;
?}
while(a<=50);
printf("第%d次水才可以把水港挑滿",n-1);
}
計(jì)算2000年的1月1到2008年的1月1日之間相隔有多少天
#include <stdio.h>?
int main()
{
int n=2000;
int a=0;
?
do{if(n%4==0&&n%100!=0){a=a+365;
}
?if(n%400==0){a=a+366;
?}
n++;
?}
while(n<=2008);
printf("2000年的1月1到2008年的1月1日之間相隔有%d天",a);
}
計(jì)算2008年的1月1日,到2008年的9月1日相隔有多少天
#include <stdio.h>?
int main()
{
int n=1;
int a=0;
?
do{if(n==1){a=a+31;
}
else if(n==3){a=a+31;
}else if(n==5){a=a+31;
}else if(n==7){a=a+31;
}else if(n==8){a=a+31;
}else if(n==10){a=a+31;
}else if(n==12){a=a+31;
}else if(n==2){a=a+28;
}
?else if(n==2){a=a+28;
}
else if(n==4){a=a+28;
}
else if(n==6){a=a+28;
}
else if(n==9){a=a+28;
}
n++;
?}
while(n<=9);
printf("2008年的1月1日,到2008年的9月1日相隔有%d天",a);
}
7、計(jì)算2000年的1月1到2008年的1月1日之間相隔有多少天。(提示:平年有365天,潤年有366天,循環(huán)從2000年到2008年結(jié)束)
public class four {
?public static void main(String []args){
? int a=0;
? int sum =0;
? for(int i=2000;i<2008;i++){
? if(i%400==0||(i%4==0&&i%100==0)){
? a=366;
? }else{
? a=365;
? }
? sum=sum+a;
? }
? System.out.println(sum);?
?}
}
8、計(jì)算2008年的1月1日,到2008年的9月1日相隔有多少天。(提示:如果是潤年的2月就有29天,
平年的2月有28天。1、3、5、7、8、10、12月都有31天,4、6、9、11月都有30天)
public class four {
?public static void main(String []args){
? int a=1;
? int sum =0;
? while(a<9){
? ?switch(a){
? ?case 4:
? ?case 6:
? ?case 9:
? ?case 11:
? ? sum=sum+30;break;
? ?case 2:
? ? sum=sum+29;break;
? ? default:
? ? ?sum=sum+31;break;
? ?}
? ?a++;
? }
? System.out.println("2008年的1月1日,到2008年的9月1日相隔有"+sum+"天");
?}
}
9、計(jì)算2000年的1月1日到2008年的9月1日相隔多少天
public class four {
?public static void main(String []args){
? int a=1,b=0;
? int sum =0;
? for(int i=2000;i<2008;i++){
? ?if(i%400==0||(i%4==0&&i%100==0)){
? ? b=366;
? ?}else{
? ? b=365;
? ?}
? ?sum=sum+b;
? }
? while(a<9){
? ?switch(a){
? ?case 4:
? ?case 6:
? ?case 9:
? ?case 11:
? ? sum=sum+30;break;
? ?case 2:
? ? sum=sum+29;break;
? ? default:
? ? ?sum=sum+31;break;
? ?}
? ?a++;
? }
? System.out.println("2000年的1月1日,到2008年的9月1日相隔有"+sum+"天");
?}
}
苦練半年,眼看大賽在即,
每彩排一次,就問導(dǎo)演:“結(jié)果滿意么?”,如果回答“y”
以后就不用彩排了,不滿意的話每天都要彩排,
直到現(xiàn)場表現(xiàn)讓她滿意為止!?
#include <stdio.h>?
int main()
{char a;?
int n;
do{ printf("結(jié)果滿意么??y滿意,以后就不用彩排了 ?其他字符 ?不滿意,每天都要彩排");
scanf("%c",&a) ;
}
while(a!='y');?
printf("滿意,以后就不用彩排了");
}
4.讓計(jì)算機(jī)隨機(jī)產(chǎn)生10個(gè)0到2之間的數(shù),
如果產(chǎn)生的是0就輸出“生成了一只白豬,我好怕怕”,
如果產(chǎn)生的是1就輸出“生成了一只黑豬,我喜歡”
如果產(chǎn)生的是2就輸出“生成了一只紅豬,有下酒菜了”。
#include <stdio.h>?
#include <stdlib.h>?
#include <time.h>?
int main()
{
srand((int)time(0));
float a,b,c,d,e,f,g,h,i,j;
a=rand()%2;
b=rand()%2;
c=rand()%2;
d=rand()%2;
e=rand()%2;
f=rand()%2;
g=rand()%2;
h=rand()%2;
i=rand()%2;
j=rand()%2;
printf("%f",a);
if(a==0){
printf("生成了一只白豬,我好怕怕 ");}
else if(a==1){
printf("生成了一只黑豬,我喜歡");}
else if(a==2){
printf("生成了一只紅豬,有下酒菜了 ");}
printf("%f",b);
if(b==0){
printf("生成了一只白豬,我好怕怕 ");}
else if(b==1){
printf("生成了一只黑豬,我喜歡");}
else if(b==2){
printf("生成了一只紅豬,有下酒菜了 ");}
printf("%f",c);
if(c==0){
printf("生成了一只白豬,我好怕怕 ");}
else if(c==1){
printf("生成了一只黑豬,我喜歡");}
else if(c==2){
printf("生成了一只紅豬,有下酒菜了 ");}
printf("%f",d);
if(d==0){
printf("生成了一只白豬,我好怕怕 ");}
else if(d==1){
printf("生成了一只黑豬,我喜歡");}
else if(d==2){
printf("生成了一只紅豬,有下酒菜了 ");}
printf("%f",e);
if(e==0){
printf("生成了一只白豬,我好怕怕 ");}
else if(e==1){
printf("生成了一只黑豬,我喜歡");}
else if(e==2){
printf("生成了一只紅豬,有下酒菜了 ");}?
printf("%f",f);
if(f==0){
printf("生成了一只白豬,我好怕怕 ");}
else if(f==1){
printf("生成了一只黑豬,我喜歡");}
else if(f==2){
printf("生成了一只紅豬,有下酒菜了 ");}
printf("%f",g);
if(g==0){
printf("生成了一只白豬,我好怕怕 ");}
else if(g==1){
printf("生成了一只黑豬,我喜歡");}
else if(g==2){
printf("生成了一只紅豬,有下酒菜了 ");}
printf("%f",h);
if(h==0){
printf("生成了一只白豬,我好怕怕 ");}
else if(h==1){
printf("生成了一只黑豬,我喜歡");}
else if(h==2){
printf("生成了一只紅豬,有下酒菜了 ");}
printf("%f",i);
if(i==0){
printf("生成了一只白豬,我好怕怕 ");}
else if(i==1){
printf("生成了一只黑豬,我喜歡");}
else if(i==2){
printf("生成了一只紅豬,有下酒菜了 ");}
printf("%f",j);
if(j==0){
printf("生成了一只白豬,我好怕怕 ");}
else if(j==1){
printf("生成了一只黑豬,我喜歡");}
else if(j==2){
printf("生成了一只紅豬,有下酒菜了 ");}?
}
#include <stdio.h>?
#include <stdlib.h>?
#include <time.h>?
int main()
{
srand((int)time(0));
double a;
a=rand()%3+0;
int n=1;
while(n<=10){printf("%f ",a);if(a==0){
printf("生成了一只白豬,我好怕怕 ");}
else if(a==1){
printf("生成了一只黑豬,我喜歡");}
else if(a==2){
printf("生成了一只紅豬,有下酒菜了 ");}
n++;
}
}
2(選做)
猴子摘了一堆棗N個(gè),第一天吃了一半,還嫌不過癮,
又多吃了一個(gè):第二天又吃了剩下的一半零一個(gè):以后每天如此,
到第十天,猴子一看只剩下一個(gè)了。問最初有多少個(gè)棗子?
#include <stdio.h>?
int main()
{
int n=1;
while(n<=10){
n=n+(n+1)/0.5
}
printf("%d",n);
}
3(選做)
百元買百雞問題:公雞每只5元,母雞每只3元,
小雞每3只1元;一百元要求三種雞都要買,
有多少種購買組合?
#include <stdio.h>
int main()
{
int a,b,c; ? ? ? ? ? ? ? ? ? ? ? ? ? ?
for(a =1;a<= 20;a++) ? ? ? ? ? ? ? ? ??
for(b = 1;b <= 33;b++) ? ? ? ? ? ? ? ? ?
for(c = 3;c <= 92;c++)
if(5*a +3*b+c/3 == 100)?
if(a +b+c == 100)
if(c%3==0) ??
? ?
? ? ? ??
printf("公雞:%d 母雞:%d 小雞:%d\n", a,b,c);}
#include <stdio.h>
int main (){int n;
for(n=1;n<=10;n++) {printf("%d\n",n);
}
}
#include <stdio.h>
int main (){int n;
for(n=1;n<=10;n++) {printf("hello!world!\n");
}
}
srand((int)time(0));
int i=0;?
while(i<10){
int num=rand()%2;
switch(num){
case 0:
printf("白豬\n");break;?
case 1:
printf("白豬1\n");break;?
case 2:
printf("白豬2\n");break;?
}
i++;
}
#include <stdio.h>
int main (){int n;int ?he=0;printf("請輸入一個(gè)數(shù)字");int g;scanf("%d",&g);
for(n=1;n<=5;n++) { ?
?he= g+n;printf("%d+%d=%d\n",n,g,he);
}
}
#include <stdio.h>
int main (){int n;int ?he=0;printf("請輸入一個(gè)數(shù)字");int g;scanf("%d",&g);
for(n=1;n<=5;n++) { ?if(n%2==1){
?he= g+n;printf("%d+%d=%d\n",n,g,he);}
}
}
#include <stdio.h>
//#include <time.h>
//#include <stdlib.h>
int main()
{
int a,b,c; ? ? int num=0; ? ? ? ? ? ? ? ? ? ? ??
for(a =1;a<= 20;a++) { ? ? ? ??
for(b = 1;b <= 33;b++){ ? ? ? ? ??
for(c = 3;c <= 92;c++){
if(5*a +3*b+c/3 == 100) {
if(a +b+c == 100){
if(c%3==0){
? ? ?num++;
printf("公雞:%d 母雞:%d 小雞:%d\n ? ", a,b,c);
}//for,if都要用{},用鼠標(biāo)點(diǎn){時(shí),會 有對應(yīng)} 變紅。用文字不易解釋出 ,則用視頻?
}
}
} ?
} ? ?
}printf("共%d種方案",num);
}
#include <stdio.h>
int main (){?
for(int n=1;n<=100;n++) { ?if(n%11==0){
?printf("%d\n",n);
?}
?else if(n>=50){break;}?
}
}
#include <stdio.h>
int main (){?
for(int n=1;n<=100;n++) { ?if(n%2==0){
?printf("%d\n",n);
}
?
}
}
#include <stdio.h>
int main (){ printf("輸入一個(gè)數(shù)");int num;scanf("%d",&num);int j=num;
for(int i=0;i<=num;i++){
printf("%d*%d=%d\n",i,j,i+j);j--;}
?}
#include <stdio.h>
int main (){ int a,b;
for(int a=1;a<=9;a++){
for(int b=1;b<=a;b++){printf("%d*%d=%d\t",a,b,a*b);}//"for嵌套"如同俄羅斯套娃,條件并集后,循環(huán)并集的條件?
printf("\n");
}
}
#include <stdio.h>
int main (){ int a;int he=0;
for(int a=1;a<=100;a++){if(a%2==0&&a%3==0||a%10==0) { he=he+a;?
}
}?
printf("%d",he);
}
//1.使用for循環(huán),將1到100之間的所有能被7整除或者包含7的數(shù)都不打印
#include <stdio.h>
int main(){
for(int n=1;n<=100;n++){
if(n%7!=0&&n%10!=7&&n/10!=7){
printf("%d\n",n);}
}
}
//2.使用for循環(huán),將1到100之間的所有能被7整除或者包含7的數(shù)都不打印,計(jì)算其所有值的和
//如果和大于500,停止循環(huán)
#include <stdio.h>
int main(){int he=0;
for(int n=1;n<=100;n++){
if(n%7!=0&&n%10!=7&&n/10!=7){he=he+n;
printf("%d\n",n);if(he>=500) {break;
}
}
}
printf("所有值的和為%d\n",he);
}?
#include <stdio.h>
int main(){
for(int n=1;n<=5;n++){
for(int n=1;n<=5;n++){
{
}
printf("*\t\t");}
}
}
#include <stdio.h>
int main (){ int a,b;
for(int a=1;a<=5;a++){
for(int b=1;b<=a;b++){printf("*\t");}//"for嵌套"如同俄羅斯套娃,條件并集后,循環(huán)并集的條件?
printf("\n");
}
}
#include <stdio.h>
int main (){ int a,b;
for(int a=1;a<=5;a++){
for(int b=1;b<=a;b++){printf("*\t");}//"for嵌套"如同俄羅斯套娃,條件并集后,循環(huán)并集的條件?
printf("\n");
}
}
#include <stdio.h>
int main(){
for(int a=1;a<=4;a++){printf("*\n");
for(int b=1;b<=a;b++){printf("*");}
{
}
}
}
#include <stdio.h>
int main(){
for(int a=1;a<=5;a++){
for(int b=1;b<=5;b++){printf("你做了第%d個(gè)俯臥撐\n",b);
//越里面越先執(zhí)行?
}
printf("恭喜你跑完了第%d圈\n",a);
}
}
#include <stdio.h>
int main(){
for(int a=1;a<=365;a++){
for(int b=0;b<3;b++){switch(b){case 0:printf("吃了早餐\n");break;
case 1:printf("吃了午餐\n");break;
case 2:printf("吃了晚餐\n");break;
}
//越里面越先執(zhí)行?
}
printf("度過了第%d天\n",a);
}
}
#include <stdio.h>?
int main()
{int a,he;
he=0;
for(a=1;a<=10;a++) {
if(a%2==1){he=he+a;
}
}
printf("%d",he);
return 0;
}
#include <stdio.h>?
int main()
{int a,he;
he=0;
a=1;
while(a<=10) {if(a%2==1)he=he+a;
a++;
}
printf("%d",he);
return 0;
}
#include <stdio.h>?
int main()
{int a,he;
he=0;
a=1;?
do{if(a%2==1)
he=he+a;
a++;
}
while(a<=10);
printf("%d",he);
return 0;
}
#include <stdio.h>?
int main()
{char a;?
printf("退出游戲?y退出游戲 ?其他字符 ?繼續(xù)游戲");
do{?
scanf("%c",&a) ;printf("退出游戲");
}
while();?
printf("繼續(xù)游戲");
}
//3、聲明一個(gè)int型的數(shù)組,循環(huán)接收8個(gè)學(xué)生的成績,計(jì)算這8個(gè)學(xué)生的總分及平均分。
#include <stdio.h>
int main (){?
int a[8],i;
int he=0;?
for(i=0;i<=7;i++){printf("請輸錄第%d個(gè)學(xué)生的成績",i+1);
scanf("%d",&a[i]); he=he+a[i];?
}
printf("這8個(gè)學(xué)生的總分為%d,平均分為%d",he,he/i);
}
//
//4、聲明一個(gè)int型的數(shù)組,循環(huán)隨機(jī)生成13個(gè)1到13之間隨機(jī)數(shù)放入到此數(shù)組中去,再循環(huán)輸出。
#include <stdio.h>
#include <stdlib.h>?
#include <time.h>?
int main()
{
srand((int)time(0));
int a[52];
for(int i=1;i<=13;i++){
a[i]=rand()%13+1;
?
printf("%d\n",a[i]);
}
}
//
//5、聲明一個(gè)char型的數(shù)組,在此數(shù)組的單元格中放入"a,b,c"三個(gè)字符,然后使用循環(huán)將它反序輸出。如"c,b,a"。
#include <stdio.h>?
int main()
{?
char as[]={'a','b','c'};?
for(int i=2;i>=0;i--) {printf("%c",as[i]);
}
}
#include<stdio.h>
int main(){for(int n=100;n<=999;n++){
int a,b,c;
a=n%10;
b=n/10%10;
c=n/100;
if(a*a*a+b*b*b+c*c*c==n){printf("%d\n",n);
}
}}
#include<stdio.h>
int main(){
for(int n=1;n<=100;n++){if(n%3==0){printf("%d\n",n);
}
}}
//1.求1000以內(nèi)的質(zhì)數(shù),只能夠除以自身和1,除以其他沒有余數(shù)?
(1)官方標(biāo)準(zhǔn)答案:
//#include <stdio.h>
//int main(void)
//{
// ? ?/*
// ? ?輸出1000以內(nèi)的質(zhì)數(shù)
// ? ?*/
//?
// ? ?int m;
// ? ?int n;
// ? ?for (n=2;n<=1000;n++)
// ? ?{
// ? ? ? ?for (m = 2; m < n; m++)
// ? ? ? ?{
// ? ? ? ? ? ?if (n % m == 0)
// ? ? ? ? ? ?{
// ? ? ? ? ? ? ? ?break;
// ? ? ? ? ? ?}
// ? ? ? ?}
//?
// ? ? ?
// ? ? ? ?
// ? ? ? ? if(m==n)
// ? ? ? ?{
// ? ? ? ? ? ?printf("%d ? ? ",n);
// ? ? ? ?}
// ? ?}
//?
// ? ?return 0;
//}
(1)自己的答案:
#include <stdio.h>
int main()
{
? ??
?
? ? int a;
? ? int b;
? ? for (a=2;a<=1000;a++)
? ? {
? ? ? ? for (b = 2; b <= a-1; b++)
? ? ? ? {
? ? ? ? ? ? if (a % b == 0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
?
? ? ? ??
? ? ? ?
?
? ? ? ? ?if(a==b)
? ? ? ? {
? ? ? ? ? ? printf("%d ?",b);//兩個(gè)空格時(shí),數(shù)字顯示為佳?
? ? ? ? }
? ? }
?
? ? return 0;
}
//2.求1000以內(nèi)的完數(shù),
//如果一個(gè)數(shù)恰好等于它的因子之和,則稱該數(shù)為“完全數(shù)” [1] ?。
//各個(gè)小于它的約數(shù)(真約數(shù),列出某數(shù)的約數(shù),去掉該數(shù)本身,剩下的就是它的真約數(shù))的和等于它本身的自然數(shù)叫做完全數(shù)(Perfect number),又稱完美數(shù)或完備數(shù)。
//例如:第一個(gè)完全數(shù)是6,它有約數(shù)1、2、3、6,除去它本身6外,
//其余3個(gè)數(shù)相加,1+2+3=6。第二個(gè)完全數(shù)是28,它有約數(shù)1、2、4、7、14、28,
//除去它本身28外,其余5個(gè)數(shù)相加,1+2+4+7+14=28。第三個(gè)完全數(shù)是496,
//有約數(shù)1、2、4、8、16、31、62、124、248、496,除去其本身496外,其余9個(gè)數(shù)相加,
//1+2+4+8+16+31+62+124+248=496。后面的完全數(shù)還有8128、33550336等等。
#include <stdio.h>?
int main()?
{?
int n=1000;?
int r,j,i;//先聲明3個(gè)變量?
for(i=1;i<=n; i++) ? ?{ //成對的{}要對齊,便于觀察?
r = 0;?
for(j=1;j<i;j++){?
if(i%j == 0){ //j為r的因數(shù)?
r = r + j;// 此時(shí)r為因數(shù)和
? ? ? ? ?}?
? ? ? ? ? ? ? ? }?
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ??
if(r == i) ?{ // 因數(shù)和=本身數(shù)字 ??
printf("%d\n",r);?
? ? ? ? ? ? ? ? } // 完數(shù)為r或i?
? ? ? ? ? ? ? ? ? ? ? ?}?
return 0;?
}?
//3.聲明一個(gè)整形數(shù)組,提示用戶輸入10個(gè)數(shù)字,將其內(nèi)容進(jìn)行從小到大進(jìn)行排序
#include <stdio.h>
int main()
{
int a[10];
int i,fuzhi;//用于賦值 ,fuzhi為交換兩個(gè)變量的數(shù)值的第三個(gè)變量?
int xiabiao;//xia biao為下標(biāo)的拼音,這樣便于明白定義變量的含義
for(i=0;i<10;i++)
{printf("請輸入%d個(gè)整數(shù):",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<9;i++)
{
for(xiabiao=0;xiabiao<9-i;xiabiao++)
{
if(a[xiabiao]>a[xiabiao+1])
{
fuzhi=a[xiabiao];//用于賦值 ,fuzhi為交換兩個(gè)變量的數(shù)值的第三個(gè)變量?
a[xiabiao]=a[xiabiao+1];
a[xiabiao+1]=fuzhi;
}
}
}
printf("從小到大進(jìn)行排序?yàn)椋?#34;);
for(i=0;i<10;i++)
{
printf("%d ",a[i]);
}
printf("\n");
return 0;
}