你們誰會c語言,c語言是誰

本文目錄一覽:

誰會c語言啊?

#include “stdio.h”

#include “stdlib.h”

#include “string.h”

#include “conio.h”

struct time /*出版時間結構體*/

{

int year;

int month;

int day;

};

struct data /*圖書數據結構體*/

{

int num;

char bname[20];

char wname[15];

char clanum[15];

char pubcom[10];

struct time pubtime;

float price;

}books[20],book;

void face() /*程序主界面函數*/

{

system(“cls”);

printf(“\n ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n”);

printf(” ┃ ┃\n”);

printf(” ┃ ┃\n”);

printf(” ┃ 圖 書 信 息 管 理 系 統 ┃\n”);

printf(” ┃ ┃\n”);

printf(” ┃ ┃\n”);

printf(” ┃ 1.圖書數據輸入 ┃\n”);

printf(” ┃ ┃\n”);

printf(” ┃ 2.圖書數據瀏覽 ┃\n”);

printf(” ┃ ┃\n”);

printf(” ┃ 3.圖書數據查找 ┃\n”);

printf(” ┃ ┃\n”);

printf(” ┃ 4.圖書數據排序 ┃\n”);

printf(” ┃ ┃\n”);

printf(” ┃ 5.圖書數據修改 ┃\n”);

printf(” ┃ ┃\n”);

printf(” ┃ 6.圖書數據刪除 ┃\n”);

printf(” ┃ ┃\n”);

printf(” ┃ 7.退出系統 ┃\n”);

printf(” ┃ ┃\n”);

printf(” ┃ (Alpha Ver 0.1)┃\n”);

printf(” ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n”);

printf(” 請選擇操作:”);

}

int days(int year,int month) /*判斷年月,返回輸入時月份最大天數限制*/

{

int day2,loop=0;

if(year%4==0year%100!=0||year%400==0)

loop=1;

switch(month)

{

case 4:

case 6:

case 9:

case 11:

{

day2=30;

return(day2);

}

break;

case 2:

{

if(loop==1)

{

day2=29;

return(day2);

}

else

{

day2=28;

return(day2);

}

break;

}

break;

default :

{

day2=31;

return(day2);

}

break;

}

}

void input() /*圖書信息輸入函數*/

{

FILE *fp,*fp1;

struct data t;

char ch;

int day1,count,loop,i;

float temp;

do

{

system(“cls”);

fp=fopen(“book.dat”,”ab”);

if(fp==NULL)

{

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n\n\t\t\t\t文件無法創建!”);

getchar();

return;

}

do /*判斷登錄號是否重複及是否小於0*/

{

fp1=fopen(“book.dat”,”rb”);

loop=0;

fseek(fp1,0,2);

count=ftell(fp1)/sizeof(struct data);

fclose(fp1);

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\t請輸入圖書信息:”);

printf(“\n\t\t\t1.登 錄 號:”);

scanf(“%d”,book.num);

getchar();

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

{

fp1=fopen(“book.dat”,”rb”);

fseek(fp1,i*(sizeof(struct data)),0);

fread(t,sizeof(struct data),1,fp1);

fclose(fp1);

if(book.num=0)

{

loop=1;

break;

}

if(book.num==t.num)

{

loop=1;

break;

}

}

}while(loop!=0);

printf(“\n\t\t\t2.圖 書 名:”);

scanf(“%s”,book.bname);

printf(“\n\t\t\t3.作 者 名:”);

scanf(“%s”,book.wname);

printf(“\n\t\t\t4.分 類 號:”);

scanf(“%s”,book.clanum);

printf(“\n\t\t\t5.出版單位:”);

scanf(“%s”,book.pubcom);

printf(“\n\t\t\t6.出版時間:”);

printf(“\n\t\t\t 年:”);

scanf(“%d”,book.pubtime.year);

getchar();

while(book.pubtime.year2006||book.pubtime.year=0) /*判斷年份是否超出界限,超出就重新輸入正確值*/

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\t請輸入圖書信息:”);

