c語言編寫答案,c語言編程答案

本文目錄一覽:

求C語言練習題答案

二、填空題

1. ___變數__是指在程序運行過程中,值可以發生變化的量。

2.C語言是一種____區分_(區分/不區分)字母大小寫的語言,Password和password在C語言中是兩個___不同__(相同/不同)的標識符。

3.下面的轉義字元分別表示:

』\b』__退格___,』\n』__換行___,』\t』__水平製表___,』\」』 __雙引號字元「”」___

4.下面常量的類型分別為:

1.5E12__浮點型___,1288L _整型____,』a』__字元___,”a”__字元串___

08 __整形___,』\007』__整型___

5. C語言源程序一定要有而且只有一個__主函數___函數,程序執行時也從它開始。

6. 結構化程序設計主要有___順序__、__選擇___和__循環___三種基本結構。

三、判斷題

1. C語言不是一種結構化程序設計語言。(錯)

2. C語言是弱類型語言,為了類型轉換的方便,對類型的要求很不嚴格,在許多情況下不做類型檢查。( 對 )

3. C語言既具有高級語言的特點,同時也具有部分低級語言的特點。(對)

4. C源程序可以由多個文件組成,每個文件中都可有一個主函數main()。( 錯 )

5. C程序從main()函數開始執行,因此主函數main()必須放在程序的開頭。(錯)

6. 命名標識符時字元個數不得超過6個。(錯)

7. 對於同一個數據種類型,變數值越大,它所佔內存的位元組數越多。(錯)

8. 定義一個變數時必須指出變數類型,但是不一定必須給變數初始化。( 對 )

9. “”表示一個空字元串常量,』』表示一個空字元常量。( 對 )

10. 一個表達式中出現多種數值型數據類型,運算前先進行類型轉換。( 對 )

11. 浮點數不能作自增或自減運算,只有整型才可作自增或自減運算。( 錯 )

12. 已知a、b是整型變數,則表達式a=3,2+4,b=6,7+8是一個逗號表達式。( 對 )

四、問答題

1. 寫出下面表達式的值

(1)12/3*9=36

(2)int i=3,j;

i*=2+5;

i/=j=4;

i+=(j%2);

i、j的最終結果是多少?i=5,j=4

(3)int a=3,b,c;

b=(a++)+(a++)+(a++);

c=(++a)+(++a)+(++a);a、b、c的最終結果是多少?a=9,b=9,c=25

2. 下列表達式是否正確?若正確,表達式的值是什麼?

21/2=10 21/2.0= 10.5 21.0/2=10.5 21%2=1 21.0%2 21%2.0 18%15=3 15%18=15 3%15=3

五、編程題

編寫程序,在屏幕上輸出如下信息:

===================

= I am a student. =

===================

#include”stdio.h「

void main()

{

printf(“= I am a student. =”);

}

求一道C語言編程答案

樓主,樓上不太會說話,不要理,等等我貼出代碼。沒有其他語言基礎的C語言初學者起步是慢了一點,但是要渣油~

#include stdio.h

int main()

{

int i, n, t1 = 1, t2 = 1, nextTerm,ct=0;

//printf(“輸出幾項: “);

//scanf(“%d”, n);

n=20;

printf(“斐波那契數列: \n”);

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

{

printf(“%d “, t1);ct+=1;

if(ct%5==0)printf(“\n”);

nextTerm = t1 + t2;

t1 = t2;

t2 = nextTerm;

}

return 0;

}

//推薦個學C的網站(我自己就是在這學的):m.runoob.com/cprogramming/

C語言編程,急求答案。。。。

第一個

#include stdio.h

#include math.h

double cal(double e)

{

int c=1;

double ret = 0;

double cur = 1;

double t = 1;

while(cur  e)

{

ret += cur;

c ++;

t *= c;

cur = 1.0/c;

}

return ret;

}

int main()

{

int n, i;

double e;

printf(“input n:”);

scanf(“%d”, n);

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

{

e = pow(10, -i);

printf(“e=%lg result = %lg\n”, e, cal(e));

}

return 0;

}

第二個

#include stdio.h

int count(char *s, char c)

{

int ret = 0;

int i;

for(i = 0; s[i]; i ++)

if(s[i] == c) ret ++;

return ret;

}

void delete(char *s, char c)

{

int i,j;

for(i = j = 0; s[i]; i ++)

if(s[i] != c) s[j++] = s[i];

s[j] = 0;

}

int main()

{

char str[1024];

char c;

printf(“input str:”);

gets(str);

printf(“input char:”);

c = getchar();

printf(“count = %d\n”, count(str,c));

delete(str,c);

printf(“after delete:%s\n”, str);

return 0;

}

供參考 望採納

20分求c語言編程題答案

我這裡有一些程序(dev-c++編譯器),雖然並不是你所想要的完美答案,但是其中的一些代碼,希望對你有所幫助:

