当前位置:首页 » 编程语言 » c语言敲代码

c语言敲代码

发布时间: 2025-09-23 05:55:25

1. 写一个简短的c语言代码

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

#include <stdio.h>

int main(){

printf("Hello, World! ");

return 0;

}

(1)c语言敲代码扩展阅读:

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

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

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

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

2. 求几个比较有趣,简单的C语言源代码 小白自己敲着练一下手感

最简单的模拟计时器:

#include<stdio.h>

#include<conio.h>

#include<windows.h>

int m=0,s=0,ms=0; //m是分 s是秒 ms是毫秒

//以下是5个自编函数

void csh( ); //初始化界面

void yinc(int x,int y); //隐藏光标的函数(y值设为0就会隐藏)

void jishi( ); //计时器运行(每100毫秒变化一次)

void Color (short x, short y); //设定颜色的函数(y设为0就是黑底)

void gtxy (int x, int y); //控制光标位置的函数

int main( ) //主函数

{ csh( );

getch( );

while(1)

{ jishi( );

Sleep(100); //间隔100毫秒

if( kbhit( ) )break; //有键按下就退出循环

}

return 0;

}

void csh( ) //初始化界面

{Color(14,0); //设定淡黄字配黑底

printf(“ 计时器”);

Color(10,0); //设定淡绿字配黑底

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

printf(" │ │");

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

gtxy(10,4); //光标到屏幕第10列4行处输出

Color(7,0); //恢复白字黑底

printf(" 00:00:00 ");

yinc(1,0 ); //隐藏光标(yinc代表隐藏)

return;

}

void jishi( ) //计时器运行

{ms+=1;

if(ms==10){s+=1;ms=0;}

if(s==60){m+=1;s=0;}

gtxy(10,4);

Color(9,0); //设定淡蓝字配黑底

if(m>9) printf(" %d:",m);

else printf(" 0%d:",m);

Color(14,0); //设定淡黄字配黑底

if(s>9) printf("%d:",s);

else printf("0%d:",s);

Color(12,0); //设定淡红字配黑底

printf("0%d",ms);

}

void gtxy (int x, int y) //控制光标位置的函数

{ COORD pos;

pos.X = x;

pos.Y = y;

SetConsoleCursorPosition ( GetStdHandle (STD_OUTPUT_HANDLE), pos );

}

void Color (short ForeColor= 7, short BackGroundColor= 0) //设定颜色的函数

{ HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE );

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

}

void yinc(int x,int y) //隐藏光标的设置(gb代表光标)

{ CONSOLE_CURSOR_INFO gb={x,y}; //x为1-100,y为0就隐藏光标

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &gb);

}

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:710
制作脚本网站 发布:2025-10-20 08:17:34 浏览:972
python中的init方法 发布:2025-10-20 08:17:33 浏览:681
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:833
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:741
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1081
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:312
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:192
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:880
python股票数据获取 发布:2025-10-20 07:39:44 浏览:837