當前位置:首頁 » 編程語言 » c語言日本作業
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言日本作業

發布時間: 2022-08-30 01:43:40

c語言作業,角谷問題

#include <stdio.h>

int main()

{int x,x1;

scanf("%d",&x);

while(x!=1)

{if(x%2)

{x1=3*x1+1;

printf("%d*3+1=%d ",x,x1);

}

else

{x1=x/2;

printf("%d/2=%d ",x,x1);

}

x=x1;

}

return 0;

}

㈡ c語言結構體作業

#include<stdio.h>

structStudent

{

charname[20];

intscore;

longno;

};

voidsortbysocre(structStudent*stu,intsize)

{

inti,j;

structStudentt;

for(i=0;i<size-1;i++)

for(j=0;j<size-1-i;j++)

{

if(stu[j].score<stu[j+1].score)

{

t=stu[j];

stu[j]=stu[j+1];

stu[j+1]=t;

}

}

}

voidsortbyno(structStudent*stu,intsize)

{

inti,j;

structStudentt;

for(i=0;i<size-1;i++)

for(j=0;j<size-1-i;j++)

{

if(stu[j].no>stu[j+1].no)

{

t=stu[j];

stu[j]=stu[j+1];

stu[j+1]=t;

}

}

}

intmain()

{

structStudentstu[]={

{"小明",90,8},{"小紅",70,9},

{"小劉",100,5},{"小軍",59,3}

};

intchoice;

inti;

printf("1.按成績從高到低排序;2.按學號升序排序. 選擇:");

scanf("%d",&choice);

if(choice==1)

sortbysocre(stu,4);

else

sortbyno(stu,4);

printf("%-8s%-8s%-8s ","姓名","成績","學號");

for(i=0;i<4;i++)

{

printf("%-8s%-8d%-8ld ",stu[i].name,stu[i].score,stu[i].no);

}

getchar();

return0;

}

㈢ c語言的題目,求詳細解釋啊,在線等!

答案是 japan korea

理由:
str[3][6]是一個二維數組,可以看成是 以str[6]為元素的數組,大小為3。
str[1] 就是 字元串「japan」
str[1][5]就是"japan"的第六個字元,也就是「\0」,即字元串結束符
賦值語句把這個位置的字元改成了空格『 』 ,所以當讀取字元串str[1]的時候,計算機一直要讀到結束符「\0」為止,因此會一直把下一個字元串的內容也讀出來。

在內存中存放的順序就是
原來是: china\0
japan\0
korea\0
賦值以後:china\0
japan
korea\0
輸出str[1]的時候從j開始讀取內容一直到\0,因此得出結果
japan korea

㈣ c語言程序設計作業

//數據文件放在D盤下,名稱為1.txt
//格式為:學號姓名C語言成績數學成績物理成績
//例如:
//001趙日天958892
//002劉斬仙596273

#include<stdio.h>
#include<stdlib.h>

typedefstruct
{
charnum[8];
charname[10];
intcgrade;
intmgrade;
intphysics;
floatave;
}STUDENT;

