当前位置:首页 » 编程语言 » 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 浏览:104
砸百鬼脚本 发布:2025-05-18 03:53:34 浏览:940
安卓手机如何拍视频和苹果一样 发布: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