当前位置:首页 » 编程语言 » 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-12-29 09:57:04 浏览:730
服务密码需要什么证件 发布:2024-12-29 09:42:10 浏览:225
pc辅助存储器构造 发布:2024-12-29 09:24:40 浏览:236
hadooplinux安装 发布:2024-12-29 09:23:20 浏览:824
数控编程思维 发布:2024-12-29 09:21:45 浏览:306
php时间区 发布:2024-12-29 09:20:05 浏览:928
我的世界如何做出一个好的服务器 发布:2024-12-29 09:18:45 浏览:943
哪里买安卓二手机好 发布:2024-12-29 09:06:09 浏览:533
助威战舰如何配置船长 发布:2024-12-29 09:05:37 浏览:736
如何触发安卓小游戏 发布:2024-12-29 09:00:24 浏览:955