intmain()
{
STUDENTs[50];
intcount=0;
FILE*fp;
charbuf[100];
if((fp=fopen("d:\1.txt","r"))==NULL)
{
printf("Openfilefalied!");
return-1;
}
while(!feof(fp))
{
fgets(buf,100,fp);
sscanf(buf,"%s%s%d%d%d",s[count].num,s[count].name,&s[count].cgrade,&s[count].mgrade,&s[count].physics);
s[count].ave=(s[count].cgrade+s[count].mgrade+s[count].physics)/3.0;
count++;
}
fclose(fp);
printf("共有%d人 ",count);
inti,j;
for(i=0;i<count;i++)
{
printf("%-5s%-6s%-3d%-3d%-3d%-5.2f ",s[i].num,s[i].name,s[i].cgrade,s[i].mgrade,s[i].physics,s[i].ave);
}

intmax[3]={0,0,0},min[3]={100,100,100},sum[3]={0,0,0};
floatave[3]={0.0};
intgood[3]={0,0,0},pass[3]={0,0,0},unpass[3]={0,0,0};

for(i=0;i<count;i++)
{
sum[0]+=s[i].cgrade;
sum[1]+=s[i].mgrade;
sum[2]+=s[i].physics;

if(max[0]<s[i].cgrade) max[0]=s[i].cgrade;
if(max[1]<s[i].mgrade) max[1]=s[i].mgrade;
if(max[2]<s[i].physics)max[2]=s[i].physics;

if(min[0]>s[i].cgrade) min[0]=s[i].cgrade;
if(min[1]>s[i].mgrade) min[1]=s[i].mgrade;
if(min[2]>s[i].physics)min[2]=s[i].physics;

if(s[i].cgrade>=90) good[0]++;
elseif(s[i].cgrade>=60)pass[0]++;
else unpass[0]++;

if(s[i].mgrade>=90)good[1]++;
elseif(s[i].mgrade>=60)pass[1]++;
else unpass[1]++;

if(s[i].physics>=90)good[2]++;
elseif(s[i].mgrade>=60)pass[2]++;
else unpass[2]++;
}
ave[0]=(float)sum[0]/(float)count;
ave[1]=(float)sum[1]/(float)count;
ave[2]=(float)sum[2]/(float)count;
printf(" C語言成績: ");
printf("最高分:%d最低分:%d平均分:%.2f",max[0],min[0],ave[0]);
printf(" 優秀:%d及格:%d不及格:%d",good[0],pass[0],unpass[0]);
printf(" 數學成績: ");
printf("最高分:%d最低分:%d平均分:%.2f",max[1],min[1],ave[1]);
printf(" 優秀:%d及格:%d不及格:%d",good[1],pass[1],unpass[1]);
printf(" 物理成績: ");
printf("最高分:%d最低分:%d平均分:%.2f",max[2],min[2],ave[2]);
printf(" 優秀:%d及格:%d不及格:%d",good[2],pass[2],unpass[2]);

int*all_score;
all_score=(int*)malloc(sizeof(int)*count);
for(i=0;i<count;i++)
{
all_score[i]=s[i].cgrade+s[i].mgrade+s[i].physics;
}
//排序
intt;
for(i=0;i<count-1;i++)
{
for(j=0;j<count-1-i;j++)
{
if(all_score[i]<all_score[i+1])
{
i=all_score[i];
all_score[i]=all_score[i+1];
all_score[i+1]=i;
}
}
}
printf(" 總成績最高到低為: ");
for(i=0;i<count;i++)
{
printf("%d",all_score[i]);
}

return0;
}

㈤ 一道C語言的作業,,大概意思是,求解答一個一元二次方程,AX平方+BX+C=0,依次輸入A,B,C的值

樓主你好。
以下是我的代碼:
#include <stdio.h>
#include <math.h>
int main(){
double a,b,c;
double x1,x2;
double deta;
while(1){
printf("Please enter a, b and c:");
scanf("%lf %lf %lf",&a, &b, &c);
printf("a=%.2f, b=%.2f, c=%.2f\n", a, b, c);
deta = b*b-4*a*c;
if(deta < 0){//若deta小於零,提示用戶此方程無實數解
printf("deta is negtive! This quation doesn't have a real solution!\n");
}else{
if(deta == 0){
x1=x2= -b/(2*a);
}else{
deta = sqrt(deta);
x1 = (-b+deta)/(2*a);
x2 = (-b-deta)/(2*a);
}
printf("x1=%.2f, x2 = %.2f\n", x1, x2);
}
printf("==========================================\n");
}
return 1;
}

輸出:
Please enter a, b and c:1 -7 12
a=1.00, b=-7.00, c=12.00
x1=4.00, x2 = 3.00
==========================================
Please enter a, b and c:2 -6 -20
a=2.00, b=-6.00, c=-20.00
x1=5.00, x2 = -2.00
==========================================
Please enter a, b and c:1 4 3
a=1.00, b=4.00, c=3.00
x1=-1.00, x2 = -3.00
==========================================
Please enter a, b and c:4 1 4
a=4.00, b=1.00, c=4.00
deta is negtive! This quation doesn't have a solution!
==========================================
Please enter a, b and c:

