當前位置:首頁 » 編程語言 » abc10C語言

abc10C語言

發布時間: 2022-10-19 04:48:26

c語言編程 從二進制文件c:\abc.dat中讀出10個float型數據存放於數組a中,然後將

c:\abc.dat中的內容為:
10.2
23.0
25.1
14.6
32.6
452.3
12.3
69.3
45.6
123.2

排序後為:
10.2
12.3
14.6
23.0
25.1
32.6
45.6
69.3
123.2
452.3
Press any key to continue

#include <stdio.h>
main()
{
int i,j;
FILE *fp;
float tmp,a[10];
fp = fopen("c:\\abc.dat","r");
printf("c:\\abc.dat中的內容為:\n");
for (i=0;i<10;i++)
{
fscanf(fp,"%f",&a[i]);
printf("%.1f\n",a[i]);
}
printf("\n");
for (i=0;i<10-1;i++)
{
for (j=0;j<10-i-1;j++)
{
if (a[j]>a[j+1])
{
tmp = a[j];
a[j] = a[j+1];
a[j+1] = tmp;
}
}
}
printf("排序後為:\n");
for (i=0;i<10;i++)
{
printf("%.1f\n",a[i]);
}
}

Ⅱ 求解C語言編程: 文本文件abc.txt中有10個整數,編寫程序,在屏幕上顯示這10個數。

//測試可用
#include<stdio.h>
intmain()
{
FILE*fout;
if((fout=fopen("abc.txt","r"))==NULL)
{
printf("Cannotopenthisfile! ");
return0;
}
inttemp;
while(!feof(fout))
{
if(fscanf(fout,"%d",&temp)!=1)
break;
printf("%d",temp);
}
return0;
}
/*把這個c語言文件和abc.txt放在同一文件夾,然後編譯運行,
如果指定路徑請給出路徑;望採納*/

Ⅲ C語言 char str[10] = "ABCABC"; printf("%d\n", strcmp( str, &str[3]));

...這個跟字元串關系不大的。
下面是strcmp的詳細事項。
原型:extern int strcmp(const char *s1,const char * s2);
用法:#include <string.h>
功能:比較字元串s1和s2。
一般形式:strcmp(字元串1,字元串2)
說明:
當s1<s2時,返回值<0
當s1=s2時,返回值=0
當s1>s2時,返回值>0
即:兩個字元串自左向右逐個字元相比(按ASCII值大小相比較),直到出現不同的字元或遇'\0'為止。如:
"A"<"B" "a">"A" "computer">"compare"
是因為strcmp函數的返回值為非0值(一般為1)或0(成功則返回非零值,失敗則為0);此處調用strcmp函數成功就返回了1,所以按%d格式輸出,就為1了。
解釋完畢

Ⅳ 一道C語言題目。用結構體。運行環境VC

#include<iostream>
#include <time.h>
#include <iomanip>
using namespace std;

#define NUM 30
#define NUM_START 20000

char names[NUM][20]={
"abc0","abc1","abc2","abc3",
"abc4","abc5","abc6","abc7",
"abc8","abc9","abc10","abc11",
"abc12","abc13","abc14","abc15",
"abc16","abc17","abc18","abc19",
"abc20","abc21","abc22","abc23",
"abc24","abc25","abc26","abc27",
"abc28","abc29"
};

struct Student
{
int Number;
char Name[20];
float scoChn;
float scoMath;
float scoEng;
};

Student stu[NUM];

void Init(Student*pst)
{
srand(time(NULL));
for(int i=0;i<NUM;i++)
{
pst[i].Number=NUM_START+i;
strcpy(pst[i].Name,names[i]);
pst[i].scoChn=51+rand()%50;
pst[i].scoMath=51+rand()%50;
pst[i].scoEng=51+rand()%50;
}
}

void Show(Student*pst)
{
cout<<setw(8)<<"學號"
<<setw(20)<<"姓名"
<<setw(10)<<"語文成績"
<<setw(10)<<"數學成績"
<<setw(10)<<"英語成績"
<<setw(10)<<"總成績"
<<endl;
for(int i=0;i<NUM;i++)
{
cout<<setw(8)<<pst[i].Number
<<setw(20)<<pst[i].Name
<<setw(10)<<pst[i].scoChn
<<setw(10)<<pst[i].scoMath
<<setw(10)<<pst[i].scoEng
<<setw(10)<<pst[i].scoEng+pst[i].scoChn+pst[i].scoMath
<<endl;
}
}

void ShowAtIndex(Student*pst,int i)
{
if(i==-1)
{
cout<<"查無此人!"<<endl;
return;
}

cout<<setw(8)<<"學號"
<<setw(20)<<"姓名"
<<setw(10)<<"語文成績"
<<setw(10)<<"數學成績"
<<setw(10)<<"英語成績"
<<setw(10)<<"總成績"
<<endl;

cout<<setw(8)<<pst[i].Number
<<setw(20)<<pst[i].Name
<<setw(10)<<pst[i].scoChn
<<setw(10)<<pst[i].scoMath
<<setw(10)<<pst[i].scoEng
<<setw(10)<<pst[i].scoEng+pst[i].scoChn+pst[i].scoMath
<<endl;
}