No.1 有5個學生,每個學生有3門課的成績,從鍵盤輸入數據(包括學生號,姓名,3門課的成績),計算出平均成績,將原有數據和計算出的平均分數存放在磁碟文件stud中。

程序:

#includestdio.h

#includestdlib.h

struct student

{

char num[10];

char name[8];

int score[3];

float ave;

}stu[5];

int main()

{

int i,j,sum;

FILE *fp;

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

{

printf(“\ninput score of student %d:\n”,i+1);

printf(“No.:”);

scanf(“%s”,stu[i].num);

printf(“name:”);

scanf(“%s”,stu[i].name);

sum=0;

for(j=0;j3;j++)

{

printf(“score %d:”,j+1);

scanf(“%d”,stu[i].score[j]);

sum+=stu[i].score[j];

}

stu[i].ave=sum/3.0;

}

fp=fopen(“stud”,”w”);

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

if(fwrite(stu[i],sizeof(struct student),1,fp)!=1)

printf(“file write error\n”);

fclose(fp);

fp=fopen(“stud”,”r”);

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

{

fread(stu[i],sizeof(struct student),1,fp);

printf(“\n%s,%s,%d,%d,%d,%6.2f\n”,stu[i].num,stu[i].name,

stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].ave);

}

system(“pause”);

return 0;

}

No.2 將運行No.1程序所得到的stud文件中的學生數據按平均分進行排序處理,將已排序的學生數據存入一個新文件stu_sort中。

程序:

#includestdio.h

#includestdlib.h

#define N 10

struct student

{

char num[10];

char name[8];

int score[3];

float ave;

}st[N],temp;

int main()

{

FILE *fp;

int i,j,n;

if((fp=fopen(“stud”,”r”))==NULL)

{

printf(“can not open.”);

exit(0);

}

printf(“File ‘stud’:”);

for(i=0;fread(st[i],sizeof(struct student),1,fp)!=0;i++)

{

printf(“\n%8s%8s”,st[i].num,st[i].name);

for(j=0;j3;j++)

printf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[i].ave);

}

printf(“\n”);

fclose(fp);

n=i;

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

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

if(st[i].avest[j].ave)

{

temp=st[i];

st[i]=st[j];

st[j]=temp;

}

printf(“\nNow:”);

fp=fopen(“stu_sort”,”w”);

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

{

fwrite(st[i],sizeof(struct student),1,fp);

printf(“\n%8s%8s”,st[i].num,st[i].name);

for(j=0;j3;j++)

printf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[i].ave);

}

printf(“\n”);

fclose(fp);

system(“pause”);

return 0;

}

No.3 將題No.2已排序的學生成績文件進行插入處理。插入一個學生的3門課程成績,程序先計算新插入學生的平均成績,然後將它按平均成績高低順序插入,插入後建立一個新文件。

程序:

#includestdio.h

#includestdlib.h

struct student

{

char num[10];

char name[8];

int score[3];

float ave;

}st[10],s;

int main()

{

FILE *fp,*fp1;

int i,j,t,n;

printf(“\nNo.:”);

scanf(“%s”,s.num);

printf(“name:”);

scanf(“%s”,s.name);

printf(“score1,score2,score3:”);

scanf(“%d,%d,%d”,s.score[0],s.score[1],s.score[2]);

s.ave=(s.score[0]+s.score[1]+s.score[2])/3.0;

if((fp=fopen(“stu_sort”,”r”))==NULL)

{

printf(“can not open file.”);

exit(0);

}

printf(“Original data:\n”);

for(i=0;fread(st[i],sizeof(struct student),1,fp)!=0;i++)

{

printf(“\n%8s%8s”,st[i].num,st[i].name);

for(j=0;j3;j++)

printf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[i].ave);

}

n=i;

for(t=0;st[t].aves.avetn;t++);

printf(“\nNow:\n”);

fp1=fopen(“sort1.dat”,”w”);

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

{

fwrite(st[i],sizeof(struct student),1,fp1);

printf(“\n%8s%8s”,st[i].num,st[i].name);

for(j=0;j3;j++)

printf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[t].ave);

}

fwrite(s,sizeof(struct student),1,fp1);

printf(“\n%8s%8s%8d%8d%8d%10.2f”,s.num,s.name,s.score[0],

s.score[1],s.score[2],s.ave);

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

{

fwrite(st[i],sizeof(struct student),1,fp1);

printf(“\n%8s%8s”,st[i].num,st[i].name);

for(j=0;j3;j++)

printf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[i].ave);

}

printf(“\n”);

fclose(fp);

fclose(fp1);

system(“pause”);

return 0;

}

No.4 將No.3的結果仍存入原有的文件而不另建立新文件。

程序:

#includestdio.h

#includestdlib.h

struct student

{

char num[10];

char name[8];

int score[3];

float ave;

}st[10],s;

int main()

