當前位置:首頁 » 編程語言 » 張亞紅c語言程序設計
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

張亞紅c語言程序設計

發布時間: 2022-04-19 08:01:11

c語言程序設計

每次都加j導致列印錯誤。

修改如下:

if(*(p1+i)%2==0)
{
b[j]=*(p1+i);
printf("%d,",b[j]);
j++;
}

❷ 《C語言程序設計》課程設計

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

#define BUFFERSIZE 1024
#define MAXACCOUNT 1000
typedef struct BankAccount
{
int account;
int key;
char name[32];
float balance;
}BANKACCOUNT;

BANKACCOUNT accountCollection[MAXACCOUNT];
int curAccount = 0;

void InsertAccount(FILE *fp)
{
BANKACCOUNT newaccount;
printf("please input the account information\n");
printf(">>account num:");
scanf("%d",&(newaccount.account));
printf(">>key:");
scanf("%d",&(newaccount.key));
printf(">>name:");
scanf("%s",newaccount.name);
printf(">>balance:");
scanf("%f",&(newaccount.balance));
fseek(fp,0L,SEEK_END);
fprintf(fp,"%d %d %s %.2f\n",newaccount.account,newaccount.key,newaccount.name,newaccount.balance);
}
void GetAccount(FILE *fp)
{
int accountnum;
int key;
char name[32];
float balance;
int i =0,j;
char buffer[BUFFERSIZE];
int len;
curAccount = 0;
fseek(fp,0,SEEK_SET);
while(!feof(fp)) /* 因為feof()最後會讀2遍,所以最後curAccount多加了1 */
{
fscanf(fp,"%d %d %s %f",&accountnum,&key,name,&balance);
accountCollection[curAccount].account = accountnum;
accountCollection[curAccount].key = key;
strcpy(accountCollection[curAccount].name ,name);
accountCollection[curAccount].balance = balance;
curAccount++;
}
}
void ListAccount(FILE *fp)
{
int i =0;
printf("There is %d accounts at all:\n",curAccount-1);/* curAccount減去多加的1 */
for(i = 0;i< curAccount-1;i++)
{
printf("ACCOUNT[%d]:\n",i+1);
printf("account:%d\n",accountCollection[i].account);
printf("name:%s\n",accountCollection[i].name);
printf("balance:%.2f\n",accountCollection[i].balance);
}
}
int SearchAccount(FILE *fp,int accountnum)
{
int i =0;
for(i = 0;i< curAccount-1;i++)
{
if(accountCollection[i].account == accountnum)
{
printf("ACCOUNT[%d]:\n",i+1);
printf("account:%d\n",accountCollection[i].account);
printf("name:%s\n",accountCollection[i].name);
printf("balance:%.2f\n",accountCollection[i].balance);
return 1;
}
}
return 0;
}
void DelAccount(FILE *fp,int accountnum)
{
int i;
if(SearchAccount(fp,accountnum)==0)
printf("Can't find the account\n");
else
{
for(i = 0;i<curAccount-1;i++)
{
if(accountCollection[i].account != accountnum)
fprintf(fp,"%d %d %s %.2f\n",accountCollection[i].account,accountCollection[i].key,accountCollection[i].name,accountCollection[i].balance);
}
printf("delete successfully!\n");
}
}

int main()
{
FILE *fp;
int accountnum;
int i;
do{
system("cls"); //清屏
puts("********************************************");
puts("* You can choose : *");
puts("* 1 : Insert a new Account *");
puts("* 2 : List all Accounts *");
puts("* 3 : Find a Account *");
puts("* 4 : Delete a Account *");
puts("* 5 : quit *");
puts("********************************************");
printf("Please input your choice:");
scanf("%d",&i);
system("cls"); //清屏
switch(i)
{
case 1:
if(!(fp = fopen("account.txt","a+")))
{
printf("can't open the file account.txt\n");
exit(0);
}
InsertAccount( fp);

printf("press any key to continue.....\n");
getch();
fclose(fp);
break;
case 2:
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
ListAccount(fp);

fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
case 3:
printf("please input the account num:\n");
scanf("%d",&accountnum);
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
if(!SearchAccount(fp,accountnum))
printf("There is not the account:%d\n",accountnum);

fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
case 4:
printf("please input the account num:\n");
scanf("%d",&accountnum);
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
fclose(fp);
if(!(fp = fopen("account.txt","w+")))
{
printf("can't open the file account.txt\n");
exit(0);
}
DelAccount(fp,accountnum);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
default:
break;
}
}while(i != 5);
return 0;
}
賬戶數據文件名已經設定為account.txt,這個文件要和上面這個程序放在同一個文件夾下面,不然就得用絕對路徑(比如"d:\\book\\account.txt"),account內容可以用記事本打開自己改動,然後運行程序後就可以在程序中添加或刪除

