『壹』 c語言編程代碼

兩種方法我寫在一起,可以獨立拆開。

#include <stdio.h>

void finda1(char a[3][10]);

void finda2(char a[3][10]);

void show(char (*p)[10]);

int main()

{

char a[3][10]={{"gehajl"},{"788a987a7"},{"ccabbbabbb"}};

printf("原數組內容: ");

show(a);

printf(" 1、用數組指針的方法(函數): ");

finda1(a);

printf("執行後: ");

show(a);


printf(" --------------------- ");


char b[3][10]={{"gehajl"},{"788a987a7"},{"ccabbbabbb"}};

printf("原數組內容: ");

show(a);

printf(" 2、用指針數組的方法(函數finda2): ");

finda2(b);

printf("執行後: ");

show(b);

return 0;

}

void finda1(char a[3][10])

{

int i,j;

char (*p)[10]=a;

for(i=0;i<3;i++)

for(j=0;j<10;j++)

if(p[i][j]=='a')

printf("發現:第%d行第%d個元素是『a』,已替換 ",i+1,j+1),p[i][j]='1';

}

void finda2(char a[3][10])

{

int i,j;

char *p[3]={&a[0][0],&a[1][0],&a[2][0]};

for(i=0;i<3;i++)

for(j=0;j<10;j++)

if(p[i][j]=='a')

printf("發現:第%d行第%d個元素是『a』,已替換 ",i+1,j+1),p[i][j]='1';


}

void show(char (*p)[10])

{

int i,j;

for(i=0;i<3;i++,printf(" "))

for(j=0;j<10;j++)

printf("%c ",p[i][j]);

}

『貳』 C語言編程代碼

我寫的是java手上沒有寫c的東西,思路就是把這個式子轉換成一步一步的普通式子就好了,既然你引用了math頭文件,裡面已經支持了各種各樣的計算方法,比如sin(),pow()等,運用這些方法分別計算:
1、計算 con3x + x平方 -1;
2、計算 e的x次方 - 2tanx + 1 取絕對值;
3、第1步與第2步求商;
4、計算 3ysiny + tany;
5、計算 1.5 + y的絕對值;
6、第4步與第5步求商;
7、第3步與第6步求和

『叄』 C語言,求程序代碼

#include<stdio.h>

int main()

{ char s[100],*p,*q;

gets(s);

for(p=q=s;*p;p++)

if(*p>='0'&&*p<='9'||*p>='A'&&*p<='F'||*p>='a'&&*p<='f')

*q++=*p;

*q='';

puts(s);

return 0;

}

『肆』 求助五個C語言程序代碼

第一題:
#include
"stdio.h"
main()
{
int
a,b,c,k;
printf("請鍵入3個整數:");
scanf("%d%d%d",&a,&b,&c);
if(a>b){k=a;a=b;b=k;}
if(a>c){k=a;a=c;c=k;}
if(b>c){k=b;b=c;c=k;}
printf("調整後的a,b,c分別為:%d,%d,%d\n",a,b,c);
}

『伍』 c語言源程序代碼

你可以到「如鵬網」
裡面就是講C語言的
應該對你有用把
裡面有視屏教學

『陸』 求簡單C語言程序代碼!

小游戲2048源碼:

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

#include<time.h>

#include<windows.h>

int jsk( ); //計算空格數

void rsgm( ); //重置游戲

void inkey( ); //按鍵輸入

void left( ); //向左移動

void right( ); //向右移動

void up( ); //向上移動

void down( ); //向下移動

void show( ); //輸出界面

void adnum( ); //添加隨機數

void yes( ); //游戲是否結束(1是0否)

void gtxy(int x, int y); //控制游標位置的函數

int a[4][4]; //存儲16個格子中的數字

int score = 0; //每局得分

int best = 0; //最高得分

int ifnum; //是否需要添加數字(1是0否)

int over; //游戲結束標志(1是0否)

int i,j,k;

int main( )

{ rsgm( ); //重置游戲

inkey( ); //按鍵輸入

return 0;

}

void setColor(unsigned short ForeColor = 7, unsigned short BackGroundColor = 0)

{ HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleTextAttribute(handle, ForeColor + BackGroundColor * 0x10);

} //用於控制字元顏色的函數

void rsgm( ) //重置游戲