㈥ c語言難題,求助啊

覺得第5題還有點好玩,所以做了個.
應該沒問題的.

/*驗證谷角猜想。日本數學家谷角靜夫在研究自然數時發現了一個奇怪現象:
對於任意一個自然數n,若n為偶數,則將其除以2;若n為奇數,則將其乘以3,
然後再加1。如此經過有限次運算後,總可以得到自然數1。人們把谷角靜夫的
這一發現叫做「谷角猜想」。要求由鍵盤輸入一個自然數n,把n經過有限次運算
後,最終變成自然數1的全過程列印出來。 */

#include<stdio.h>
void main(void)
{
int i,t,count=0;
scanf("%d",&i);
printf("Input number is %d,processing:\n",i);
while(i!=1)
{
if(i%2==0){
t=i;
i=i/2;
printf("->%d/2=%d\n",t,i);
count++;
}
else
{
t=i;
i=i*3+1;
printf("->%d*3+1=%d\n",t,i);
count++;
}
}
printf("Total %d times used!",count);
}

附調試結果:
Input number is 20789,processing:
->20789*3+1=62368
->62368/2=31184
->31184/2=15592
->15592/2=7796
->7796/2=3898
->3898/2=1949
->1949*3+1=5848
->5848/2=2924
->2924/2=1462
->1462/2=731
->731*3+1=2194
->2194/2=1097
->1097*3+1=3292
->3292/2=1646
->1646/2=823
->823*3+1=2470
->2470/2=1235
->1235*3+1=3706
->3706/2=1853
->1853*3+1=5560
->5560/2=2780
->2780/2=1390
->1390/2=695
->695*3+1=2086
->2086/2=1043
->1043*3+1=3130
->3130/2=1565
->1565*3+1=4696
->4696/2=2348
->2348/2=1174
->1174/2=587
->587*3+1=1762
->1762/2=881
->881*3+1=2644
->2644/2=1322
->1322/2=661
->661*3+1=1984
->1984/2=992
->992/2=496
->496/2=248
->248/2=124
->124/2=62
->62/2=31
->31*3+1=94
->94/2=47
->47*3+1=142
->142/2=71
->71*3+1=214
->214/2=107
->107*3+1=322
->322/2=161
->161*3+1=484
->484/2=242
->242/2=121
->121*3+1=364
->364/2=182
->182/2=91
->91*3+1=274
->274/2=137
->137*3+1=412
->412/2=206
->206/2=103
->103*3+1=310
->310/2=155
->155*3+1=466
->466/2=233
->233*3+1=700
->700/2=350
->350/2=175
->175*3+1=526
->526/2=263
->263*3+1=790
->790/2=395
->395*3+1=1186
->1186/2=593
->593*3+1=1780
->1780/2=890
->890/2=445
->445*3+1=1336
->1336/2=668
->668/2=334
->334/2=167
->167*3+1=502
->502/2=251
->251*3+1=754
->754/2=377
->377*3+1=1132
->1132/2=566
->566/2=283
->283*3+1=850
->850/2=425
->425*3+1=1276
->1276/2=638
->638/2=319
->319*3+1=958
->958/2=479
->479*3+1=1438
->1438/2=719
->719*3+1=2158
->2158/2=1079
->1079*3+1=3238
->3238/2=1619
->1619*3+1=4858
->4858/2=2429
->2429*3+1=7288
->7288/2=3644
->3644/2=1822
->1822/2=911
->911*3+1=2734
->2734/2=1367
->1367*3+1=
->/2=2051
->2051*3+1=6154
->6154/2=3077
->3077*3+1=9232
->9232/2=4616
->4616/2=2308
->2308/2=1154
->1154/2=577
->577*3+1=1732
->1732/2=866
->866/2=433
->433*3+1=1300
->1300/2=650
->650/2=325
->325*3+1=976
->976/2=488
->488/2=244
->244/2=122
->122/2=61
->61*3+1=184
->184/2=92
->92/2=46
->46/2=23
->23*3+1=70
->70/2=35
->35*3+1=106
->106/2=53
->53*3+1=160
->160/2=80
->80/2=40
->40/2=20
->20/2=10
->10/2=5
->5*3+1=16
->16/2=8
->8/2=4
->4/2=2
->2/2=1
Total 149 times used!