❸ C語言程序設計怎麼做

分析題目
設計演算法
設計流程圖(一般報告要求要有, 如果不要求 可以不做。)
實現代碼
調試功能。
寫報告。

❹ C語言程序設計 (學生選修課程設計)

這是我做的,你看是否滿意?可能有點大,但也沒辦法呀,你的題目也比較大,呵呵!所以,如果滿意,多給我追加點分!
#include
"stdio.h"
#include
"stdlib.h"
#include
"string.h"
typedef
struct
course
{
char
number[15],name[25];
int
kind,time,lessontime,practicetime,credit,term;
}type;
FILE
*fp1;
void
overview();
//瀏覽函數,負責瀏覽整個課程信息
void
seek();
//查詢函數,負責查詢課程信息
void
choose_course();//選課函數,負責讓用戶選課
void
out(type
temp);
void
input();
int
main()
{
int
n,i;
if((fp1=fopen("course_information.txt","wb"))==NULL)
{printf("創建文件失敗!\n");exit(0);}
printf("請輸入要存儲的課程數目:\n");
scanf("%d",&n);
printf("開始創建文件,請輸入課程信息:\n\n");
for(i=0;i<n;i++)
{
printf("請輸入第%d門課程的信息:\n",i+1);
input();
printf("\n");
}
printf("如想瀏覽整個課程信息,請輸入1;如想查詢課程信息,請輸入2;
如想進行選課,請輸入3;如想結束選修課系統,請輸入0!\n");
while((scanf("%d",&n))!=EOF)
{
if(n==1)
overview();
if(n==2)
seek();
if(n==3)
choose_course();
if(n==0)
exit(0);
printf("\n\n如想繼續操作,只要按規則輸入你要進行的操作即可!\n規則:如想瀏覽整個課程信息,請輸入1;如想查詢課程信息,請輸入2;如想進行選課,請輸入3!\n");
}
printf("歡迎您使用此程序進行選課,謝謝!\n");
fclose(fp1);
return
0;
}
void
input()
{
course
c_a;
printf("請輸入課程編碼:
");
scanf("%s",c_a.number);
printf("請輸入課程名:
");
scanf("%s",c_a.name);
printf("請輸入課程性質:限選課,請輸入1;選修課,請輸入2;必修課,請輸入3!
");
scanf("%d",&c_a.name);
printf("請輸入課程總學時:
");
scanf("%d",&c_a.time);
printf("請輸入課程授課時間:
");
scanf("%d",&c_a.lessontime);
printf("請輸入課程實驗或實踐時間:
");
scanf("%d",&c_a.practicetime);
printf("請輸入課程學分:
");
scanf("%d",&c_a.credit);
printf("請輸入課程所在的學期,比如第二學期,就輸入2即可。");
scanf("%d",&c_a.term);
fwrite(&c_a,sizeof(struct
course),1,fp1);//將一個結構體元素寫入文件中
}
void
out(type
temp)
{
printf("課程代碼:
%s\n課程名:
%s\n",temp.number,temp.name);
printf("課程名:
%s\n",temp.name);
if(temp.kind==1)
printf("課程性質:
Limited
optional
course\n");
else
if(temp.kind==2)
printf("課程性質:
Optional
course\n");
else
if(temp.kind==3)
printf("課程性質:
Required
Courses\n");
else
printf("該編碼系統不認識,即無對應的課程性質存在!\n");
printf("課程總學時:
%d\n課程授課學時:
%d\n實驗或上機學時:
%d\n學分:
%d\n課程開課學期:
%d\n\n",temp.time,temp.lessontime,temp.practicetime,temp.credit,temp.term);
}
void
overview()
{
rewind(fp1);
course
temp;
printf("整個課程信息如下:\n");
while((fread(&temp,sizeof(type),1,fp1))!=0)
out(temp);
}
void
seek()
{
int
judge,credit=0,kind=0;
char
a='N';
course
temp;
printf("如想按學分查詢,請輸入1;如想按課程性質,請輸入2:\n");
scanf("%d",&judge);
rewind(fp1);
//將文件指針位置置為開頭
if(judge==1)
{
printf("請輸入要查詢的學分:\n");
scanf("%d",&credit);
while((fread(&temp,sizeof(type),1,fp1))!=0)
if(credit==temp.credit)
out(temp);
}
else
if(judge==2)
{
printf("請輸入你要查找課程的性質(限選課,請輸入1;選修課,請輸入2;必修課,請輸入3):");
scanf("%d",&kind);
while((fread(&temp,sizeof(type),1,fp1))!=0)
if(temp.kind==kind)
out(temp);
}
else
printf("不好意思,無此類查詢!\n");
}
void
choose_course()
{
rewind(fp1);
course
temp;
int
judge=1,n=0,time=0,credit=0;
char
choose[20][20];
r1:
printf("請開始填寫課程編號進行選課:\n");
while(judge==1)
{
printf("請輸入你所選課程的標號:
");
scanf("%s",choose[n]);
n++;
printf("如想繼續選課,請輸入1;如想提交,請輸入0!\n");
scanf("%d",&judge);
}
while((fread(&temp,sizeof(type),1,fp1))!=0)
{
for(int
i=0;i<n;i++)
if(strcmp(temp.number,choose[i])==0)
{time=time+temp.time;credit=temp.credit;break;}
}
if(time<270||credit<40)
goto
r1;
printf("你所選的課為:\n");
while((fread(&temp,sizeof(type),1,fp1))!=0)
{
for(int
i=0;i<n;i++)
if(strcmp(temp.number,choose[i])==0)
{out(temp);break;}
}
}

❺ C語言程序設計是什麼

C語言是古老而長青的編程語言,它具備了現代程序設計的基礎要求,它的語法是很多其他編程語言的基礎,在系統程序、嵌入式系統等領域依然是無可替代的編程語言,在各類編程語言排行榜上常年占據前兩名的位置。

程序設計是一門基礎課程。對於計算機相關專業而言,程序設計是專業基礎知識,是進一步學習其他專業知識的第一步階梯;對於非計算機專業而言,程序設計的學習有助於理解計算機的能力所在,理解哪些是計算機擅長解決的問題,怎樣的方式方法是計算機擅長的手段,從而能更好地利用計算機來解決本專業領域內的問題。

❻ C語言程序設計

#include <stdio.h>
#include <string.h>

int main ( )
{
int yanghui[7][10], i, j;
memset (yanghui, 0, sizeof(yanghui));
yanghui[0][0] = 1;
yanghui[1][0] = yanghui[1][1] = 1;
for (i = 2; i < 7; ++i){
yanghui[i][0] = 1;
for (j = 1; j <= i; ++j){
yanghui[i][j] = yanghui[i-1][j] + yanghui[i-1][j-1];
}
}
for (i = 0; i < 7; ++i){
for (j = 0; j <= i; ++j){
printf ("%d ", yanghui[i][j]);
}
printf ("\n");
}
return 0;
}

❼ C語言程序設計。

基本是按照需求來寫的,有BUG的話樓主自己改下哈。

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

/*
輸&#12042;&#12032;個&#12055;六進制數,
返回對應的&#12102;符號&#12055;進制數。
&#12055;六進制數輸&#12042;並保存在&#12032;個字元串,
函數需能對&#12055;六進制數是否正確進
&#12175;判斷,
如「123」有前導空&#12137;字元,算&#12032;個合法的&#12055;六進制數;
「12fg」中含有&#12206;法字元,可以僅轉換「12f」,並輸出警告信息
「h123」為&#12206;法字元串,返回結果為0,並輸出警告信息。
*/

//0error
//1warnning
//2right


intjudeg(char*b)
{
intlength=strlen(b);
intcycle,value;
if(b[0]==''&&b[0]<='f')
{
for(cycle=1;cycle<length;cycle++)
{
if((b[cycle]>='0'&&b[cycle]<='9')||(b[cycle]>='a'&&b[cycle]<='f'))
value=2;
elseif(b[cycle]>'f')
{
b[cycle]='';
value=1;
}
}
}
elseif(b[0]>'f')
value=0;
else
{
for(cycle=0;cycle<length;cycle++)
{
if((b[cycle]>='0'&&b[cycle]<='9')||(b[cycle]>='a'&&b[cycle]<='f'))
value=2;
elseif(b[cycle]>'f')
{
b[cycle]='';
value=1;
}
}
}
returnvalue;
}


intmain(void)
{
chara[100];
intvalue=-1,hex;
printf("HEX:");
scanf("%x",&hex);
sprintf(a,"%x",hex);
printf("getstring=%s,hex=%x ",a,hex);
value=judeg(a);
printf("value=%d ",value);
if(value==0)
printf("Warnning:error! ");
elseif(value==1)
{
printf("Warnning:containsillegalcharacters! ");
printf("string=%s,int=%d ",a,hex);
}
else
{
printf("string=%s,int=%d ",a,hex);
}

return0;


}

❽ c語言程序設計的基本步驟

語言程序開發的步驟
1.
定義程序目標。在開始寫程序之前,應對希望程序要做什麼有一個清晰的想法。考慮程序需要的信息,程序需要進行的計算和操作...
2.
設計程序。在對程序需要完成的事情有一個概念性的認識後,就應該決定程序要如何完成它,用戶界面應該是怎麼樣的,程序應該如何組織...
3.
編寫代碼。在程序有了清晰的設計後,就可以通過編寫代碼來實現它了。也就是說,將設計構思轉變為C語言。一般來說...
4.
編譯源代碼。編譯細節取決於編程環境,編譯器還檢查程序是否為有效的C語言程序。

❾ c語言程序設計

#include<stdio.h>

voidfindMax(inta[3][3]){
intmaxi=0;
intmaxj=0;
intmax=0;
intt;
inti=0;
intj=0;
max=a[0][0];
for(i=0;i<3;i++){
for(j=0;j<3;j++){
if(a[i][j]>=max){
maxi=i;
maxj=j;
max=a[i][j];
}
}
}
t=a[1][1];
a[1][1]=a[maxi][maxj];
a[maxi][maxj]=t;
}

intfindMin(inta[3][3]){
intmini=0;
intminj=0;
intmin=0;
intt;
inti=0;
intj=0;
min=a[0][0];
for(i=0;i<3;i++){
for(j=0;j<3;j++){
if(a[i][j]<=min){
mini=i;
minj=j;
min=a[i][j];
}
}
}
t=a[0][0];
a[0][0]=a[mini][minj];
a[mini][minj]=t;
returnmin;
}

voidfindTheSecMinNum(inta[3][3],intmin){
intnumi=0;
intnumj=0;
intnum=0;
intt;
inti=0;
intj=0;
num=a[0][1];
for(i=0;i<3;i++){
for(j=0;j<3;j++){
if(a[i][j]==min){
numi=i;
numj=j+1;
num=a[i][j+1];
}elseif(a[i][j]>min&&a[i][j]<num){
numi=i;
numj=j;
num=a[i][j];
}
}
}
t=a[2][2];
a[2][2]=a[numi][numj];
a[numi][numj]=t;
}

voidprint(inta[3][3]){
inti=0;
intj=0;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%d,",a[i][j]);
}
printf(" ");
}
}

三個函數,那個找第二個數的程序有點違反編程規范。但是結果倒是沒問題。