資源描述:
《C語(yǔ)言編程簡(jiǎn)單示例》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、1.”1”字三角形#includeintmain(){intn,i,j;printf("Enterthesideofthetriangle:");scanf("%d",&n);for(i=1;i<=n;i++){for(j=1;j<=n-i;j++)putchar('');for(j=1;j<=i;j++){putchar('1');if(j!=i)putchar('1');}putchar('');}return0;}2.N的階乘#includeintmain(){inti=1,n;doublej=1;printf("請(qǐng)輸入N:");s
2、canf("%d",&n);while(i<=n){j=i*j;i++;}printf("%lf",j);}3.計(jì)算e的方法(1)#includeintmain(){inti=1,n;doublej=1;printf("請(qǐng)輸入N:");scanf("%d",&n);while(i<=n){j=i*j;i++;}printf("%lf",j);}(2)#includeintmain(){floata,i=1,j=1,e=1;printf("請(qǐng)輸入精度p=");scanf("%f",&a);do{j*=i;e+=(1/j);i++;}wh
3、ile((1/i)>a);printf("e=%.16f",e);return0;}1.九九乘法表#includeintmain(){intm=0,n=0;for(m=1;m<=9;m++){for(n=1;n<=m;n++)printf("%2d*%d=%2d",n,m,n*m);printf("");}return0;}2.判斷月的天數(shù)#includeintmain(){inta,b,c,d,year;printf("請(qǐng)輸入年份:");scanf("%d",&year);printf("請(qǐng)輸入月份:");scanf("%d",&a
4、);if(a<1&&a>13)printf("輸入錯(cuò)誤!!!");else{switch(a){case4:case6:case9:case11:printf("本月有30天");break;case2:if(year%4!=0
5、
6、year%100==0&&year%400!=0)printf("本月有28天");elseprintf("本月有29天");break;default:printf("本月有31天");}}}1.顯示系統(tǒng)時(shí)間#include#include#includeintmain(){str
7、ucttm*date;time_tcurr;curr=time(NULL);date=localtime(&curr);printf("%d/%d/%d%d:%d:%d",date->tm_year+1900,date->tm_mon+1,date->tm_mday,date->tm_hour,date->tm_min,date->tm_sec);getchar();}2.素?cái)?shù)(1)#include#includechara,b,c,d;intt;intxx(intd){for(a='a';a<=d;a++){for(t=1;t<=d-
8、a;t++)printf("");for(b='a';b<=a;b++)printf("%c",b);for(c=a-1;c>='a';c--)printf("%c",c);printf("");}returnd;}intdx(intd){for(a='A';a<=d;a++){for(t=1;t<=d-a;t++)printf("");for(b='A';b<=a;b++)printf("%c",b);for(c=a-1;c>='A';c--)printf("%c",c);printf("");}returnd;}intmain(){while(1){chara,b,
9、c,d,p;intt;title:printf("請(qǐng)輸入一個(gè)字母:");scanf("%c",&d);if(d<='z'&&d>='a')xx(d);elseif(d<='Z'&&d>='A')dx(d);else{printf("輸入錯(cuò)誤!!請(qǐng)按Enter鍵繼續(xù)...");getchar();getchar();system("cls");gototitle;}printf("是否繼續(xù)(y/n)");getchar();scanf("%c",&p);system("cls");if(p