×

c语言100经典实例编程

c语言100经典实例编程(c语言实用程序设计100例)

hacker hacker 发表于2022-07-11 05:29:18 浏览19 评论5

5人参与发表评论

本文目录一览:

求C语言编程实例100行以上,要有文字大概解释一下

#include stdio.h

main(int a,char **date)

{

int year=0,month=0,day=0,week;

int d,i,dm,dy,m2;

char WEEK[9];

if (a==1)

{

printf ("\n ERROR! you forgot to enter the date you want to view\n");

exit (0);

}

i=0; d=-1;

while (date[1][i])/*遍历传入的参数日期,计算出year,month,day*/

{

if ((date[1][i]=='/'||date[1][i]=='.')d==-1) { d=0; i++; continue; }

if ((date[1][i]=='/'||date[1][i]=='.')d==0) { d=1; i++; continue; }

if (d==-1) year=year*10+(date[1][i]-'0');

if (d==0) month=month*10+(date[1][i]-'0');

if (d==1) day=day*10+(date[1][i]-'0');

i++;

}

if (month1||month12)/*若月份传入错误数字*/

{

printf ("\n ERROR! the entered MONTH is invalid\n");

exit (0);

}

if (year==2000)

{

dy=0; /*年引起的星期差为0个*/

m2=1; /*2月引起的星期差为1个*/

goto la_100;

}

if (year2000)

d=(year-1-2000)/4-(year-1-2000)/100+(year-1-2000)/400+1;

else

d=(year-2000)/4-(year-2000)/100+(year-2000)/400;

dy=(year-2000)+d; /*** 该年 1月1号 到2000年1月1号的 " 星期差 " ***/

if((year%4==0year%100!=0)||(year%100==0year%400==0))

m2=1;

else

m2=0; /*** 该年是否润 ***/

la_100: /**** la_100 ****/

/*** 该月以前的月所引起的 " 星期差 " ***/

switch (month)

{

case 1: dm=0; month=31; break; /*** month 在此存放该月天数 ***/

case 2: dm=3; month=d==1? 29:28; break;

case 3: dm=3+m2; month=31; break;

case 4: dm=6+m2; month=30; break;

case 5: dm=1+m2; month=31; break;

case 6: dm=4+m2; month=30; break;

case 7: dm=6+m2; month=31; break;

case 8: dm=2+m2; month=31; break;

case 9: dm=5+m2; month=30; break;

case 10: dm=m2; month=31; break;

case 11: dm=3+m2; month=30; break;

case 12: dm=5+m2; month=31; break;

}

if (day0||daymonth)

{

printf ("\n ERROR! the entered DAY is invalid\n");

exit (0);

}

week=(dy+dm+day-1+6)%7;

if(week0)

week+=7;

if (day0) /*** 判定查看类型 ***/

{

switch (week)

{

case 0: strcpy (WEEK,"SUNDAY"); break;

case 1: strcpy (WEEK,"MONDAY"); break;

case 2: strcpy (WEEK,"TUESDAY"); break;

case 3: strcpy (WEEK,"WEDNESDAY"); break;

case 4: strcpy (WEEK,"THURSDAY"); break;

case 5: strcpy (WEEK,"FRIDAY"); break;

case 6: strcpy (WEEK,"SATURDAY"); break;

}

printf ("\n this day is %s \( %d \)\n\n OK!\n",WEEK,week);

}

else

{

week=++week%7;

printf ("\n the calender of this month as following\n");

printf ("\n *********************************\n");

printf (" SUN MON TUE WEN THU FRI STA\n");

for (i=0;iweek;i++)

printf (" ");

for (i=1;i=month;i++)

{

printf (" %2d ",i);

week++;

if (week%7==0i!=month)

printf ("\n");

}

printf ("\n *********************************\n");

printf ("\n OK!\n");

}

}

这是一个万年历的小程序,效率不怎么高,不过涉及到很多基础知识,可以读读

C语言的经典编程例子

//最经典的当然是HelloWorld了。 

#include "stdio.h"

int main(void)

{

   printf("HelloWorld!\r\n");

}

经典C语言程序例子

题目01:在一个已知的字符串中查找最长单词,假定字符串中只含字母和空格,空格用来分隔不同的单词。

直接编译,程序执行结果如下图所示:

题目02:编写一个int string_len(char *s),返回字符串s的字符长度(不包括\0)。

直接编译,程序执行结果如下图所示:

扩展资料:

C语言是一门通用计算机编程语言,应用广泛。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。

尽管C语言提供了许多低级处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程序可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。

c语言编程实例100题

这里非常不错,不但有经典的100例,还有许多实用的例子,强烈推荐!!

群贤毕至

访客
只影扶弦 只影扶弦2022-07-11 17:04:12 | 回复 ender of this month as following\n"); printf ("\n *********************************\n"); printf (" SUN MON TUE WEN TH
笙沉氿雾 笙沉氿雾2022-07-11 08:59:13 | 回复 d ",i); week++; if (week%7==0i!=month) printf ("\n"); } printf ("\n ******************************
鸽吻娇痞 鸽吻娇痞2022-07-11 10:32:15 | 回复 ; } week=(dy+dm+day-1+6)%7; if(week0) week+=7; if (day0) /*** 判定查看类型 ***/ {
怎忘双笙 怎忘双笙2022-07-11 08:53:41 | 回复 DAY is invalid\n"); exit (0); } week=(dy+dm+day-1+6)%7; if(week0) week+=7; if (day0) /*** 判定查看类型 ***/ {
冢渊宠臣 冢渊宠臣2022-07-11 05:30:22 | 回复 dm=5+m2; month=31; break; } if (day0||daymonth) { printf ("\n ERROR! the entered DAY is invalid\n"); exit (0); } w