|
题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
1.程序分析:利用while语句,条件为输入的字符不为'n'.
2.程序源代码:
#include "stdio.h"
#include "conio.h"
main()
{
char c;
int letters=0,space=0,digit=0,others=0;
printf("please input some charactersn");
while((c=getchar())!='n')
{
if(c>='a'&&c='A'&&c='0'&&ci)
{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 secondsn",var=(double)(end-start)/18.2);
printf("1: it took you %6.3f secondsnn",difftime(b,a));
if(var<15)
printf("11 You are very clever! 11nn");
else if(var<25)
printf("11 you are normal! 11nn");
else
printf("11 you are stupid! 11nn");
printf("11 Congradulations 11nn");
printf("The number you guess is %d",i);
}
printf("ndo you want to try it again?("yy".or."n")n");
if((c=getch())=='y')
goto loop;
}
题目:从键盘输入一些字符,逐个把它们送到磁盘上去,直到输入一个#为止。
1.程序分析:
2.程序源代码:
#include "stdio.h"
main()
{ FILE *fp;
char ch,filename[10];
scanf("%s",filename);
if((fp=fopen(filename,"w"))==NULL)
{printf("cannot open filen");
exit(0);}
ch=getchar();
ch=getchar();
while(ch!='#')
{fputc(ch,fp);putchar(ch);
ch=getchar();
}
fclose(fp);
}
|