當前位置:首頁 » 編程語言 » c語言源程序

c語言源程序

發布時間: 2022-02-10 05:08:34

c語言源程序

for(j=2;j<i;j++) 這個循環中如果找到i的因數會break;跳出循環如果是跳出來的,則j一定會小於i如果沒有找到i的因數,則循環一定會走完,直到j==i

❷ c語言源程序是有什麼組成的

源程序:人類可以識別、修改、編寫的代碼,可以編譯為計算機可執行的2進制代碼。
沒有什麼基本單位:對於C來說,就是 main()函數 和正確的程序

❸ C語言源程序是由什麼構成的

C語言源程序是由:數據類型、常量與變數、數組、指針、字元串、文件輸入/輸出、運算構成。

1、數據類型

C的數據類型包括:整型、字元型、實型或浮點型(單精度和雙精度)、枚舉類型、數組類型、結構體類型、共用體類型、指針類型和空類型。

2、常量與變數

常量其值不可改變,符號常量名通常用大寫。

變數是以某標識符為名字,其值可以改變的量。標識符是以字母或下劃線開頭的一串由字母、數字或下劃線構成的序列,請注意第一個字元必須為字母或下劃線,否則為不合法的變數名。變數在編譯時為其分配相應存儲單元。

3、數組

如果一個變數名後面跟著一個有數字的中括弧,這個聲明就是數組聲明。字元串也是一種數組。它們以ASCII的NULL作為數組的結束。要特別注意的是,方括內的索引值是從0算起的。

4、指針

如果一個變數聲明時在前面使用 * 號,表明這是個指針型變數。換句話說,該變數存儲一個地址,而 *(此處特指單目運算符 * ,下同。C語言中另有 雙目運算符 *) 則是取內容操作符,意思是取這個內存地址里存儲的內容。指針是 C 語言區別於其他同時代高級語言的主要特徵之一。

指針不僅可以是變數的地址,還可以是數組、數組元素、函數的地址。通過指針作為形式參數可以在函數的調用過程得到一個以上的返回值,不同於return(z)這樣的僅能得到一個返回值。

指針是一把雙刃劍,許多操作可以通過指針自然的表達,但是不正確的或者過分的使用指針又會給程序帶來大量潛在的錯誤。

5、字元串

C語言的字元串其實就是以''字元結尾的char型數組,使用字元型並不需要引用庫,但是使用字元串就需要C標准庫裡面的一些用於對字元串進行操作的函數。它們不同於字元數組。使用這些函數需要引用頭文件<string.h>。

6、文件輸入/輸出

在C語言中,輸入和輸出是經由標准庫中的一組函數來實現的。在ANSI C中,這些函數被定義在頭文件<stdio.h>;中。

7、運算

C語言的運算非常靈活,功能十分豐富,運算種類遠多於其它程序設計語言。在表達式方面較其它程序語言更為簡潔,如自加、自減、逗號運算和三目運算使表達式更為簡單,但初學者往往會覺的這種表達式難讀,關鍵原因就是對運算符和運算順序理解不透不全。

當多種不同運算組成一個運算表達式,即一個運算式中出現多種運算符時,運算的優先順序和結合規則顯得十分重要。

在學習中,對此合理進行分類,找出它們與數學中所學到運算之間的不同點之後,記住這些運算也就不困難了,有些運算符在理解後更會牢記心中,將來用起來得心應手,而有些可暫時放棄不記,等用到時再記不遲。

(3)c語言源程序擴展閱讀:

C語言的特有特點:

1、C語言是一個有結構化程序設計、具有變數作用域(variable scope)以及遞歸功能的過程式語言。

2、C語言傳遞參數均是以值傳遞(pass by value),另外也可以傳遞指針(a pointer passed by value)。

3、不同的變數類型可以用結構體(struct)組合在一起。

4、只有32個保留字(reserved keywords),使變數、函數命名有更多彈性。

5、部份的變數類型可以轉換,例如整型和字元型變數。

6、通過指針(pointer),C語言可以容易的對存儲器進行低級控制。

7、預編譯處理(preprocessor)讓C語言的編譯更具有彈性。

❹ C語言源代碼

大體上可以滿足你的要求了,個別細節你再自己看看吧,我困的實在不行了。。
DEV C++ 編譯通過,運行正常 。

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

void practisesys(void);
void testsys(void);
int typechoose(void);
int Addition(int,int);
int Subtraction(int,int);
int Multiplication(int,int);
int Division(int,int);

