博文

银行管理(2005-09-18 11:27:00)

摘要:       #include  <stdio.h>main(){int i,y;float b,l,total;printf("\nPlease input the cash(yuan) and the year(year=1,2,3,5,8).\n");loop: scanf("%f%d",&b,&y);switch(y){case 1:l=0.0063; break;case 2:l=0.0066; break;case 3:l=0.0069; break;case 5:l=0.0075; break;case 8:l=0.0084; break;default:printf("The year is error! Please input the cash and the year.\n ");goto loop;}total=b;for(i=1;i<=y*12;i++)total=total*(1+l);printf("The total is %f yuan .",total);getchar();getchar();}......

阅读全文(4060) | 评论:1

冒泡法(2005-09-18 11:27:00)

摘要:           #include <iostream.h> void BubbleSort(int* pData,int Count){    int iTemp;    for(int i=1;i<Count;i++)    {        for(int j=Count-1;j>=i;j--)        {            if(pData[j]<pData[j-1])            {                iTemp = pData[j-1];                pData[j-1] = pData[j];                pData[j] = iTemp;            }        }    }} void main(){    in......

阅读全文(5629) | 评论:1

图书馆管理系统(2005-09-18 11:26:00)

摘要: #include <stdio.h>#include <stdlib.h>#include <conio.h> struct BOOK { int id,usr[10],total,store,days[10]; char name[31],author[21]; }books[100];/*上面是结构体的定义,用于存放书籍及借书的信息。*/ void page_title(char *menu_item) { clrscr(); printf(">>> 图 书 管 理 系 统 <<<\n\n- %s -\n\n",menu_item); }/*上面是打印页眉的函数,同时通过参数menu_item,可以显示当前的状态。*/ void return_confirm(void) { printf("\n按任意键返回……\n"); getch(); }/*上面是返回前请求确认的函数,以便在返回前观察结果*/ int search_book(void) { int n,i; printf("请输入图书序号:"); scanf("%d",&i); for(n=0;n<100;n++)  {  if(books[n].id==i)   {   printf("书名:%s\n",books[n].name);   printf("作者:%s\n",books[n].author);   printf("存数:%d of ",books[n].store);   printf("%d\n",books[n].total);   return n;   }  } printf("\n输入错误或无效图书序号.\n"); return -1; }/*上面的函数是在数组中找到图书号匹配的记录,显示其信息并返  回......

阅读全文(7026) | 评论:6

学生成绩管理(2005-09-18 11:26:00)

摘要:  #include <stdio.h>#include <stdlib.h>#include <conio.h> int INDEX[32];struct STUDENT { int id,age,chinese,math,english; char name[21]; }students[32]; void page_title(char *menu_item) { clrscr(); printf(">>> 学 生 管 理 系 统 <<<\n\n- %s -\n\n",menu_item); } void return_confirm(void) { printf("\n按任意键返回……\n"); getch(); } void student_new(void) { int n; page_title("录入学生基本信息"); for(n=0;n<32;n++)   if(students[n].id==0) break; printf("学号:"); scanf("%d",&students[n].id); printf("姓名:"); scanf("%s",&students[n].name); printf("年龄:"); scanf("%d",&students[n].age); return_confirm(); } int search_id(void) { int n,i; printf("请输入学生学号:"); scanf("%d",&i); for(n=0;n<32;n++)  {  if(students[n].id==i&&students[n].id!=0)   {   printf("学号:%d\n",students[n].id......

阅读全文(5119) | 评论:5

泊车管理(2005-09-18 11:25:00)

