随笔分类 -  二级C

摘要:#include <stdio.h>int main(){int i=1,sum=0,s=0;do{sum=i*(i+1)*(i+2);s+=sum;printf("%d*%d*%d+",i,i+1,i+2);i++;}while(i<=7);sum=i*(i+1)*(i+2);s+=sum;printf("%d*%d*%d=%d\n",i,i+1,i+2,s);//getch();return 0;}#include <stdio.h>int main(){ int i,j,k,sum=0,s=0; for (i=1;i& 阅读全文
posted @ 2013-03-12 21:33 王井玉 阅读(234) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <stdlib.h>int main(){int n,m,i,num=0;char *p,*q;q=(char *)malloc(10*sizeof(char));p=(char *)malloc(20*sizeof(char));scanf("%d%d",&n,&m);for (i=m;i<n;i++){sprintf(p,"%d",i);sprintf(q,"%d",m);while(*p!='\0'){if(*p= 阅读全文
posted @ 2013-03-11 21:50 王井玉 阅读(677) 评论(0) 推荐(0)
摘要:#include <stdio.h>int main(){ /*从键盘上输入一些字符,把这些字符送到磁盘上,直到输入#号时*/ FILE *fp; char filename[10],ch; scanf("%s",filename); if((fp=fopen(filename,"w"))==NULL) { printf("can't open the file.\n"); exit(0); } ch=getchar(); ch=getchar(); while(ch!='#') { fputc(c 阅读全文
posted @ 2013-03-07 22:27 王井玉 阅读(240) 评论(0) 推荐(0)
摘要:#include <stdio.h>int main(){ /*判断一个字符串中子串出现的次数.*/ char str1[100],str2[20],*p,*q; int sum=0; printf("please input two strings.\n"); scanf("%s%s",str1,str2); p=str1;q=str2; while(*p!='\0') { if(*p==*q) { while(*p==*q&&*q!='\0') { p++; q++; } } else p+ 阅读全文
posted @ 2013-03-06 22:15 王井玉 阅读(532) 评论(0) 推荐(0)
摘要://fputc.c#include <stdio.h>int main(){ /*int fputc(int ch,FILE *p);送一个字符到一个流中*/char *p="abcdefgh";while(*p!='\0'){fputc(*p,stdout);p++;}printf("\n");return 0;} 阅读全文
posted @ 2013-03-06 21:08 王井玉 阅读(463) 评论(0) 推荐(0)
摘要://strcpy.c#include <stdio.h>#include <windows.h>int main(){/*exterm strcpy(char *dest,char *src);将src字符串中的内容复制到dest所指的字符中.返回指向dest字符串的指针.*/char *d="abcdefgh";char p[20]="";system("cls");strcpy(p,d);printf("%s\n",p);return 0;} 阅读全文
posted @ 2013-03-06 20:35 王井玉 阅读(441) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <windows.h>int main(){/*strncat的用法extern char *strncat(char *dest,char *src,int n);将src所指字符串的n个字符填加到dest所指的字符串尾部*/char d[20]="abcd";char *p="efgh";system("cls");strncat(d,p,4);printf("%s\n",d);return 0;} 阅读全文
posted @ 2013-03-06 19:57 王井玉 阅读(725) 评论(0) 推荐(0)
摘要:#include <windodws.h>system("cls"); 阅读全文
posted @ 2013-03-06 17:43 王井玉 阅读(398) 评论(0) 推荐(0)
摘要:filename 必需。规定要打开的文件或 URL。 mode 必需。规定要求到该文件/流的访问类型。可能的值见下表。 include_path 可选。如果也需要在 include_path 中检索文件的话,可以将该参数设为 1 或 TRUE。 context 可选。规定文件句柄的环境。Context 是可以修改流的行为的一套选项。 "r" 只读方式打开,将文件指针指向文件头。 "r+" 读写方式打开,将文件指针指向文件头。 "w" 写入方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。 "w+& 阅读全文
posted @ 2013-03-05 21:51 王井玉 阅读(217) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <dos.h>int main(){ /*getdate()函数的用法*/ struct date d; getdate(&d); //获取DOS日期 printf("the current year is:%d\n",d.da_year);//cprintf和printf用法是不同的 printf("the current day is:%d\n",d.da_day); printf("the current month is:%d\n",d.da 阅读全文
posted @ 2013-03-05 09:11 王井玉 阅读(1442) 评论(0) 推荐(0)
摘要:#include <conio.h>int main(void){ /*gotoxy()的用法*/ //clrscr(); //清除文本模式的窗口 gotoxy(2,1);//在文本窗口中设置光标用(列,行) cprintf("Hello world");//送格式化输出至屏幕 getch(); return 0;} 阅读全文
posted @ 2013-03-05 07:44 王井玉 阅读(1058) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <conio.h>#include <stdlib.h>#include <time.h>int main(){ /*时间函数4:猜数字游戏*/ int i,guess; char c; double var; time_t a,b; clock_t start,end; srand(time(NULL)); printf("\ndo you want to play a game.('y'or'n')\n"); loop: while((c 阅读全文
posted @ 2013-03-04 20:43 王井玉 阅读(192) 评论(0) 推荐(0)
摘要:/*calculate time*/#include <stdio.h>#include <conio.h>#include <time.h>int main(){ /*时间函数举例3*/ clock_t start,end; int i; double var; // 这是怎么回事啊 start=clock(); for (i=0;i<10000;i++) printf("\1\1\1\1\1\1\1\1\1\1\n"); end=clock(); printf("\1:the different time is %6. 阅读全文
posted @ 2013-03-04 14:51 王井玉 阅读(247) 评论(0) 推荐(0)
摘要:/*calculate time*/#include <stdio.h>#include <conio.h>#include <time.h>int main(){ /*时间函数举例2 在vc 和win-tc 中结果不同*/ time_t start,end; int i; start=time(NULL); for (i=0;i<30000;i++) printf("\1\1\1\1\1\1\1\1\1\1\n"); end=time(NULL); printf("\1:the different time is %6. 阅读全文
posted @ 2013-03-04 14:39 王井玉 阅读(140) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <conio.h>#include <time.h>int main(){ /*时间函数举1*/ time_t lt; //define a longint time available lt=time(NULL); //system time and date printf(ctime(&lt)); //english format output printf(asctime(localtime(&lt)));//tranfer to tm printf(asctime(gmtime(& 阅读全文
posted @ 2013-03-04 14:14 王井玉 阅读(219) 评论(0) 推荐(0)
摘要:#include <stdio.h>int main(){ /*打印楼梯同时在楼梯上方打印出两个笑脸*/ int i,j; printf("\1\1\n"); for (i=1;i<11;i++) { for (j=1;j<=i;j++) printf("%c%c",219,219); printf("\n"); } getch(); return 0;} 阅读全文
posted @ 2013-03-04 13:30 王井玉 阅读(824) 评论(0) 推荐(0)
摘要:#include <stdio.h>int main(){ /*打印出国际象棋棋盘*/ int i,j; for (i=0;i<8;i++) { for (j=0;j<8;j++) { if ((i+j)%2==0) printf("%c",219); else printf(" "); } printf("\n"); } getch(); return 0;} 阅读全文
posted @ 2013-03-04 13:21 王井玉 阅读(256) 评论(0) 推荐(0)
摘要:#include <stdio.h>int main(){ /*打印9*9乘法口决,i控制行,j控制列*/ int i,j,result; for (i=1;i<10;i++) { for (j=1;j<=i;j++) { result=i*j; printf("%d*%d=%-3d ",j,i,result); } printf("\n"); } getch(); return 0;} 阅读全文
posted @ 2013-03-04 12:33 王井玉 阅读(218) 评论(0) 推荐(0)
摘要:#include <stdio.h>int main(){ /*很漂亮的案,运行下试试,very beautiful*/ char a=176,b=219; printf("%c%c%c%c%c\n",b,a,a,a,b); printf("%c%c%c%c%c\n",a,b,a,b,a); printf("%c%c%c%c%c\n",a,a,b,a,a); printf("%c%c%c%c%c\n",a,b,a,b,a); printf("%c%c%c%c%c\n",b,a,a,a 阅读全文
posted @ 2013-03-04 12:24 王井玉 阅读(206) 评论(0) 推荐(0)
摘要:#include <stdio.h>int main(){ /*用*号输出字母C的图案*/ printf("hello C-world\n"); printf(" ****\n"); printf(" **\n"); printf(" **\n"); printf(" ****\n"); getch(); return 0;} 阅读全文
posted @ 2013-03-04 12:09 王井玉 阅读(939) 评论(0) 推荐(0)