{

FILE *fp;

int i,j,t,n;

printf(“\nNo.:”);

scanf(“%s”,s.num);

printf(“name:”);

scanf(“%s”,s.name);

printf(“score1,score2,score3:”);

scanf(“%d,%d,%d”,s.score[0],s.score[1],s.score[2]);

s.ave=(s.score[0]+s.score[1]+s.score[2])/3.0;

if((fp=fopen(“stu_sort”,”r”))==NULL)

{

printf(“can not open file.”);

exit(0);

}

printf(“Original data:\n”);

for(i=0;fread(st[i],sizeof(struct student),1,fp)!=0;i++)

{

printf(“\n%8s%8s”,st[i].num,st[i].name);

for(j=0;j3;j++)

printf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[i].ave);

}

n=i;

for(t=0;st[t].aves.avetn;t++);

printf(“\nNow:\n”);

fp=fopen(“stu_sort”,”w”);

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

{

fwrite(st[i],sizeof(struct student),1,fp);

printf(“\n%8s%8s”,st[i].num,st[i].name);

for(j=0;j3;j++)

printf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[t].ave);

}

fwrite(s,sizeof(struct student),1,fp);

printf(“\n%8s%8s%8d%8d%8d%10.2f”,s.num,s.name,s.score[0],

s.score[1],s.score[2],s.ave);

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

{

fwrite(st[i],sizeof(struct student),1,fp);

printf(“\n%8s%8s”,st[i].num,st[i].name);

for(j=0;j3;j++)

printf(“%8d”,st[i].score[j]);

printf(“%10.2f”,st[i].ave);

}

printf(“\n”);

fclose(fp);

system(“pause”);

return 0;

}

對鏈表的綜合操作:

程序:

#includestdio.h

#includestdlib.h

#includemalloc.h

#define LEN sizeof(struct student)

struct student

{

long num;

float score;

struct student *next;

};

int n;

struct student *creat(void)

{

struct student *head;

struct student *p1,*p2;

n=0;

p1=p2=(struct student *)malloc(LEN);

scanf(“%ld,%f”,p1-num,p1-score);

head=NULL;

while(p1-num!=0)

{

n=n+1;

if(n==1) head=p1;

else p2-next=p1;

p2=p1;

p1=(struct student *)malloc(LEN);

scanf(“%ld,%f”,p1-num,p1-score);

}

p2-next=NULL;

return(head);

}

void print(struct student *head)

{

struct student *p;

printf(“\nNow,These %d records are:\n”,n);

p=head;

if(head!=NULL)

do

{

printf(“%ld %5.1f\n”,p-num,p-score);

p=p-next;

}while(p!=NULL);

}

struct student *del(struct student *head,long num)

{

struct student *p1,*p2;

if(head==NULL)

{

printf(“\nlist null!\n”);

return(head);

}

p1=head;

while(num!=p1-nump1-next!=NULL)

{

p2=p1;p1=p1-next;

}

if(num==p1-num)

{

if(p1==head) head=p1-next;

else p2-next=p1-next;

printf(“delete:%ld\n”,num);

n=n-1;

}

else printf(“%ld not been found!\n”,num);

return(head);

}

struct student *insert(struct student *head,struct student *stud)

{

struct student *p0,*p1,*p2;

p1=head;

p0=stud;

if(head==NULL)

{

head=p0;

p0-next=NULL;

}

else

{

while((p0-nump1-num)(p1-next!=NULL))

{

p2=p1;

p1=p1-next;

}

if(p0-num=p1-num)

{

if(head==p1) head=p0;

else

{

p2-next=p0;

p0-next=p1;

}

}

else

{

p1-next=p0;

p0-next=NULL;

}

}

n=n+1;

return(head);

}

int main()

{

struct student *head,*stu;

long del_num;

printf(“input records:\n”);

head=creat();

print(head);

printf(“\ninput the deleted number:”);

scanf(“%ld”,del_num);

while(del_num!=0)

{

head=del(head,del_num);

print(head);

printf(“\ninput the deleted number:”);

scanf(“%ld”,del_num);

}

printf(“\ninput the inserted record:”);

stu=(struct student *)malloc(LEN);

scanf(“%ld,%f”,stu-num,stu-score);

while(stu-num!=0)

{

head=insert(head,stu);

print(head);

printf(“\ninput the inserted record:”);

stu=(struct student *)malloc(LEN);

scanf(“%ld,%f”,stu-num,stu-score);

}

system(“pause”);

return 0;

}

c語言 請寫出詳細答案

#include “stdio.h”

int main(int argc,char *argv[]){

int N,i;

double sum;

printf(“Please enter N(int N0)…\nN=”);

if(scanf(“%d”,N)!=1 || N1){

printf(“Input error, exit…\n”);

return 0;

}

for(sum=0,i=1;i=N;sum+=1.0/(i+i++-1));

printf(“sum = %f\n”,sum);

return 0;

}

運行樣例:

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

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

相關推薦

  • 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

發表回復

登錄後才能評論