int main(void)
{
int choose;
printf(" =====================================================================\n\n");
printf("\t\t Welcome to the math study system\n\n");
printf(" =====================================================================\n\n");
printf("\t\t[1].practise\t\t\t[2].test\n");
printf("\nPlease choose one option of the two:");
scanf("%d",&choose);
if(choose == 1)
{
practisesys();
system("cls");
}
else if(choose == 2)
{
testsys();
system("cls");
}
else
{
printf("Input a wrong number,exit...\n");
getch();
return 0;
}
system("PAUSE");
return 0;
}

void practisesys(void)
{
int n1,n2,result,type,input,right,wrong;
right = 0;
wrong = 0;
type = typechoose();
system("cls");
do
{
do
{
srand((unsigned)time(NULL));
n1 = rand()%100;
n2 = rand()%100;
}while(n1<n2);
label1:
if(type == 1)
{
result = Addition(n1,n2);
printf("%d + %d =",n1,n2);
}
else if(type == 2)
{
result = Subtraction(n1,n2);
printf("%d - %d =",n1,n2);
}
else if(type == 3)
{
result = Multiplication(n1,n2);
printf("%d * %d =",n1,n2);
}
else if(type == 4)
{
result = Division(n1,n2);
printf("%d / %d =",n1,n2);
}
else if(type == 5)
{
srand((unsigned)time(NULL));
type = rand()%4+1;
goto label1;
}
scanf("%d",&input);
if(input == result)
{
right++;
printf("you are right!\n");
}
else
{
wrong++;
printf("you are wrong!\n");
}
}while(1);
printf("you anwsered the question rightly for %d .\n",right);
printf("you totally anwsered the question for %d .\n",right+wrong);
printf("your answer's exactitude rateaccuracy rate is %d %%.\n",right/(right+wrong)*100);
printf("Welcome to use the program!\n");
getch();
return;
}
void testsys(void)
{
int n1,n2,result,input,i,right,wrong,times,sum;
right = 0;
wrong = 0;
sum = 0;
system("cls");
printf("please input how many times would you like to test:");
scanf("%d",×);
do
{
srand((unsigned)time(NULL));
n1 = rand() % 100;
n2 = rand() % 100;
i = rand() % 4+1;
if(i == 1)
{
result = Addition(n1,n2);
printf("%d + %d =",n1,n2);
}
else if(i == 2)
{
result = Subtraction(n1,n2);
printf("%d - %d =",n1,n2);
}
else if(i == 3)
{
result = Multiplication(n1,n2);
printf("%d * %d =",n1,n2);
}
else if(i == 4)
{
result = Division(n1,n2);
printf("%d / %d =",n1,n2);
}
scanf("%d",&input);
if(input == result)
{
right++;
printf("you are right!\n");
}
else
{
wrong++;
printf("you are wrong!\n");
}
}while(sum++ <= times);
printf("you anwsered the question rightly for %d .\n",right);
printf("you totally anwsered the question for %d .\n",right+wrong);
printf("your answer's exactitude rateaccuracy rate is %d %%.\n",right/(right+wrong)*100);
printf("you get the score of %d",right*10);
printf("Welcome to use the program!\n");
getch();
return;
}

int typechoose(void)
{
int choose,flag;
do
{
system("cls");
flag = 0;
printf("1.Addition arithmetic\n2.Subtraction arithmetic\n3.Multiplication arithmetic\n4.Division arithmetic\n5.Commixture arithmetic\n");
printf("\nplease input a number that you choose:");
scanf("%d",&choose);
if(choose != 1 && choose != 2 && choose != 3 && choose != 4 && choose != 5)
{
flag = 1;
}
}while(flag);
return choose;
}

int Addition(int n1,int n2)
{
return n1+n2;
}

int Subtraction(int n1,int n2)
{
return n1-n2;
}

int Multiplication(int n1,int n2)
{
return n1*n2;
}

int Division(int n1,int n2)
{
return n1/n2;
}

❺ C語言源程序的文件擴展名為

在Windows平台上,C語言源代碼文件一般擴展名為.c。

在Linux平台上,C語言源代碼文件一般擴展名為.c,預處理操作後的文件名擴展名一般為.i,編譯器生成的匯編代碼一般擴展名為.s,生成的可執行文件一般擴展為.out,它是有匯編器生成的,所以默認gcc生成的程序名為a.out意思即為Assembler output 。

拓展資料

C是一種通用的編程語言,廣泛用於系統軟體與應用軟體的開發。於1969年至1973年間,為了移植與開發UNIX操作系統,由丹尼斯·里奇與肯·湯普遜,以B語言為基礎,在貝爾實驗室設計、開發出來。

C語言具有高效、靈活、功能豐富、表達力強和較高的可移植性等特點,在程序設計中備受青睞,成為最近25年使用最為廣泛的編程語言。目前,C語言編譯器普遍存在於各種不同的操作系統中,例如Microsoft Windows、macOS、Linux、Unix等。C語言的設計影響了眾多後來的編程語言,例如C++、Objective-C、Java、C#等。