{ score = 0; ifnum = 1; over = 0; srand((unsigned)time(0)); //啟動隨機數發生器

int n = rand( ) % 16; //隨機函數產生0-15的數字

for (i = 0; i < 4; i++)

{for (j = 0; j < 4; j++)

{ if (n == 0) { int k = rand( ) % 3; if (k == 0 || k == 1) { a[i][j] = 2; }

else { a[i][j] = 4; } n--; }

else { a[i][j] = 0; n--; }

}

}

adnum( );

system("cls");

CONSOLE_CURSOR_INFO cursor_info={1,0}; //以下兩行是隱藏游標的設置

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);

setColor(14, 0); //設置字體淡紅色,背景為黑色

printf(" 2048小游戲"); setColor(7, 0); //恢復白字黑底

printf(" ┌──────┬──────┬──────┬──────┐");

printf(" │ │ │ │ │");

printf(" ├──────┼──────┼──────┼──────┤");

printf(" │ │ │ │ │");

printf(" ├──────┼──────┼──────┼──────┤");

printf(" │ │ │ │ │");

printf(" ├──────┼──────┼──────┼──────┤");

printf(" │ │ │ │ │");

printf(" └──────┴──────┴──────┴──────┘");

show( );

}

void show( ) //輸出界面

{ for(i=0;i<4;i++)

for(j=0;j<4;j++)

{ gtxy(7*j+9,2*i+4); //gtxy(7*j+9, 2*i+4)是游標到指定位置輸出數字

if(a[i][j]==0){printf(" "); setColor(7, 0); printf("│");}

else if(a[i][j]<10){ if (a[i][j] == 2) {setColor(14, 0); }

else if (a[i][j] == 4) {setColor(13, 0); }

else if (a[i][j] == 8) {setColor(12, 0); }

printf(" %d ", a[i][j]); setColor(7, 0); printf("│");

}

else if (a[i][j] < 100){if (a[i][j] == 16) {setColor(12, 0); }

else if (a[i][j] == 32) {setColor(10, 0); }

else if (a[i][j] == 64) {setColor(2, 0); }

printf(" %d ", a[i][j]); setColor(7, 0); printf("│");

}

else if (a[i][j] < 1000) {if (a[i][j] == 128) {setColor(9, 0); }

else if (a[i][j] == 256) {setColor(1, 0); }

else if (a[i][j] == 512) {setColor(13, 0); }

printf(" %d ", a[i][j]); setColor(7, 0); printf("│");

}

else if (a[i][j] < 10000) {if (a[i][j] == 1024) {setColor(5, 0); }

else {setColor(15, 0); }

printf(" %d ", a[i][j]); setColor(7, 0); printf("│");

}

}

if (jsk( ) == 0)

{ yes( ); if (over) { gtxy(9,12); setColor(10, 0);

printf(" 游戲結束!是否繼續? [ Y/N ]:"); }

}

}

void inkey( ) //按鍵輸入

{ int key;

while (1)

{ key = getch( );

if (over) { if (key == 89|| key == 121) {rsgm( ); continue; }

else if (key == 78|| key == 110) { return; }

else continue; }

ifnum = 0;

if(key==224)key=getch( );

switch (key)

{ case 75: left( ); break;

case 77: right( ); break;

case 72: up( ); break;

case 80: down( );break;

}

if (score > best) { best = score; }

if (ifnum) { adnum( ); show( ); }

}

}

int jsk( ) //計算空格數

{ int n = 0;

for (i = 0; i < 4; i++)

{ for (j = 0; j < 4; j++) { if ( a[i][j] == 0) {n++;} } }

return n;

}

void left( ) //向左移動

{ for (i = 0; i < 4; i++)

{for (j = 1, k = 0; j < 4; j++)

{ if (a[i][j] > 0)

{ if ( a[i][k] == a[i][j])

{ a[i][k] *= 2; k++;

score = score + 2 * a[i][j];

a[i][j] = 0; ifnum = 1; }

else if ( a[i][k] == 0) { a[i][k] = a[i][j]; a[i][j] = 0; ifnum = 1; }

else { a[i][k + 1] = a[i][j]; if ((k + 1) != j) { a[i][j] = 0; ifnum = 1; }

k++; }

}

}

}

}

void right( ) //向右移動

