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

c語言源代碼

發布時間: 2022-01-19 09:55:50

『壹』 c語言編程,要源代碼

參考程序:
#include <math.h>#include <stdio.h>int main() {
double a, b, c, discriminant, root1, root2, realPart, imagPart;
printf("Enter coefficients a, b and c: ");
scanf("%lf %lf %lf", &a, &b, &c);

discriminant = b * b - 4 * a * c;

// condition for real and different roots
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("root1 = %.2lf and root2 = %.2lf", root1, root2);
}

// condition for real and equal roots
else if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf("root1 = root2 = %.2lf;", root1);
}

// if roots are not real
else {
realPart = -b / (2 * a);
imagPart = sqrt(-discriminant) / (2 * a);
printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart, imagPart, realPart, imagPart);
}

return 0;}

『貳』 有如下C語言源代碼:

從這兩行的運算結果來看!第一個不夠精確,第二個很精確。

B轉換成了long型後,變成可帶小數的了,比如B=40;這里就變成了40.0。
同時後面運算時都將變成lang型去運算,就變成40.0*100.0/4095.0=0.97 約等於1。 如果按照第一種演算法最終的結果是0。顯然第二種要准確的多!

『叄』 求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語言編寫求源代碼

intdata[20]

輸入就不說了我直接弄輸出

intnum=0,max=0,min=100,yx=0,lh=0,hg=0,bhg=0
for(inti=0;i<20;i++){
if(data[i]<0)
break;
num++;
if(data[i]>max)
max=data[i];
if(data[i]<min)
min=data[i];
if(data[i]<60)
bhg++;
elseif(data[i]<80)
hg++;
elseif(data[i]<90)
lh++
elseyx++
}

基本上改下類型,控制下輸出就可以了

『伍』 C語言庫函數源代碼

http://www.gnu.org/software/libc/這里就有所有的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語言源代碼什麼意思

("please enter Month Number(less than 40):"); 雙引號內的為字元串 原樣輸出 please enter Month Number(less than 40):"); 這個都要原樣輸出來的
("%d",&n); %d表示十進制整數 &n 是n所在的內存地址
scanf("%d",&n);就是給 n輸入一個十進制的整數

("\n"); 什麼意思 轉義字元 換行的意思

(" M. 1:%10ld",fn1);為什麼有%10ld, ld(long) 長整形 10表示寬度為10

if(i%4==0)printf("\n");什麼意思 如果 i為4的倍數 換行一次。

QQ 7154920

『捌』 C語言的源代碼是什麼意思啊

C語言源代碼,就是依據C語言規則所寫出的程序代碼,常見的存儲文件擴展名為.c文件和.h文件,分別對應C源文件(source file)和C頭文件(header file)。

C語言是一門編程語言,簡單點說,就是由人類書寫按照一定規范書寫的字元,通過一定手段(編譯鏈接)轉換後,可以讓電腦或者其它電子晶元"讀懂",並按照其要求工作的語言。

在所有的編程語言中,C語言是相對古老而原始的,同時也是在同類語言中更接近硬體,最為高效的編程語言。

(8)c語言源代碼擴展閱讀:

C語言廣泛應用於底層開發。它的設計目標是提供一種能以簡易的方式編譯、處理低級存儲器、產生少量的機器碼以及不需要任何運行環境支持便能運行的編程語言。

它能提供了許多低級處理的功能,可以保持著良好跨平台的特性,以一個標准規格寫出的C語言程序可在許多電腦平台上進行編譯,甚至包含一些嵌入式處理器(單片機或稱MCU)以及超級電腦等作業平台。

其編譯器主要有Clang、GCC、WIN-TC、SUBLIME、MSVC、Turbo C等。

『玖』 c語言源代碼不懂

for(j=2;j<i;j++)
這個循環中如果找到i的因數會break;跳出循環
如果是跳出來的,則j一定會小於i
如果沒有找到i的因數,則循環一定會走完,直到j==i循環結束,這時,說明沒有找到i的因數
所以,判斷i是否等於j就可以知道i是不是素數了

『拾』 C語言源程序

1. 1<=x<10 的語法是錯誤的,不能連續這樣寫,而要寫成邏輯「與」的形式,就是「並且」的意思: if (x>=1 && x<10)

熱點內容
福建社保銀行卡初始密碼是多少 發布:2024-11-15 11:47:40 瀏覽:911
游戲多開用什麼配置 發布:2024-11-15 11:46:51 瀏覽:729
管理java版本 發布:2024-11-15 11:44:03 瀏覽:629
ndk編譯的程序如何執行 發布:2024-11-15 11:43:18 瀏覽:626
輕應用伺服器適合搭建網站嗎 發布:2024-11-15 11:36:08 瀏覽:246
c語言的百分號 發布:2024-11-15 11:34:24 瀏覽:31
一加五安卓8什麼時候推送 發布:2024-11-15 11:19:40 瀏覽:854
暗影騎士擎有哪些配置 發布:2024-11-15 11:13:46 瀏覽:598
方舟主機專用伺服器是什麼意思 發布:2024-11-15 11:12:23 瀏覽:8
創維最早的伺服器是什麼 發布:2024-11-15 11:11:35 瀏覽:864