printf(“\n\t\t\t1.登 錄 號:%d\n”,book.num);

printf(“\n\t\t\t2.圖 書 名:%s\n”,book.bname);

printf(“\n\t\t\t3.作 者 名:%s\n”,book.wname);

printf(“\n\t\t\t4.分 類 號:%s\n”,book.clanum);

printf(“\n\t\t\t5.出版單位:%s\n”,book.pubcom);

printf(“\n\t\t\t6.出版時間:”);

printf(“\n\t\t\t 年:”);

scanf(“%d”,book.pubtime.year);

getchar();

}

printf(“\t\t\t 月:”);

scanf(“%d”,book.pubtime.month);

getchar();

while(book.pubtime.month12||book.pubtime.month=0) /*判斷月份是否超出界限,超出就重新輸入正確值*/

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\t請輸入圖書信息:”);

printf(“\n\t\t\t1.登 錄 號:%d\n”,book.num);

printf(“\n\t\t\t2.圖 書 名:%s\n”,book.bname);

printf(“\n\t\t\t3.作 者 名:%s\n”,book.wname);

printf(“\n\t\t\t4.分 類 號:%s\n”,book.clanum);

printf(“\n\t\t\t5.出版單位:%s\n”,book.pubcom);

printf(“\n\t\t\t6.出版時間:”);

printf(“\n\t\t\t 年:%d”,book.pubtime.year);

printf(“\n\t\t\t 月:”);

scanf(“%d”,book.pubtime.month);

getchar();

}

printf(“\t\t\t 日:”);

scanf(“%d”,book.pubtime.day);

getchar();

day1=days(book.pubtime.year,book.pubtime.month); /*計算輸入年月後,當月的天數最大值*/

while(book.pubtime.dayday1||book.pubtime.day=0) /*判斷天數是否超出界限,超出就重新輸入正確值*/

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\t請輸入圖書信息:”);

printf(“\n\t\t\t1.登 錄 號:%d\n”,book.num);

printf(“\n\t\t\t2.圖 書 名:%s\n”,book.bname);

printf(“\n\t\t\t3.作 者 名:%s\n”,book.wname);

printf(“\n\t\t\t4.分 類 號:%s\n”,book.clanum);

printf(“\n\t\t\t5.出版單位:%s\n”,book.pubcom);

printf(“\n\t\t\t6.出版時間:”);

printf(“\n\t\t\t 年:%d”,book.pubtime.year);

printf(“\n\t\t\t 月:%d”,book.pubtime.month);

printf(“\n\t\t\t 日:”);

scanf(“%d”,book.pubtime.day);

getchar();

}

do /*判斷價格是否為0和負值*/

{

loop=0;

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\t請輸入圖書信息:”);

printf(“\n\t\t\t1.登 錄 號:%d\n”,book.num);

printf(“\n\t\t\t2.圖 書 名:%s\n”,book.bname);

printf(“\n\t\t\t3.作 者 名:%s\n”,book.wname);

printf(“\n\t\t\t4.分 類 號:%s\n”,book.clanum);

printf(“\n\t\t\t5.出版單位:%s\n”,book.pubcom);

printf(“\n\t\t\t6.出版時間:”);

printf(“\n\t\t\t 年:%d”,book.pubtime.year);

printf(“\n\t\t\t 月:%d”,book.pubtime.month);

printf(“\n\t\t\t 日:%d”,book.pubtime.day);

printf(“\n\n\t\t\t7.價 格:”);

scanf(“%f”,temp);

book.price=temp;

if(book.price=0)

{

loop=1;

}

}while(loop!=0);

fwrite(book,sizeof(struct data),1,fp);

fclose(fp);

printf(“\n\t\t\t\t\t\t是否繼續輸入數據(Y or N)?:”);

ch=getch();

}while(ch==’y’||ch==’Y’);

system(“cls”);