{for (i = 0; i < 4; i++)

{for (j = 2, k = 3; j >= 0; j--)

{if (a[i][j] > 0)

{ if (a[i][k] == a[i][j])

{a[i][k] *= 2; k--; score = score + 2 * a[i][j]; a[i][j] = 0; ifnum = 1; }

else if ( a[i][k] == 0) {a[i][k] = a[i][j]; a[i][j] = 0; ifnum = 1; }

else { a[i][k - 1] = a[i][j]; if ((k - 1) != j) { a[i][j] = 0; ifnum = 1; } k--; }

}

}

}

}

void up( ) //向上移動

{for (i = 0; i < 4; i++)

{for (j = 1, k = 0; j < 4; j++)

{if (a[j][i] > 0)

{if ( a[k][i] == a[j][i]) { a[k][i] *= 2; k++;score = score + 2 * a[j][i];

a[j][i] = 0; ifnum = 1; }

else if ( a[k][i] == 0) { a[k][i] = a[j][i]; a[j][i] = 0; ifnum = 1; }

else { a[k + 1][i] = a[j][i]; if ((k + 1) != j) { a[j][i] = 0; ifnum = 1; }

k++; }

}

}

}

}

void down( ) //向下移動

{ for (i = 0; i < 4; i++)

{for (j = 2, k = 3; j >= 0; j--)

{if (a[j][i] > 0)

{if (a[k][i] == a[j][i])

{a[k][i] *= 2; k--;score = score + 2 * a[j][i]; a[j][i] = 0; ifnum = 1; }

else if (a[k][i] == 0) {a[k][i] = a[j][i]; a[j][i] = 0; ifnum = 1; }

else {a[k - 1][i] = a[j][i];

if ((k - 1) != j) {a[j][i] = 0; ifnum = 1; } k--; }

}

}

}

}

void adnum( ) //添加隨機數

{ srand(time(0)); //啟動隨機數發生器

int n = rand( ) % jsk( );

for (int i = 0; i < 4; i++)

{for (int j = 0; j < 4; j++)

{ if (a[i][j] == 0) { if (n != 0) { n--; }

else {int k = rand() % 3;

if (k == 0 || k == 1) {a[i][j] = 2; return; }

else {a[i][j] = 4; return; } }

}

}

}

}

void yes( ) //游戲是否結束

{ for (int i = 0; i < 4; i++)

{for (int j = 0; j < 3; j++)

{if (a[i][j] == a[i][j + 1] || a[j][i] == a[j + 1][i]) {over = 0; return; }}

}

over = 1;

}

void gtxy(int x, int y) //控制游標位置的函數

{ COORD coord;

coord.X = x;

coord.Y = y;

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}

『柒』 C語言源程序

#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,i,j,k; //定義整形變自量;
printf("Input n:");
scanf("%d",&n); //把你輸的數讀入n中;

if(n==1)
{
printf("A\n"); //如果n=1,輸出A;
}

else
{
k=2*(n-1); //否則, k=2*(n-1);
for(i=0;i<n;i++) //外循環
{
for(j=0;j<k;j++) //內循環;
{
printf(" "); //輸出空格;
}

k-=2; //k=k-2;

for(j=0;j<i;j++)
{
printf("%c ",'A'+j); //輸出『A』+j;j=1時 ,輸出B,用的是ASC碼;
}

for(j=i-2;j>=0;j--)
{
printf("%c ",'A'+j); //同上
}
printf("\n");
}
}

system("pause");
}
懂了嗎??

『捌』 求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語言的源程序

這個是邏輯判斷的典型錯誤
不能這樣判斷
if(a>b>c)

if(a>b
&&
b>c)
這樣
#include
"stdio.h"
int
main
()
{
int
a
,b
,c,Sum,Average
,Proct
,Smallest,
Largest
;
printf("
Input
three
different
integers
:");
scanf("
%d%d%d",&a,&b,&c);
Sum=a+b+c;
Average=(a+b+c)/3
;
Proct
=
a*b*c
;
printf("Sum
is
%d\n",Sum
);
printf
("Average
is
%d\n",Average);
printf
("Proct
is
%d\n",Proct);
if(a>b
&&
b>c)
Largest
=
a,Smallest=c;
if(a>c&&c>b)
Largest
=
a,Smallest=b;
if(b>a&&a>c)
Largest
=
b,Smallest=c;
if(b>c&&c>a)
Largest
=
b,Smallest=a;
if(c>a&&a>b)
Largest
=
c,Smallest=b;
if(c>b&&b>a)
Largest
=
c,Smallest=a;
printf
("Smallest
is
%d\n",Smallest);
printf
("Largest
is
%d\n",
Largest);
getch();
return
0;
}