c語言短作業,c語言作業題整理

本文目錄一覽:

c語言作業(簡單!)

其實,我想,來這裡的任何一位同志都可以解答您的問題,可是我還是希望您把它自己解答出來,真的,作為一名學生,這真的是您應該做的,無論您以後會從事什麼工作,這些基礎的東西對您都是有用的,相信我。

既然這門課對你不重要,那我就簡單回答你幾個問題吧,第一個已經有人答過了。

2.

#include stdio.h

void main()

{

float in;

char out;

scanf(“%f”, in);

if(n=90) out=’A’;

else if(n=80) out=’B’;

else if(n=70) out=’C’;

else if(n=60) out=’D’;

else out=’E’;

printf(“%c”, out);

}

第二題應該是有程序的,你沒給。

我也簡單回答一下,i=i+1的作用是進行循環計數,來控制循環次數,如果沒有回死循環。

while後面的程序還可以怎麼寫???我不知道你原來怎麼寫的???

i和sum不賦值會怎麼樣???這個是和程序有關的,如果一開始就沒賦值的話,裡面的值可能是不確定的,或者說是亂的,錯的。

如果循環體只有一條語句,可以不用大括弧。

第三題

#include stdio.h

void main()

{

char in[100];

scanf(“%s”, in);

int letter=0, number=0, space=0, other=0;

int i=0;

while(in[i])

{

if(in[i]=’0′ in[i]=’9′) number++;

else if((in[i]=’a’ in[i]=’z’) ||(in[i]=’A’ in[i]=’A’) ) letter++;

else if(in[i] == ‘ ‘) space++;

else other++;

i++;

}

printf(“letter:%d, number:%d, space:%d, other:%d”, letter, number, space, other);

}

最後那個如果數列是以一維數組給的,

#include stdio.h

void main()

{

int num[20];

int sum = 0;

int i;

for(i=0; i20; i++)sum+=num[i];

printf(“%d”, sum);

}

短作業優先演算法用c語言如何寫?

這樣寫應該可以:

#includeiostream.h

#includestdio.h

struct pcb{

char pno;

int come_time; //到達時間

int run_time; //服務時間

};

float fcfs(pcb pro[],int n)

{

struct pcb temp;

int i,j,k; //time為當前時間

float weight_time=0,time=0; //記錄周轉時間的和

//temp=(pcb)malloc(sizeof(pcb));

cout”進程調度情況如下:”endl;

cout”進程號 到達時間 服務時間 周轉時間:”endl;

//選擇排序過程,按到達時間升序排列

for(i=0;in-1;i++)

{

k=i;

for(j=i+1;jn;j++)

if(pro[k].come_timepro[j].come_time)

k=j;

if(k!=i)

{

temp=pro[i];

pro[i]=pro[k];

pro[k]=temp;

}

}

for(i=0;in;i++)

{ time+=pro[i].run_time;

weight_time+=(time-pro[i].come_time)/pro[i].run_time; //(time-pro[i].come_time)/pro[i].run_time為排序後第i個進程的周轉時間

coutpro[i].pno” “pro[i].come_time” “pro[i].run_time” “(time-pro[i].come_time)/pro[i].run_timeendl;

}

return weight_time/=n; //返回平均帶權周轉時間

}

void insert(pcb pro[],pcb pro1,int start,int end)//將一pcb類型的元素插入到有序數組中,最後還保持有序

{

int i=end;

while((i–)start)

if(pro[i].run_timepro1.run_time)pro[i+1]=pro[i];

pro[i]=pro1;

}

float sjp(pcb pro[],int n)