getchar();

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 輸 入 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n 圖書信息輸入結束!”);

printf(“\n\n\n\n Press ENTER to continue!”);

getchar();

}

void output()

{

FILE *fp;

int count,i;

char ch;

fp=fopen(“book.dat”,”rb”);

if(fp==NULL)

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 瀏 覽 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n\n\t\t\t\t文件無法讀取!”);

getchar();

return;

}

fseek(fp,0,2);

count=ftell(fp)/sizeof(struct data); /*讀取文件里的記錄條數*/

rewind(fp);

if(count==0)

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 瀏 覽 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n\n\t\t\t\t圖書庫內無信息!”);

getchar();

return;

}

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

fread(books[i],sizeof(struct data),1,fp); /*將文件中的數據讀取到內存中*/

fclose(fp);

for(i=0;icount;)

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 瀏 覽 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\t瀏覽圖書信息:”);

printf(“\n\t\t\t1.登 錄 號:%d\n”,books[i].num);

printf(“\n\t\t\t2.圖 書 名:%s\n”,books[i].bname);

printf(“\n\t\t\t3.作 者 名:%s\n”,books[i].wname);

printf(“\n\t\t\t4.分 類 號:%s\n”,books[i].clanum);

printf(“\n\t\t\t5.出版單位:%s\n”,books[i].pubcom);

printf(“\n\t\t\t6.出版時間:%d年%d月%d日\n”,books[i].pubtime.year,books[i].pubtime.month,books[i].pubtime.day);

printf(“\n\t\t\t7.價 格:%.2f\n”,books[i].price);

if(i==0count==1) /*當記錄只有1條時顯示菜單選項*/

{

printf(“\n\n\t1.返回主菜單”);

printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);

printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);

}

else if(count1) /*記錄大於1條*/

{

if(i==0) /*首頁的顯示菜單*/

{

printf(“\n\n\t1.返回主菜單\t2.下一頁”);

printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);

printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);

}

else if(i==count-1) /*末頁的顯示菜單*/

{

printf(“\n\n\t1.返回主菜單\t\t\t3.上一頁”);

printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);

printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);

}

else /*中間頁的顯示菜單*/

{

printf(“\n\n\t1.返回主菜單\t2.下一頁\t3.上一頁”);

printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);

printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);

}

}

ch=getchar();

getchar();

if(ch==’1′)

break;

if(ch==’2′)

{

if(i!=count-1) /*記錄不為末頁時向下翻頁*/

i++;

else /*記錄為末頁時的下翻處理,防止超出界限*/

{

getchar();

getchar();

}

}

if(ch==’3′)

{

if(i!=0) /*記錄不為首頁時向上翻頁*/

i–;

else /*記錄為首頁時的上翻處理,防止超出界限*/

{

getchar();

getchar();

}

}

}

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 瀏 覽 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n 圖書信息瀏覽結束!”);

printf(“\n\n\n\n Press ENTER to continue!”);

getchar();

}

void find()

{

FILE *fp;

struct data temp[20];

int count,i,n;

char ch,ch1,ch2,cha[20];

fp=fopen(“book.dat”,”rb”);

if(fp==NULL)

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n\n\t\t\t\t文件無法讀取!”);

getchar();

return;

}

fseek(fp,0,2);

n=ftell(fp)/sizeof(struct data);

rewind(fp);

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

fread(books[i],sizeof(struct data),1,fp);

fclose(fp);

if(n==0)

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n\n\t\t\t\t圖書庫內無信息!”);

getchar();

return;

}

do

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\t\t\t1.按圖書名查詢”);

printf(“\n\n\n\t\t\t2.按作者名查詢”);

printf(“\n\n\n\t\t\t3.退出查詢”);

printf(“\n\n\n\t\t\t\t請選擇相應的操作:”);

ch1=getchar();

getchar();

if(ch1==’1′)

