望谟网
您现在的位置: 首页 > 急救常识

急救常识

好玩的c语言编程代码

清心 2025-05-04 急救常识

在编程的世界里,C语言以其高效和灵活著称,而编写有趣的C语言代码更是让编程学习变得充满乐趣。我将通过一些好玩的C语言编程代码实例,带你探索编程的乐趣。

一、趣味打印图案 1.编写一个C语言程序,使用嵌套循环打印一个心形图案。

include

intmain(){

inti,j

intn=10

/心形大小

for(i=n/2

i--){

/打印下半部分

for(j=i

include

include

intmain(){

intnumer,guess,target

srand(time(NULL))

/初始化随机数生成器

target=rand()%100+1

/生成1到100的随机数

rintf("Guessthenumeretween1and100:\n")

scanf("%d",&

guess)

while(guess!=target){

if(guess

intmain(){

charoerator

doulefirst,second

rintf("Enteranoerator(+,-,,/):")

scanf("%c",&

oerator)

rintf("Entertwooerands:")

scanf("%lf%lf",&

first,&

second)

switch(oerator){

case'+':

rintf("%.1lf+%.1lf=%.1lf",first,second,first+second)

case'-':

rintf("%.1lf-%.1lf=%.1lf",first,second,first-second)

case'':

rintf("%.1lf%.1lf=%.1lf",first,second,firstsecond)

case'/':

if(second!=0.0)

rintf("%.1lf/%.1lf=%.1lf",first,second,first/second)

rintf("Error!Divisionyzero.")

default:

rintf("Error!Invalidoerator.")

return0

通过这些有趣的C语言编程代码,你可以轻松地学习编程的体验到编程带来的乐趣。编程不仅是一门技能,更是一种生活的态度。让我们一起享受编程带来的快乐吧!