{

int i,first=0,count,flag[20],k,min;

float time=0,weight_time=0;

//調度第一個到達內存的進程

for(i=1;in;i++)

{

if(pro[first].come_timepro[i].come_time) first=i;

flag[i]=0;

}

flag[first]=1;

time=(float)pro[first].run_time;

weight_time=1;

coutpro[first].pno” “pro[first].come_time” “pro[first].run_time” “weight_timeendl;

//pro_temp[0]=pro[first];

count=n-1;

while(count)

{

k=0;

min=32767; //設置一個較大的閾值,

for(i=0;in;i++) //找到一個未被訪問的,作業較短的且已經到達內存的作業調度

if((i!=first)(flag[i]==0)(time=pro[i].come_time)(minpro[i].run_time))

{

k=i;

min=pro[i].run_time;

}

flag[k]=1; //訪問後置標記為訪問

time+=pro[k].run_time;

weight_time+=(time-pro[k].come_time)/pro[k].run_time;

coutpro[k].pno” “pro[k].come_time” “pro[k].run_time” “(time-pro[k].come_time)/pro[k].run_timeendl;

count–; //每調度一個作業,count減1

}

return weight_time/=n;

}

void main()

{

pcb pro[5]={{‘C’,2,5},{‘A’,0,4},{‘B’,1,3},{‘D’,3,2},{‘E’,4,4}};

coutfcfs(pro,5)endl;

coutsjp(pro,5)endl;

}

c語言作業

也許那裡已是一片草地,

鋤犁和釘耙來來往往,

家鄉,花園,老哈哈屋和栗樹,

一無所有,只剩下我的夢。

有時候,當一隻小鳥鳴囀,

寫一個簡短的C語言代碼

最簡單的C語言代就是輸出「helloWord」,通常是作為初學編程語言時的第一個程序代碼。具體代碼如下:

#include stdio.h

int main(){

  printf(“Hello, World! \n”);

  return 0;

}

擴展資料:

1、程序的第一行#include stdio.h是預處理器指令,告訴 C 編譯器在實際編譯之前要包含 stdio.h 文件。

2、下一行intmain()是主函數,程序從這裡開始執行。

3、下一行printf(...)是C中另一個可用的函數,會在屏幕上顯示消息"Hello,World!"。

4、下一行return0;終止main()函數,並返回值0。

參考資料來源:百度百科-c語言

C語言小作業

#include

#include

#include

const

char

filename[]=”查詢結果.txt”;

FILE

*fp;

struct

ticket

{

char

banci[20];

//班次

char

shifadi[20];

//始發地

char

zhongdian[20];//終點站

int

date;

//日期

int

rest;

//剩餘票數

struct

ticket

*next;

}Node;

//1、創建鏈表

struct

ticket

*creat(int

n)

{

struct

ticket

*head,*tail,*newnode;

int

i;

head=(struct

ticket

*)malloc(sizeof(Node));

head-next=NULL;

tail=head;

printf(“車輛班次、始發地、終點站、日期(月

如九月六日0906)、剩餘票數\n”);

for(i=0;i

banci);

scanf(“%s”,newnode-shifadi);

scanf(“%s”,newnode-zhongdian);

scanf(“%d”,newnode-date);

scanf(“%d”,newnode-rest);

tail-next=newnode;

tail=newnode;

}

tail-next=NULL;

return(head);

}

//4、瀏覽

void

print(struct

ticket

*head)

{

struct

ticket

*p;

p=head-next;

//文件讀寫操作

fp=fopen(filename,”ab+”);//打開文件

printf(“班次\t始發地\t終點地\t日期\t剩餘票數

\n”);

fprintf(fp,”班次\t始發地\t終點地\t日期\t剩餘票數

\n”);

while(p!=NULL)

{

fprintf(fp,”%s\t%s\t%s\t%d\t%d

\n”,p-banci,p-shifadi,p-zhongdian,p-date,p-rest);//向文件流裡面寫文件

printf(“%s\t%s\t%s\t%d\t%d

\n”,p-banci,p-shifadi,p-zhongdian,p-date,p-rest);

p=p-next;

}

fclose(fp);//關閉文件

}

//2、增加班次

struct

ticket

*insert