{

do

{

count=0;

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\t\t請輸入查詢的圖書名:”);

scanf(“%s”,cha); /*輸入查詢內容*/

getchar();

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

{

if(strstr(books[i].bname,cha)) /*查詢*/

{

temp[count]=books[i]; /*將找到匹配數據放入臨時變數*/

count++; /*統計查找到的記錄條數*/

}

}

if(count==0)

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\t\t\t\t未查找到相關數據!!!”);

printf(“\n\n\n\n\n\t\t\t\t\t\t是否繼續查詢?(Y or N):”);

ch2=getchar();

getchar();

}

}while(count==0ch2==’y’||ch2==’Y’);

for(i=0;icount;) /*瀏覽匹配數據*/

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\t瀏覽圖書信息:”);

printf(“\n\t\t\t1.登 錄 號:%d\n”,temp[i].num);

printf(“\n\t\t\t2.圖 書 名:%s\n”,temp[i].bname);

printf(“\n\t\t\t3.作 者 名:%s\n”,temp[i].wname);

printf(“\n\t\t\t4.分 類 號:%s\n”,temp[i].clanum);

printf(“\n\t\t\t5.出版單位:%s\n”,temp[i].pubcom);

printf(“\n\t\t\t6.出版時間:%d年%d月%d日\n”,temp[i].pubtime.year,temp[i].pubtime.month,temp[i].pubtime.day);

printf(“\n\t\t\t7.價 格:%.2f\n”,temp[i].price);

if(i==0count==1)

{

printf(“\n\n\t1.返回主菜單”);

printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);

printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);

}

else if(count1)

{

if(i==0)

{

printf(“\n\n\t1.返回主菜單\t2.下一頁”);

printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);

printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);

}

else if(i==count-1)

{

printf(“\n\n\t1.返回主菜單\t\t\t3.上一頁”);

printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);

printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);

}

else

{

printf(“\n\n\t1.返回主菜單\t2.下一頁\t3.上一頁”);

printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);

printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);

}

}

ch=getchar();

getchar();

if(ch==’1′)

break;

if(ch==’2′)

{

if(i!=count-1)

i++;

else

{

getchar();

getchar();

}

}

if(ch==’3′)

{

if(i!=0)

i–;

else

{

getchar();

getchar();

}

}

}

}

if(ch1==’2′)

{

do

{

count=0;

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\t\t請輸入查詢的作者名:”);

scanf(“%s”,cha); /*輸入查詢內容*/

getchar();

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

{

if(strstr(books[i].wname,cha)) /*數據比較*/

{

temp[count]=books[i]; /*將找到匹配數據放入臨時變數*/

count++; /*統計查找到的記錄條數*/

}

}

if(count==0)

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\t\t\t\t未查找到相關數據!!!”);

printf(“\n\n\n\n\n\t\t\t\t\t\t是否繼續查詢?(Y or N):”);

ch2=getchar();

getchar();

}

}while(count==0ch2==’y’||ch2==’Y’);

for(i=0;icount;) /*瀏覽匹配數據*/

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\t瀏覽圖書信息:”);

printf(“\n\t\t\t1.登 錄 號:%d\n”,temp[i].num);

printf(“\n\t\t\t2.圖 書 名:%s\n”,temp[i].bname);

printf(“\n\t\t\t3.作 者 名:%s\n”,temp[i].wname);

printf(“\n\t\t\t4.分 類 號:%s\n”,temp[i].clanum);

printf(“\n\t\t\t5.出版單位:%s\n”,temp[i].pubcom);

printf(“\n\t\t\t6.出版時間:%d年%d月%d日\n”,temp[i].pubtime.year,temp[i].pubtime.month,temp[i].pubtime.day);

printf(“\n\t\t\t7.價 格:%.2f\n”,temp[i].price);

if(i==0count==1)

{

printf(“\n\n\t1.返回主菜單”);

printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);

printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);

}

else if(count1)

{

if(i==0)

{

printf(“\n\n\t1.返回主菜單\t2.下一頁”);

printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);

printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);

}

