当前位置:首页 » 操作系统 » c程序源码

c程序源码

发布时间: 2022-02-01 14:52:45

Ⅰ c程序源代码

#include<stdio.h>
main()
{
int a[3];
int i,pass,hoad;
printf("shu ru san ge shuzi:");
scanf("%2d%2d%2d",&a[0],&a[1],&a[2]);
for(i=0;i<=2;i++)
printf("%4d",a[i]);
printf("\n");
for(pass=1;pass<=2;pass++)
for(i=0;i<=1;i++)
if(a[i]>a[i+1]){
hoad=a[i];
a[i]=a[i+1];
a[i+1]=hoad; }
for(i=0;i<=2;i++)
printf("%4d",a[i]);
printf("\n");
getch();
}

Ⅱ c程序,求源代码

电费计算的特点是不足一度按照一度计算。

所以 这里要无条件进位。

#include<stdio.h>
intmain()
{
floata,b;
intn;
b=10.4;
n=(int)b;
if(n!=b)n++;
a=n*1.3;
printf("%.1f ",a);
return0;
}

Ⅲ 求c语言编写程序的源代码!

如果是找题目的话,你找ACM的吧,入门的题目还是有不少的,随便把数据结构和算法也学了吧,那些是真的考你的脑袋瓜子。
如果是想写小项目的话,纯C语言的项目不太好看,主要是GUI方面好像少用C语言的,更多是C++、java等语言了。

Ⅳ 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程序代码

亲。。。主函数,呃也就是main函数。。。这么干肯定报错。。。把里面那些乱七八糟的清理掉使用main()或者main(void)这样,或者是标准main函数写法。
这段代码里有简单的分功能的思想,这点很好,但是分的话要详细的分出来。C一般认为是面向过程的编程语言(关于这点,编程思想是一回事,语言是另一回事,java也能面向过程写,C也能面向对象做的)你用文字已经很好地写出了整个过程。所以在编写之初,可以确定,主函数写的是过程。so主函数
void main()
{
PutInNum(...);
SelectWho(...);

PutOutNum(...);
}
主函数的过程。
接下来就是函数实现。
//输入
PutInNum(...)
{
//这里需要对输入的数字进行检测,确保是数字,这里在上面你没表现出来,所以自己想哦,如何确保输入的是数字?还有是不是有更好的方式,比如把计算过程直接输入比如直接输入1+1?而不是选择如何计算这两个数?因为这样更适合使用习惯不是么?
pritnf("pleasle enter the num 1:");scanf("%d",&num1);
pritnf("pleasle enter the num 2:");scanf("%d",&num2);
pritnf("pleasle enter the "+"or"-":",1.加法,2减法);scanf("%d",&q);
}
//选择计算方式
SelectWho(...)

{//使用switch可以保证良好的扩展性,增加乘法与除法仅仅修改这个就可以了
switch()
case "+":sum=num1+num2;//如果是加法,减法类似,本行的“+”需要有你自己的识别方式,可以用数字123之类的,减法的类似。
case ".":.....;
}//这个函数把计算结果return回来,无论加减乘除。
PutOutNum(...)
{
//这里就是printf之类的了;
printf("%d",上个函数传回来的变量);//文字友好之类的自己做了。
}
加上函数声明、传参、相关incode。
根据你写的这个,给你的建议是:首先自己找一下传参部分的资料,自己看一下,C语言的全局变量、局部变量、变量的定义和使用之类的,因为真的是一塌糊涂,所以我采用类似伪代码的方式,没有完整给出来完整的代码,探索的过程才好玩儿嘛。有把功能分开来写的思想很好。

Ⅵ c程序代码

#include <stdio.h>

int a[15]={1,2,3,4,5,6,7,8,9,10,11,13,14,15,16};

int search(int key,int left,int right)
{
int mid;
if(left==right)
{
if(a[left]==key)
return left;
else
return -1;
}
else
{
mid=(left+right)/2;
if(mid==left)
mid++;
if(key<a[mid])
return search(key,left,mid-1);
else
return search(key,mid,right);
}
}

int main()
{
int in;
while(true)
{
printf("请输入查找值:(输入0退出)\n");
scanf("%d",&in);
if(in==0)
break;
else
{
in=search(in,0,14);
if(in==-1)
printf("该数不存在\n");
else
printf("该数的索引值为:%d\n",in);
}
}
return 0;
}

Ⅶ 最简单的C语言代码

最简单的C语言代就是输出“helloWord”,通常是作为初学编程语言时的第一个程序代码。具体代码如下:

#include <stdio.h>

int main(){

printf("Hello, World! ");

return 0;

}

(7)c程序源码扩展阅读:

