當前位置:首頁 » 操作系統 » 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語言

熱點內容
delphi創建資料庫 發布:2024-04-17 06:37:43 瀏覽:62
extendsjava 發布:2024-04-17 06:36:58 瀏覽:594
解壓包修復軟體 發布:2024-04-17 06:35:59 瀏覽:12
贊贊協議腳本 發布:2024-04-17 06:21:02 瀏覽:760
117小游戲伺服器ip 發布:2024-04-17 06:11:37 瀏覽:447
奧迪什麼配置好看 發布:2024-04-17 06:02:28 瀏覽:765
算命網源碼 發布:2024-04-17 05:53:16 瀏覽:296
C語言數組的遍歷 發布:2024-04-17 05:45:18 瀏覽:661
劃分清演算法 發布:2024-04-17 05:44:41 瀏覽:668
bitlocker暫停加密 發布:2024-04-17 05:25:21 瀏覽:543