else if(i==count-1)

{

printf(“\n\n\t1.返回主菜單\t\t\t3.上一頁”);

printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);

printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);

}

else

{

printf(“\n\n\t1.返回主菜單\t2.下一頁\t3.上一頁”);

printf(“\n\n\t\t\t\t第 %d 頁/共 %d 頁”,i+1,count);

printf(“\n\n\t\t\t\t\t\t請選擇相應的操作:”);

}

}

ch=getchar();

getchar();

if(ch==’1′)

break;

if(ch==’2′)

{

if(i!=count-1)

i++;

else

{

getchar();

getchar();

}

}

if(ch==’3′)

{

if(i!=0)

i–;

else

{

getchar();

getchar();

}

}

}

}

}while(ch1!=’3′);

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 查 詢 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n 圖書信息查詢結束!”);

printf(“\n\n\n\n Press ENTER to continue!”);

getchar();

}

void sort()

{

FILE *fp;

int n,i,j;

fp=fopen(“book.dat”,”rb”);

if(fp==NULL)

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 排 序 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n\n\t\t\t\t文件無法讀取!”);

getchar();

return;

}

fseek(fp,0,2);

n=ftell(fp)/sizeof(struct data);

rewind(fp);

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

fread(books[i],sizeof(struct data),1,fp);

fclose(fp);

if(n==0)

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 排 序 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n\n\t\t\t\t圖書庫內無信息!”);

getchar();

return;

}

for(i=0;in-1;i++) /*排序*/

{ for(j=0;j(n-1)-i;j++)

{

if(books[j].numbooks[j+1].num)

{

book=books[j];

books[j]=books[j+1];

books[j+1]=book;

}

}

}

fp=fopen(“book.dat”,”wb”); /*將排序內容重新寫入文件*/

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

fwrite(books[i],sizeof(struct data),1,fp);

fclose(fp);

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 排 序 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n\n\n\t\t\t\t已按圖書登錄號排序完畢!!!”);

getchar();

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 排 序 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n 圖書信息排序結束!”);

printf(“\n\n\n\n Press ENTER to continue!”);

getchar();

}

void edit()

{

FILE *fp,*fp1;

struct data temp[20];

int i,n,count,k[20],day1,loop,count1,j;

float t1;

char cha[20],ch,ch1,ch2;

fp=fopen(“book.dat”,”rb”);

if(fp==NULL)

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 修 改 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n\n\t\t\t\t文件無法讀取!”);

getchar();

return;

}

fseek(fp,0,2);

n=ftell(fp)/sizeof(struct data);

rewind(fp);

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

fread(books[i],sizeof(struct data),1,fp);

fclose(fp);

if(n==0)

{

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 修 改 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\n\n\t\t\t\t圖書庫內無信息!”);

getchar();

return;

}

do