二十世紀八十年代,為了避免各開發廠商用的C語言語法產生差異,由美國國家標准局為C語言訂定了一套完整的國際標准語法,稱為ANSI C,作為C語言的標准。二十世紀八十年代至今的有關程序開發工具,一般都支持匹配ANSI C的語法。

❻ 求C語言源程序

用戶文檔:(1)每次輸入一個代號,執行一個操作,執行完後都回到界面,第一次執行操作時要先輸入若干個學升記錄。
(2)輸入時按學號由小到大以「學號,分數,名字」格式,學號在十位內,分數要是整數,名字不能有空格,每輸入一個學生記錄後按一次回車。
(3)加上插入的一共可存放20個學生。即:若一開始輸入5個學生記錄,則最多可插入15個學生記錄。

源程序:
#include<stdio.h>
#include<string.h>
struct student
{long num;
char name[20];
int score;
}stu[20];
int n;int mid; /*保存學生記錄數的全局變數n 與 修改時調用search函數用的全局變數mid*/

input(void) /*輸入*/
{int i;
printf("\n");
printf("How many students' records do you input?\n");
scanf("%d",&n);
printf("Input %d students' records:\n",n);
printf("number,score,name\n");
for(i=0;i<=n-1;i++)scanf("%ld,%d,%s",&stu[i].num,&stu[i].score,stu[i].name);
printf("\n");
printf("the records you input are:\n");
printf("number,score,name\n");
for(i=0;i<=n-1;i++)printf("%ld,%d,%s\n",stu[i].num,stu[i].score,stu[i].name);
printf("\n");
printf("Press any key to continue\n");
getch();
}

show(void) /*當前存放的學生記錄輸出以便核對*/
{int i;
printf("The current records are:\n");
printf("number,score,name\n");
for(i=0;i<=n-1;i++)printf("%ld,%d,%s\n",stu[i].num,stu[i].score,stu[i].name);
printf("\n");
printf("Press any key to continue\n");
getch();
}

search(void) /*查找(二分法)*/
{long a;
int first,last,sign;
printf("\n");
printf("Input the number of the student you want to find:\n");
scanf("%ld",&a);
first=0;last=n-1;mid=(first+last)/2;sign=0; /*first與last是兩端點下標,mid是中點下標,sign是找到與否的標志*/
while((sign==0)&&(first<=last))
{if(stu[mid].num==a)
{printf("The student you want to find is:\n");
printf("number,score,name\n");
printf("%ld,%d,%s\n",stu[mid].num,stu[mid].score,stu[mid].name);sign=1;}
else if(stu[mid].num>a){last=mid-1;mid=(first+last)/2;}
else {first=mid+1;mid=(first+last)/2;}
}
if(sign==0)printf("The student is not in the list.\n");
printf("\n");
printf("Press any key to continue\n");
getch();
}

sort(void) /*按分數排名(選擇法)*/
{struct student stud[10];int i,j,max;long t1;char t2[]="name temporary string";int t3;
for(i=0;i<=n-1;i++)
{stud[i].num=stu[i].num;strcpy(stud[i].name,stu[i].name);stud[i].score=stu[i].score;} /*stu數組的信息傳給stud數組,再對stud排序輸出*/
for(i=0;i<=n-2;i++)
{max=i;
for(j=i+1;j<=n-1;j++)if(stud[j].score>stud[max].score)max=j;
t1=stud[max].num;stud[max].num=stud[i].num;stud[i].num=t1;
strcpy(t2,stud[max].name);strcpy(stud[max].name,stud[i].name);strcpy(stud[i].name,t2);
t3=stud[max].score;stud[max].score=stud[i].score;stud[i].score=t3;
}
printf("\n");
printf("The records sorted by scores:\n");
printf("number,score,name\n");
for(i=0;i<=n-1;i++)printf("%ld,%d,%s\n",stud[i].num,stud[i].score,stud[i].name);
printf("\n");
printf("Press any key to continue\n");
getch();
}

insert(void) /*插入*/
{
long t1;char t2[]="name temporary string";int t3;int i;
printf("\n");
printf("Input the new student's records:\n");
printf("number,score,name\n");
scanf("%ld,%d,%s",&stu[n].num,&stu[n].score,stu[n].name);
for(i=n;i>=1;i--)if(stu[i].num<stu[i-1].num)
{t1=stu[i].num;stu[i].num=stu[i-1].num;stu[i-1].num=t1;
strcpy(t2,stu[i].name);strcpy(stu[i].name,stu[i-1].name);strcpy(stu[i-1].name,t2);
t3=stu[i].score;stu[i].score=stu[i-1].score;stu[i-1].score=t3;
}
else break;
printf("After the insertion:\n");
printf("number,score,name\n");
for(i=0;i<=n;i++)printf("%ld,%d,%s\n",stu[i].num,stu[i].score,stu[i].name);
n++; /*插入後學生級錄數加1*/
printf("\n");
printf("Press any key to continue\n");
getch();
}

