本文目錄一覽:
- 1、請大家幫我寫幾個C語言代碼,完整一點,快,謝謝!最好有注釋
- 2、求用c語言編寫的程序,最好帶着注釋(越詳細越好!!)
- 3、c語言程序,請大佬詳細一點,最好能有注釋orz
- 4、求C語言代碼,最好有注釋。
請大家幫我寫幾個C語言代碼,完整一點,快,謝謝!最好有注釋
#include stdio.h
#include string.h
#include stdlib.h
int main()
{
char str[10];
int i;
while(1)
{
scanf(“%s”,str);
if(!strcmp(str,”exit;”))
{
break;
}
else
{
for(i=0;iatoi(str);++i)
{
putchar(‘A’+i);
}
putchar(‘\n’);
}
}
return 0;
}
#include stdio.h
int main()
{
int score;
char grade;
scanf(“%d”,score);
grade= score=90 ? ‘A’ : ( score=60 ? ‘B’ : ‘C’ );
putchar(grade);
return 0;
}
求用c語言編寫的程序,最好帶着注釋(越詳細越好!!)
#includestdio.h
#includestring.h
#includestdlib.h
#include”conio.h”
#define N 20
struct depositor
{char num[20];br char name[20];br char per[20];br float sec;br float mon;br};
void menu();
int reads(struct depositor dep[N]);
void save(struct depositor dep[N],int n);
void add();
void del();
void change();
void show();
void main()
{
int n;
while(1)
{
menu();
printf(“\n 請輸入您要選擇的操作序號,按回車鍵確認:”);
scanf(“%d”,n);
switch(n)
{
case 1: add();break;
case 2: show();break;
case 3: del();break;
case 4: change();break;
case 5: exit(0);
default: printf(“輸入錯誤,請輸入列表中存在的序號!\n “);
}
}}
void menu()
{
printf(” %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% “);
printf(“\n ************************* 銀行個人賬戶管理系統*************************** “);
printf(“\n 1 儲戶開戶”);
printf(“\n 2 餘額查詢”);
printf(“\n 3 儲戶銷戶”);
printf(“\n 4 密碼修改”);
printf(“\n 5 退出”);
printf(“\n ************************************************************************** “);
printf(“\n %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% “);
}
int reads(struct depositor dep[N]) // 讀取儲戶內容
{
FILE *fp;
int i=0;
if((fp=fopen(“account.dat”,”r”))==NULL)
{
printf(“文件打開失敗!\n”);
return 0;
}
else
{
for(i=0;!feof(fp);i++)
fscanf(fp,”\n%s %s %s %f %f\n”,dep[i].num,dep[i].name,dep[i].per,dep[i].sec,dep[i].mon);
}
fclose(fp);
return i;
}
void save(struct depositor dep[N],int n) // 儲戶保存後信息
{
FILE *fp;
int i=0;
if((fp=fopen(“account.dat”,”w”))==NULL)
{
printf(“文件打開失敗!\n”);
return ;
}
else
{
for(i=0;in;i++)
fprintf(fp,”\n%s %s %s %f %f\n”,dep[i].num,dep[i].name,dep[i].per,dep[i].sec,dep[i].mon );
}
fclose(fp);
}
void add()/*儲戶開戶*/
{
FILE *fp;
struct depositor dep;
if((fp=fopen(“account.dat”,”a”))==NULL) //如果文件已經存在,可以追加儲戶信息
{
if((fp=fopen(“account.dat”,”w”))==NULL) // 文件不存在時,創建新文件,輸入儲戶信息
{
printf(“用戶不存在!\n”);
return ;
}
}
printf(“\n請輸入儲戶帳號,並按回車鍵確認:\n”);
scanf(“%s”,dep.num);
fprintf(fp,”\n%s\n”,dep.num);
printf(“\n請輸入儲戶姓名,並用回車鍵確認: \n”);
scanf(“%s”,dep.name);
fprintf(fp,”\n%s\n”,dep.name);
printf(“\n請輸入儲戶身份證號,並用回車鍵確認: \n”);
scanf(“%s”,dep.per);
fprintf(fp,”\n%s\n”,dep.per);
printf(“\n請輸入儲戶密碼,並用回車鍵確認: \n”);
scanf(“%f”,dep.sec);
fprintf(fp,”\n%f\n”,dep.sec);
printf(“\n請輸入儲戶金額,並按回車鍵確認: \n”);
scanf(“%f”,dep.mon);
fprintf(fp,”\n%f\n”,dep.mon);
if(dep.mon10 )
{ printf(“\n 儲戶金額低於十元,不予開戶 \n”);
return ;
}
printf(“\n **********************開戶成功*************************\n”);
fclose(fp);
}
void show() //餘額查詢
{
struct depositor dep[N];
int i,n ;
char s[20];
float t ;
n=reads(dep);
printf(“\n請用戶輸入賬號,密碼,用空格隔開,按回車鍵確認:\n”);
scanf(“%s %f”,s,t);
for(i=0;in;i++)
if (strcmp(s,dep[i].num)==0 t==dep[i].sec) break;
if (i=n || t!=dep[i].sec)
{
printf(“\n 輸入錯誤 \n”);
return ;
}
else
{ printf(“*********************儲戶的餘額如下**********************\n”);
printf(” 餘額 \n”);
printf(“\n %11.2f \n”, dep[i].mon);
printf(“**********************************************************\n”);
}
}
void del() /*儲戶信息刪除函數*/
{
struct depositor dep[N];
char number[20];
float t;
int n,i,j;
n=reads(dep);
printf(“\n請輸入要刪除儲戶賬號,密碼,用空格隔開,按回車鍵確認:”);
scanf(“%s %f”,number,t);
for(i=0;in;i++)
if(strcmp(number,dep[i].num)==0t==dep[i].sec) break;
if(i=n||t!=dep[i].sec)
{
printf(“沒有找到該儲戶信息!\n”);
return;
}
else
{
for(j=i+1;jn;j++)
dep[j-1]=dep[j];
}
save(dep,n-1);
printf(“銷戶成功!\n”);
}
void change() //儲戶密碼更改
{
struct depositor dep[N];
int n,i;
float t;
char number[20];
printf(“\n請輸入要更改密碼的儲戶賬號,密碼,用空格隔開,按回車鍵確認:”);
scanf(“%s %f”,number,t);
n=reads(dep);
for(i=0;in;i++)
if(strcmp(number,dep[i].num)==0t==dep[i].sec)
break;
if(i=n||t!=dep[i].sec)
{
printf(“無此儲戶信息!”);
return;
}
printf(“\n請輸入更改後密碼,按回車鍵確認:\n”);
scanf(“%f”,dep[i].sec);
save(dep,n);
printf(“\n修改成功\n”);
}
c語言程序,請大佬詳細一點,最好能有注釋orz
#include stdio.h
int main()
{
int Year, WeightClass;
float Weight, Fee;
//可以進行多組測試,直到輸入的Year為負數為止
while (1)
{
printf(“Please input the model year registration :\n”);
scanf_s(“%d”, Year); //輸入Year
if (Year 0)
{
printf(“Test End\n”);
break;
}
printf(“Please input the weight :\n”);
scanf_s(“%f”, Weight); //輸入Weight
if (Year = 1970) //第一個條件,1970年以前的(包括1970)
{
if (Weight 2700) //第二個條件,小於2700磅
{
printf(“\nWeight Class |Fee\n”);
printf(“%-16d|$%-7.2f\n\n”, 1, 16.5);
}
else if (Weight = 2700 Weight = 3800)
{
printf(“\nWeight Class |Fee\n”);
printf(“%-16d|$%-7.2f\n\n”, 2, 25.5);
}
else
{
printf(“\nWeight Class |Fee\n”);
printf(“%-16d|$%-7.2f\n\n”, 3, 46.5);
}
}
else if (Year = 1971 Year = 1979)
{
if (Weight 2700)
{
printf(“\nWeight Class |Fee\n”);
printf(“%-16d|$%-7.2f\n\n”, 4, 27.0);
}
else if (Weight = 2700 Weight = 3800)
{
printf(“\nWeight Class |Fee\n”);
printf(“%-16d|$%-7.2f\n\n”, 5, 30.5);
}
else
{
printf(“\nWeight Class |Fee\n”);
printf(“%-16d|$%-7.2f\n\n”, 6, 52.5);
}
}
else
{
if (Weight 3500)
{
printf(“\nWeight Class |Fee\n”);
printf(“%-16d|$%-7.2f\n\n”, 7, 35.5);
}
else
{
printf(“\nWeight Class |Fee\n”);
printf(“%-16d|$%-7.2f\n\n”, 8, 65.5);
}
}
}
return 0;
}
//測試輸出:
//Please input the model year registration :
//1965
//Please input the weight :
//3500
//
//Weight Class | Fee
//2 | $25.50
//
//Please input the model year registration :
//1975
//Please input the weight :
//2500
//
//Weight Class | Fee
//4 | $27.00
//
//Please input the model year registration :
//1981
//Please input the weight :
//3600
//
//Weight Class | Fee
//8 | $65.50
//
//Please input the model year registration :
求C語言代碼,最好有注釋。
12345678910111213141516171819202122232425262728293031【例】把一個整數按大小順序插入已排好序的數組中。為了把一個數按大小插入已排好序的數組中,應首先確定排序是從大到小還是從小到大進行的。設排序是從大到小進序的,則可把欲插入的數與數組中各數逐個比較,當找到第一個比插入數小的元素i時,該元素之前即為插入位置。然後從數組最後一個元素開始到該元素為止,逐個後移一個單元。最後把插入數賦予元素i即可。如果被插入數比所有的元素值都小則插入最後位置。main(){ int i,j,p,q,s,n,a[11]={127,3,6,28,54,68,87,105,162,18}; for(i=0;i10;i++) { p=i;q=a[i]; for(j=i+1;j10;j++) if(qa[j]) {p=j;q=a[j];} if(p!=i) { s=a[i]; a[i]=a[p]; a[p]=s; } printf(“%d “,a[i]); } printf(“\ninput number:\n”); scanf(“%d”,n); for(i=0;i10;i++) if(na[i]) {for(s=9;s=i;s–) a[s+1]=a[s]; break;} a[i]=n; for(i=0;i=10;i++) printf(“%d “,a[i]); printf(“\n”);} 本程序首先對數組a中的10個數從大到小排序並輸出排序結果。然後輸入要插入的整數n。再用一個for語句把n和數組元素逐個比較,如果發現有na[i]時,則由一個內循環把i以下各元素值順次後移一個單元。後移應從後向前進行(從a[9]開始到a[i]為止)。 後移結束跳出外循環。插入點為i,把n賦予a[i]即可。 如所有的元素均大於被插入數,則並未進行過後移工作。此時i=10,結果是把n賦於a[10]。最後一個循環輸出插入數後的數組各元素值。 程序運行時,輸入數47。從結果中可以看出47已插入到54和 28之間。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/304632.html