『壹』 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;
}