change(void) /*修改*/
{int i;
printf("\n");
search();
printf("Now input the new record of the student:\n");
printf("number,score,name\n");
scanf("%ld,%d,%s",&stu[mid].num,&stu[mid].score,stu[mid].name);
printf("Done! Now all the records are:\n");
printf("number,score,name\n");
for(i=0;i<=n-1;i++)printf("%ld,%d,%s\n",stu[i].num,stu[i].score,stu[i].name);

printf("\n");
printf("Press any key to continue\n");
getch();
}

main() /*輸出主界面*/
{int a;
printf("This is a program that can process students' records.\n\n");
printf("******************************************************\n\n");
printf(" 1----------input\n");
printf(" 2----------show the current records\n");
printf(" 3----------search\n");
printf(" 4----------sort by score\n");
printf(" 5----------insert\n");
printf(" 6----------change\n");
printf(" 0----------exit\n\n");
printf("******************************************************\n\n");
printf("input what you want to do : ");
scanf("%d",&a);
if(a==0)printf("Thank you for using this program.Press any key to leave\n");
while(a!=0)
{switch(a)
{case 1:input();break;
case 2:show();break;
case 3:search();break;
case 4:sort();break;
case 5:insert();break;
case 6:change();break;
}
printf("******************************************************\n\n");
printf(" 1----------input\n");
printf(" 2----------show the current records\n");
printf(" 3----------search\n");
printf(" 4----------sort by score\n");
printf(" 5----------insert\n");
printf(" 6----------change\n");
printf(" 0----------exit\n\n");
printf("******************************************************\n\n");
printf("input what you want to do : ");
scanf("%d",&a);
if(a==0){printf("The you for using this program. Press any key to leave\n");break;}
}
getch();
}

測試:1、輸入:101,90,Shengping 2、查詢:104 結果:104,95,Zhuoyan
102,85,Minchao 查詢:109 結果:The student is not in the list.
104,95,Zhuoyan
108,80,Xishan
112,91,Yimin
3、插入:109,92,Zhaojian 4、修改:輸入:108
結果:101,90,Shengping 輸入改的:108,88,Jack
102,85,Minchao 結果:101,90,Shengping
104,95,Zhuoyan 102,85,Minchao
108,80,Xishan 104,95,Zhuoyan
109,92,Zhaojian 108,88,Jack
112,91,Yimin 109,92,Zhaojian
112,91,Yimin

❼ c語言源程序的基本單位是什麼

在C語言中,函數是程序的基本組成單位。
C程序是由函數構成的,函數是C程序的基本組成單位,一個C源程序中僅有一個main()函數,除main函數之外可以有若干個其它的函數,每個函數實現某一特定的操作。因此,函數是C程序的基本單位。

一個函數由兩部分組成:函數的說明部分。包括函數名、函數類型、函數屬性、函數參數(形式參數)名、形式參數類型。

❽ C語言源程序

晨暉C語言學習系統 2.0

可以下個程序學習

http://www.xgdown.com/soft/25897.htm

❾ c語言程序和c語言源程序有區別嗎

沒有區別,都是c程序。不過有可能編譯成庫文件,就看不到函數的具體實現了。總的來說區別不大,c語言程序可讀性和可移植性很強,但要有很深的功底才行。

❿ c語言 源程序是什麼

源程序,就是還沒有經過編譯的你敲上去的程序,void intmain 前邊的是返回值類型,void無返回值,int要返回一個int類型的值用return來返回

熱點內容
內置存儲卡可以拆嗎 發布:2025-05-18 04:16:35 瀏覽:333
編譯原理課時設置 發布:2025-05-18 04:13:28 瀏覽:374
linux中進入ip地址伺服器 發布:2025-05-18 04:11:21 瀏覽:609
java用什麼軟體寫 發布:2025-05-18 03:56:19 瀏覽:29
linux配置vim編譯c 發布:2025-05-18 03:55:07 瀏覽:103
砸百鬼腳本 發布:2025-05-18 03:53:34 瀏覽:939
安卓手機如何拍視頻和蘋果一樣 發布:2025-05-18 03:40:47 瀏覽:736
為什麼安卓手機連不上蘋果7熱點 發布:2025-05-18 03:40:13 瀏覽:800
網卡訪問 發布:2025-05-18 03:35:04 瀏覽:507
接收和發送伺服器地址 發布:2025-05-18 03:33:48 瀏覽:369