摘要:      #include<stdio.h>#include<conio.h>#include<stdlib.h> int cars[16][3]; void car_park(void) { int n,m,o; for(n=0;n<16;n++) if(cars[n][0]==0) break; if(n==16)   {  printf("\n便道很拥挤.\n");  getch();  return;  } printf("\n泊车-请输入车牌:");  scanf("%d",&o); for(m=0;m<16;m++) if(cars[m][0]==o) break; if(m!=16)  {  printf("\n此车已泊.\n");  getch();  return;    }  cars[n][0]=o; if(n<10)  {  printf("请输入当前时:");  scanf("%d",&cars[n][1]);  printf("请输入当前分:");  scanf("%d",&cars[n][2]);  return;  } else printf("\n请先在便道上等候车位"); getch(); }void car_get() { int n,o,p,q,r; printf("\n取车-请输入车牌:"); scanf("%d",&o); for(n=0;n<16;n++) if(cars[n][0]==o) break; if(n==16)   {  printf("\n没有这个车牌.\n");  getch();  return;  } printf("请输入当前时:......

阅读全文(3434) | 评论:1

C语言中字符串拷贝函数的实例(2005-09-18 11:24:00)

摘要:      #include <string.h> /* strcpy */ void SafeCopy(char *Dest, int DestSize, char *Source); main(){    char Text1[20]="Tracy Sorrell";  /* string buffer */    char Text2[10]="Martin";         /* string buffer */     printf (" Original string contents are: %s\n", Text2);     SafeCopy(Text2, sizeof(Text2), Text1);      printf (" New string contents are: %s\n", Text2);     strcpy(Text2, "Alex");      printf (" Final string contents are: %s\n", Text2); } /****************************************************************/ void SafeCopy(    char     *Dest,                   /* Destination buffer. */    int       DestSize, &......

阅读全文(4920) | 评论:0

C语言中的时间函数及使用实例(2005-09-18 11:24:00)

摘要:    #include <stdio.h>          /* NULL         */#include <time.h>          /* ctime, asctime      */ main(){  time_t now;    /* define 'now'. time_t is probably      * a typedef */             /* Calender time is the number of              * seconds since 1/1/1970    */   now = time((time_t *)NULL);  /* Get the system time and put it         * into 'now' as 'calender time' */   printf("%s", ctime(&now));  /* Format data in 'now'      * NOTE that 'ctime' inserts a      * '\n' */    /*************************......

阅读全文(9233) | 评论:0

C语言中的格式化写入文件函数及使用实例(2005-09-18 11:24:00)

摘要:   #include <stdio.h> main(){   FILE  *Ptr;   char  Line[256];   /* ... Open a file for output. */   Ptr = fopen("/tmp/OutputFile", "w");   while(gets(Line))  /* Get data from stdin */  {    fprintf(Ptr, "%s\n", Line); /* Send data to file.  */  }   fclose(Ptr);}......

阅读全文(3320) | 评论:0

C语言中的打开文件函数及使用实例(2005-09-18 11:23:00)

摘要:       #include <stdio.h> main(){  int c;    /* Character read from the file. */  FILE *ptr;   /* Pointer to the file. FILE is a       structure  defined in <stdio.h> */     /* Open the file - no error checking done */  ptr = fopen("/etc/hosts","r");    /* Read one character at a time, checking        for the End of File. EOF is defined        in <stdio.h>  as -1    */  while ((c = fgetc(ptr)) ! ......

阅读全文(3712) | 评论:1

一个猜数游戏,判断一个人反应快慢(2005-09-18 11:23:00)

摘要:      #include "time.h"#include "stdlib.h"#include "stdio.h"main(){char c;clock_t start,end;time_t a,b;double var;int i,guess;srand(time(NULL));printf("do you want to play it.('y' or 'n') \n");loop:while((c=getchar())=='y'){i=rand()%100;printf("\nplease input number you guess:\n");start=clock();a=time(NULL);scanf("%d",&guess);while(guess!=i){if(guess>i){printf("please input a little smaller.\n");scanf("%d",&guess);}else{printf("please input a little bigger.\n");scanf("%d",&guess);}}end=clock();b=time(NULL);printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));if(var<15)printf("\1\1 You are very clever! \1\1\n\n");getch();   }  }......

阅读全文(4364) | 评论:0