{

count=0;

system(“cls”);

printf(“\n ※ ※ ※ ※ ※ ※ 圖 書 信 息 修 改 ※ ※ ※ ※ ※ ※\n”);

printf(“\n\n\n\t\t請輸入要修改的圖書名:”);

scanf(“%s”,cha);

getchar();

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

{

if(strstr(books[i].bname,cha))

{

temp[count]=books[i]; /*源代碼太長發不完,你要的話留下Email和懸賞分偶跟你發過去 */

k[count]=i;

count++;

}

}

誰會用C語言編程 列印菱形(行=列=2n+1)

我會,具體代碼如下:#include stdio.hvoid main()

{

int i;

int j;

int k; for(i=0;i=3;i++)

{

for(j=0;j=2-i;j++)

print(” “);

}

for(k=0;k=2*i;k++)

printf(“*”);

print(“\n”);

}

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

{

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

printf(“”);

for(k=0;k4-2*i;k++)

printf(“*”);

printf(“\n”);

}

誰會做c語言啊,題目如下:

回答1樓的:

可以把數組設置為全局變數.

回答樓主:

今天下班了,改天幫你寫

==========補充回答===========

回答1樓:

還有一種方式能夠同時返回2個數組,其實嚴格的說是改變2個數組的內容.那就是把數組當作指針傳遞到處理函數中,這樣你在處理函數裡面可以任意改變數組的內容,在函數外面也能訪問到改變後的數據哦.不過有一個缺點,就是處理函數不會知道數組的長度,容易內存溢出

回答樓主:

以下是實現文件,注釋和使用方法也在裡面,你放到你的編譯器裡面測試一下吧

/*********以下是C文件內容************/

/*使用方法:在提示後面輸入2個數字,之間用空格或者回車隔開,如1 2

如果不想輸入了,則輸入2個負數,如 -1 -1

因為只是簡單的功能實現,所以未做錯誤輸入判斷。所以如果你輸入字母,可能會在屏幕上出現亂七八糟的內容

*/

#include stdio.h

/*提供函數memset,如果你把那個函數刪除,這個頭文件不要了*/

#include string.h

/*最大數,你要求的是100,我測試時候是10,你改這裡就可以了*/

#define MAXNUM 10

int chengji[MAXNUM];

int xuehao[MAXNUM];

int loop = 0; /*記錄輸入了多少數據*/

void ReadDat()/*獲取數據*/

{

int i;

int result;

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

{

printf(“please enter your number and score:”);

result = scanf(“%d %d”,xuehao[i],chengji[i]);

if(xuehao[i] 0 chengji[i] 0) /*如果輸入的數字都是負數,則跳出循環,不接受輸入*/

{

xuehao[i] = 0;

chengji[i] = 0;

break;

}

}

loop = i;

return ;

}

void jsSort() /*排序函數*/

{

int i;

int j;

int temp;

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

{

for(j=i;jloop;j++)

{

if(chengji[i] chengji[j])/*從大到小排序。如果用則是從小到大排序。*/

{

temp = chengji[i];

chengji[i] = chengji[j];

chengji[j] = temp ;

temp = xuehao[i];

xuehao[i] = xuehao[j];

xuehao[j] = temp ;

}

}

}

return;

}

void WriteDat()

{

int i;

printf(“xuehao\tchengji\n”);/*列印標題*/

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

{

printf(“%-6d\t%-7d\n”,xuehao[i],chengji[i]);/*左對齊輸出結果,如果不要-,則是右對齊輸出*/

}

return;

}

int main()

{

memset(chengji,0,sizeof(chengji));/*將數組chengji數值全部設置為0*/

memset(xuehao,0,sizeof(xuehao));

ReadDat();

jsSort();

WriteDat();

return 0;

}

/**********以上是C文件內容************/

你們的c語言都是在哪裡學的?

中國大學MOOC,手機APP和網頁版的都可以。

有網易郵箱就用網易郵箱登陸。

沒有的話可以註冊一個賬號。

裡面有很多課程。

至於學習C語言,我比較推薦浙大的翁愷老師講的:

「程序設計入門---C語言」,

我就是聽的這門課,講的很好。

希望對你有幫助

誰會用C語言 寫「定義函數返回兩個數中較大的數,在主函數中調用並輸出。編寫主函數調用該函數」。

#include stdio.h

int maxnum(int a, int b)

{

if(ab)return a;

else return b;

}

int main()

{

int i,j;

printf(“請輸入兩個整數:\n”);

scanf(“%d %d”,i,j);

printf(“較大的數是:%d\n”,maxnum(i,j));

return 0;

}

請輸入兩個整數:

4 9

較大的數是:9

請按任意鍵繼續. . .

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

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-11 17:13
下一篇 2024-12-11 17: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語言進行開發。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
  • Python基礎語言

    Python作為一種高級編程語言擁有簡潔優雅的語法。在本文中,我們將從多個方面探究Python基礎語言的特點以及使用技巧。 一、數據類型 Python基礎數據類型包括整數、浮點數、…

    編程 2025-04-28

發表回復

登錄後才能評論