(struct

ticket

*head)

{

struct

ticket

*newnode,*p,

*q;

printf(“輸入增加的車輛班次、始發地、終點站、日期(月

如九月六日09

06)、剩餘票數\n”);

scanf(“%s”,Node.banci);

scanf(“%s”,Node.shifadi);

scanf(“%s”,Node.zhongdian);

scanf(“%d”,Node.date);

scanf(“%d”,Node.rest);

newnode=(struct

ticket

*)malloc(sizeof(Node));

strcpy(newnode-banci,Node.banci);

newnode-date=Node.date;

newnode-rest=Node.rest;

strcpy(newnode-shifadi,Node.shifadi);

strcpy(newnode-zhongdian,Node.zhongdian);

p=head-next;

if

(p==NULL)

{

head-next=newnode;

newnode-next=NULL;

}else{

while(p!=NULL)

{

q=p;

p=p-next;

}

q-next=newnode;

newnode-next=NULL;

}

return

(head);

}

//6、訂票

struct

ticket

*book(struct

ticket

*head,char

b[],int

n)

{

struct

ticket

*p;

p=head-next;

if(n==1)

{

//循環結構

while(p!=NULLstrcmp(b,p-banci)!=0){

p=p-next;

}

if(p==NULL)

printf(“你所預定的班次不存在”);

if(strcmp(b,p-banci)==0)

{

if(p-rest0)

{

p-rest=p-rest-1;

printf(“訂票成功”);

}

else{

printf(“票已售完”);

}

}

}

if(n==2)

{

while(p!=NULLstrcmp(b,p-banci)!=0){

p=p-next;

}

if(p==NULL){

printf(“你所退定的班次不存在”);

}

if(strcmp(b,p-banci)==0)

{

if(p-rest0)

{

p-rest=p-rest+1;

printf(“退票成功”);

}

}

}

return

(head);

}

//3、刪除班次

struct

ticket

*del(struct

ticket

*head,char

b[])

{

struct

ticket

*p,*q;

p=head-next;

while(p!=NULLstrcmp(b,p-banci))

{

q=p;

p=p-next;

}

if

(p==NULL)

{

printf(“未找到你要刪除的班次!~、\n”);

}else{

if((p==head-next)(strcmp(b,p-banci)==0))

{

if

(p-next==NULL)

{

free(p);

head-next=NULL;

}else{

head-next=p-next;

free(p);

}

printf(“刪除成功!~、\n”);

}else

if((p!=head-next)(strcmp(b,p-banci)==0))

{

if

(p-next==NULL)

{

free(p);

q-next=NULL;

}else{

q-next=p-next;

free(p);

}

printf(“刪除成功!~、\n”);

}

}

return

(head);

}

//5、查詢

struct

ticket

*chaxun1(struct

ticket

*head,char

a[])

{

struct

ticket

*p;

p=head-next;

printf(“班次\t始發地\t終點地\t日期\t剩餘票數

\n”);

while(p!=NULL)

{

if(strcmp(p-banci,a)==0)

{

printf(“%s\t%s\t%s\t%d\t%d

\n”,p-banci,p-shifadi,p-zhongdian,p-date,p-rest);

break;

}

else

p=p-next;

}

if(p==NULL){

printf(“查詢班次不存在\n”);

}

return(head);

}

struct

ticket

*chaxun2(struct

ticket

*head,char

a[])

{

struct

ticket

*p;

p=head-next;

printf(“班次\t始發地\t終點地\t日期\t剩餘票數

\n”);

while(p!=NULL)

{

if(strcmp(p-shifadi,a)==0)

{

printf(“%s\t%s\t%s\t%d\t%d

\n”,p-banci,p-shifadi,p-zhongdian,p-date,p-rest);

break;

}

else

p=p-next;

}

return(head);

}

struct

ticket

*chaxun3(struct

ticket

*head,int

m)