void Sort(Student*pst)
{
Student tmp;
int imax;
float max;
for(int i=0;i<NUM-1;i++)
{
max=pst[i].scoChn+pst[i].scoMath+pst[i].scoEng;
imax=i;
for(int j=i+1;j<NUM;j++)
{
if(max<pst[j].scoChn+pst[j].scoMath+pst[j].scoEng)
{
max=pst[j].scoChn+pst[j].scoMath+pst[j].scoEng;
imax=j;
}
}
if(imax!=i)
{
tmp.Number=pst[i].Number;
strcpy(tmp.Name,pst[i].Name);
tmp.scoChn=pst[i].scoChn;
tmp.scoMath=pst[i].scoMath;
tmp.scoEng=pst[i].scoEng;

pst[i].Number=pst[imax].Number;
strcpy(pst[i].Name,pst[imax].Name);
pst[i].scoChn=pst[imax].scoChn;
pst[i].scoMath=pst[imax].scoMath;
pst[i].scoEng=pst[imax].scoEng;

pst[imax].Number=tmp.Number;
strcpy(pst[imax].Name,tmp.Name);
pst[imax].scoChn=tmp.scoChn;
pst[imax].scoMath=tmp.scoMath;
pst[imax].scoEng=tmp.scoEng;
}
}
}

int FindByName(Student*pst,char*na)
{
for(int i=0;i<NUM;i++)
{
if(strcmp(pst[i].Name,na)==0)
return i;
}
return -1;
}

void main()
{
char name[20];
Init(stu);
Sort(stu);
Show(stu);
cout<<endl<<"請輸入要查找的學生的名字:";
cin>>name;

int index=FindByName(stu,name);
cout<<"查詢結果:"<<endl;
ShowAtIndex(stu,index);
}

Ⅳ 以下正確的c語言自定義標識符(如變數名)是

正確答案A
C語言自定義標識符要求有字母、數字和下劃線組成,開頭必須是字母或者下劃線
題中B選項有符號「(「和 」)」
C選項是關鍵字
D選項有符號「+」
所以A選項是正確的

Ⅵ C語言:依次輸入10個數,輸出最大數

1、點擊文件、新建。

Ⅶ c語言比較abc大小怎麼做是完整的

//從大到小輸出三個整數

#include<stdio.h>

intmain(){

inta,b,c;

printf("請輸入三個整數(逗號隔開):");

scanf("%d,%d,%d",&a,&b,&c);

if(a>b){

if(b>c)printf("%d%d%d ",a,b,c);

elseif(a>c)printf("%d%d%d ",a,c,b);

elseprintf("%d%d%d ",c,a,b);

}

elseif(c>b)printf("%d%d%d ",c,b,a);

elseif(a>c)printf("%d%d%d ",b,a,c);

elseprintf("%d%d%d ",b,c,a);

return0;

}

Ⅷ C語言,寫函數ABC,要用到主函數中的數組A[],怎麼寫這么函數

主函數這樣寫:
ABC(x);
定義里這樣寫:
int ABC(int x[])
{……}
可以了

Ⅸ C語言中,表達式 abc用邏輯表達式怎麼寫

一般情況下這個是選邏輯表達式的。因為if是邏輯判斷,但如果放在c和C++語言中,所有非零運算結果均識為true,不須強制轉換,所以這里選d是正確的。但是在其他語言中是不正確的。
它主要考查的內容就是,C/CPP中並沒有真正的布爾值,只是將非零數認作false而已。所以你可以理解為if是判斷非零數即可,或者理解為其它。實際上,在C/CPP中的布爾值是用int表示的。
也就是16位進制數表示,並不是單純的一個bit。

Ⅹ c語言賦值問題 ​int a,b,c=10 是abc 同時都賦值為10 還是只是c賦值為10

只有c賦值為10,請採納,謝謝。

熱點內容
隨機啟動腳本 發布:2025-07-05 16:10:30 瀏覽:508
微博資料庫設計 發布:2025-07-05 15:30:55 瀏覽:13
linux485 發布:2025-07-05 14:38:28 瀏覽:295
php用的軟體 發布:2025-07-05 14:06:22 瀏覽:745
沒有許可權訪問計算機 發布:2025-07-05 13:29:11 瀏覽:419
javaweb開發教程視頻教程 發布:2025-07-05 13:24:41 瀏覽:667
康師傅控流腳本破解 發布:2025-07-05 13:17:27 瀏覽:229
java的開發流程 發布:2025-07-05 12:45:11 瀏覽:670
怎麼看內存卡配置 發布:2025-07-05 12:29:19 瀏覽:271
訪問學者英文個人簡歷 發布:2025-07-05 12:29:17 瀏覽:821