1、程序的第一行#include <stdio.h>是预处理器指令,告诉 C 编译器在实际编译之前要包含 stdio.h 文件。

2、下一行intmain()是主函数,程序从这里开始执行。

3、下一行printf(...)是C中另一个可用的函数,会在屏幕上显示消息"Hello,World!"。

4、下一行return0;终止main()函数,并返回值0。

Ⅷ C语言,C语言源代码到底是什么意思

现在的教学流程有问题

要是我肯定先拿一个可以正常运行的helloworld来一边改

一边讲解

然后写个猜数字控制台程序

接下来用MFC给他写个界面

让大家知道学习这些算法到底有什么用

再往后,我可能会一直教界面编程

直到你们感觉到自己的算法需要深入学习

然后再回过头去学算法

别用什么垃圾TC了,这都什么年代了

新手建议VC6即可,又可以学算法

也能开发MFC界面程序对电脑配置要求也不搞

甚至绿色精简版就能用

然后写一些游戏相关的工具或者网络相关的工具

不怕不懂,这样至少知道缺什么知识,然后去学

我最讨厌学一大堆,也不知道有什么用的

提不起兴趣,也没有积极主动性

我写的网游服务器在线人数实时显示。。。。

还有游戏辅助没写完 这里不能上图了,要是上那个估计会被删除回答

Ⅸ 要求编写一个程序,我只要源代码,C语言的

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <arpa/inet.h>
int main(int argc, char **argv) {
int sockfd;
struct sockaddr_in sock_hp;
int n, i;
char recvline[1024];
char *msg = "GET index.html HTTP/1.1\r\nHOST: \r\nConnection: Close\r\n\r\n";
char *ip ="180.186.1.105";
// GET /pub/WWW/ HTTP/1.1
// Host: www.w3.org
/*
strcat(header, "GET ");
strcat(header, GET);
strcat(header, " HTTP/1.1\r\n");
strcat(header, "HOST: ");
strcat(header, host);
strcat(header, "\r\nConnection: Close\r\n\r\n");
*/
puts("--MSG:--");
puts(msg);
puts("--MSG END--");

if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
puts("socket Error!\n"), exit(0);
bzero(&sock_hp, sizeof(sock_hp));

sock_hp.sin_port = htons(80);
sock_hp.sin_family = AF_INET;
if (inet_pton(AF_INET,ip, &sock_hp.sin_addr) <= 0)
puts("inet_pton Error!\n"), exit(0);
if (connect(sockfd, (struct sockaddr *) &sock_hp, sizeof(sock_hp)) < 0) {
puts("connect Error!\n");
exit(0);
}

i = strlen(msg);
if (send(sockfd, msg, i, 0) != i)
puts("send Error!\n"), exit(0);

while ((n = recv(sockfd, recvline, 1024, 0)) > 0) {
recvline[n] = 0;
puts(recvline);
}
exit(1);
}

Ⅹ 求简单C语言程序代码!

输入2个正整数m和n,求其最大公约数和最小公倍数

#include

#include

int main()

int m,n,p,q,s,r;

printf("请输入两个正整数;m,n ");

scanf("%d,%d",&m,&n);

#include<stdio.h>

main()

int a,b,t=0;

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

if (a<b)

printf("%d %d %d %d %d",(a+b),(a-b),(a/b),(a*b),(a%b));

}

主要特点

C语言是一种结构化语言,它有着清晰的层次,可按照模块的方式对程序进行编写,十分有利于程序的调试,且c语言的处理和表现能力都非常的强大,依靠非常全面的运算符和多样的数据类型,可以轻易完成各种数据结构的构建,通过指针类型更可对内存直接寻址以及对硬件进行直接操作,因此既能够用于开发系统程序,也可用于开发应用软件。

以上内容参考:网络-c语言

热点内容
跳转页源码 发布:2024-09-17 03:13:05 浏览:543
html文件上传表单 发布:2024-09-17 03:08:02 浏览:784
聊天软件编程 发布:2024-09-17 03:00:07 浏览:726
linuxoracle安装路径 发布:2024-09-17 01:57:29 浏览:688
两个安卓手机照片怎么同步 发布:2024-09-17 01:51:53 浏览:207
cf编译后没有黑框跳出来 发布:2024-09-17 01:46:54 浏览:249
安卓怎么禁用应用读取列表 发布:2024-09-17 01:46:45 浏览:524
win10设密码在哪里 发布:2024-09-17 01:33:32 浏览:662
情逢敌手迅雷下载ftp 发布:2024-09-17 01:32:35 浏览:337
安卓如何让软件按照步骤自动运行 发布:2024-09-17 01:28:27 浏览:197