{

struct

ticket

*p;

p=head-next;

printf(“班次\t始發地\t終點地\t日期\t剩餘票數

\n”);

while(p!=NULL)

{

if(p-date==m)

{

printf(“%s\t%s\t%s\t%d\t%d

\n”,p-banci,p-shifadi,p-zhongdian,p-date,p-rest);

break;

}

else

p=p-next;

}

return(head);

}

void

main()

{

printf(“=============================車票查詢訂購系統===============================\n”);

printf(“1、讀入車輛班次初始化信息\n”);

printf(“2、增加班次信息\n”);

printf(“3、刪除班次信息\n”);

printf(“4、瀏覽所有班次\n”);

printf(“5、查詢\n”);

printf(“6、訂票退票\n”);

printf(“7、退出\n”);

while(1)

{

int

i,n,m,x;

char

a[20],d[20],e[20];

struct

ticket

*head;

printf(“請輸入要使用的業務前相應的數字:\t”);

scanf(“%d”,i);

if(i==7)

break;

else

//選擇結構

switch(i)

{

case

1:

printf(“輸入錄入的個數:\t”);

scanf(“%d”,n);;

head=creat(n);

break;

case

2:

insert(head);

break;

case

3:

printf(“輸入要刪除的班次:\t”);

scanf(“%s”,e);

del(head,e);

break;

case

4:

print(head);

break;

case

5:printf(“1、按班次查詢:\t”);

printf(“2、按始發站查詢:\t”);

printf(“3、按日期查詢:\t”);

scanf(“%d”,x);;

switch(x)

{

case

1:printf(“輸入要查詢班次:\t”);

scanf(“%s”,d);

chaxun1(head,d);break;

case

2:printf(“輸入要查詢的始發站(請查詢後輸入有效的始發站):\t”);

scanf(“%s”,d);

chaxun2(head,d);break;

case

3:printf(“輸入要查詢的日期(格式0101):\t”);

scanf(“%d”,m);;

chaxun3(head,m);break;

}

break;

case

6:

printf(“訂票輸入1,退票輸入2:\t”);

scanf(“%d”,m);;

printf(“輸入你要訂或退的班次:\t”);

scanf(“%s”,a);

book(head,a,m);

break;

}

}

}

自己寫的,這是一個訂購、預訂車票系統,它有著增、刪、改、查的功能

,樓主就按照老師的要求畫個流程圖就行了。知識點

,我幫你標一下,絕對包括要求的所有知識點。不懂可以繼續追問

用C語言實現短作業優先的演算法

t=t+b[k];

這句運行出錯

應該我不懂你要達到什麼效果

所以沒辦法修改

請諒解

還有

你這個程序裡面

int

的和float的在相加

你得注意

兩個最好轉換成相同的然後在相加

怎麼轉換

轉換成那個你自己拿主意

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/259227.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-15 16:28
下一篇 2024-12-15 16:28

相關推薦

  • AES加密解密演算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密演算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES演算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演著非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • 小甲魚Python最新版課後作業及答案

    Python編程語言已經成為最受歡迎的計算機編程語言之一。而小甲魚的Python教程已經深受廣大編程學習者的青睞,其中課後作業及答案是學習過程中的必要部分。下面我們從幾個方面具體闡…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28
  • Python語言實現人名最多數統計

    本文將從幾個方面詳細介紹Python語言實現人名最多數統計的方法和應用。 一、Python實現人名最多數統計的基礎 1、首先,我們需要了解Python語言的一些基礎知識,如列表、字…

    編程 2025-04-28
  • Python作為中心語言,在編程中取代C語言的優勢和挑戰

    Python一直以其簡單易懂的語法和高效的編碼環境而著名。然而,它最近的發展趨勢表明Python的使用範圍已經從腳本語言擴展到了從Web應用到機器學習等廣泛的開發領域。與此同時,C…

    編程 2025-04-28

發表回復

登錄後才能評論