㈦ C語言編寫背單詞

很簡單的,自己寫吧,冒昧說一句,不知道你到底搞這個幹嘛,真正想學的話,自己學習下就會了.
如果只是不得已得做,你註明下或許別人還會幫幫忙,幫你度過難關,否則真的不願意幫!

㈧ 請高手解決c語言編程填空題!日語題無奈。。。

第一空 while中跳出循環的條件應該是「字元串的末尾為0 」
那麼表示字元串末尾不等於0,則一直l++,那麼條件有這幾個相似的填法
*(s+l)!=0,s[l]!=0另外簡易的填寫方法,因為字元串只有截止時候才是0所以我們也可直接寫作
*(s+l),s[l]因為他們在截止前都不可能使while跳出,所以成立。

第二空return一個指針類型,那麼函數返回值是指針類型,所以應該是char*
第三空我們觀察到兩個傳入參數,一個是char* 一個是const char* 那麼const是只讀不可寫,那麼應該是把const字元串接到前面的char *d字元串後,那麼char*t=?這里我寫作char* t=d;
第四空我寫作
( *( strl(t) + t++ )=*( s++ ) )!=0
也就是d的截止0字元開始依次存入s字元串。當存入的值=0時候,那麼跳出循環.

另外main函數中char a[]="abc";這里他用的逗號,應該是分號。

㈨ C語言程序設計的作業

#include<stdio.h>
intmain()
{
intf;
floatl,s;
while(1)
{
printf(" 輸入限速值及所測車速:");
scanf("%f%f",&l,&s);
if(s-l<0)
printf("未超速不處罰記%d分 ",f=0);
elseif((s-l)/l<0.2)
printf("超速未到20%%記%d分 ",f=3);
elseif((s-l)/l>=0.2&&(s-l)/l<0.5)
printf("超速20%%未到50%%記%d分 ",f=6);
elseif((s-l)/l>=0.5)
printf("超速50%%及以上記%d分 ",f=12);
printf("駕駛證剩餘分數:%d ",12-f);
}
return0;
}
#include<stdio.h>
intgeti(charc);//獲取字元對應下標
intmain()
{
intia,ib;
chara,b;
printf("猜拳游戲:'V'表示剪刀,'S'表示石頭,'P'表示布 ");
while(1)
{
printf("請輸入玩家a的手勢:");
scanf("%c",&a);
getchar();
printf("請輸入玩家b的手勢:");
scanf("%c",&b);
getchar();
ia=geti(a);
ib=geti(b);
if(ia==-1||ib==-1)
{
printf("輸入不符合規則,請重新輸入! ");
continue;
}
if(ia-ib==1||ia-ib==-2)
printf("玩家a勝 ");
elseif(ia-ib==-1||ia-ib==2)
printf("玩家b勝 ");
else
printf("平局 ");
}
return0;
}
intgeti(charc)//獲取字元對應下標
{
charg[3]={'V','S','P'};//數組元素依次克前一個元素及被後一個元素克制
inti=0;
for(i=0;i<3;i++)
if(g[i]==c)
returni;
return-1;
}

㈩ 09秋學期《C語言》在線作業2多選

1.abcd 當省略函數的存貯類型時,默認是AUTO型
2.DE
3.ADE
4.BCD 由於C語言嚴格區分大小字,所以INT與
int 不等價,Getchar與getchar不等價
而go_to 是與go to不等價的
5.E 在函數聲明的時要分別說明形參的類型