Cbasic
guyus
这个作者很懒,什么都没留下…
展开
-
C 语言putchar和getchar()
#include int main(){ int ch; while ((ch=getchar())!=EOF) { putchar(ch); } return 0;}// 函数原型 //int getchar(void);//int putchar(int ch);//注意char型一般默认是0-255所以不能吧ch定义成char型否则有可能接受不到-1,EOF是系统用原创 2013-06-22 23:08:50 · 921 阅读 · 0 评论 -
判断闰年平年
#include int main(){ int year; puts("input a year:"); scanf("%d",&year); while (year!=0) { if((year%4==0&&year%100!=0)||(year%400==0)) { printf("%d is a leap year\n",year); } else原创 2013-06-25 22:27:17 · 490 阅读 · 0 评论 -
变量小结。
空白符:空格符,制表符,换行符变量名命名规则:1:变量名字只能由字母和数字组成且第一个字符必须是字母(下划线也算字符) 2:系统库函数经常使用下划线作第一个变量名字,所以尽量不要使用下划线作第一个元素 变量名区分大小写 标识符: 变量名 ,函数名,宏名,语句标号 浮点型常量自动处理为double型。一个字节大原创 2013-06-25 21:03:22 · 421 阅读 · 0 评论 -
行计数
#include int main(){ int rcount=0; int ch; while ((ch=getchar())!=EOF) { if (ch=='\n') { ++rcount; } } printf("%d",rcount); return 0;}//统计‘\n’的次数等价于统计行数原创 2013-06-24 01:23:56 · 385 阅读 · 0 评论 -
函数计算N的阶乘
#include int Factorial(int n);int main(){ int n; scanf("%d",&n); printf("%d",Factorial(n)); return 0;}int Factorial(int n){ int result,i; result=1; for (i=1;i<=n;i++) { result=result*i原创 2013-06-24 17:52:31 · 999 阅读 · 0 评论 -
用*代替数字
#include #include void HideCiper(char t[],char s[]);int main(){ char s2[81]=""; char t2[81]=""; puts("input ciper"); gets(s2); while (strlen(s2)) { HideCiper(t2,s2); printf("%s\n",t2);转载 2013-06-25 22:43:11 · 759 阅读 · 0 评论 -
将整形数据转换为反转数字字符串输出
#include void ItoaRevers(long l,char str[]);int main(){ long l1; char aChar[81]; int i=0; puts("please input a interger:"); scanf("%ld",&l1);//ld 长整型 while(l1!=0) { ItoaRevers(l1,aChar);转载 2013-06-26 19:10:26 · 551 阅读 · 0 评论 -
register
static 函数内部函数和外部函数当一个源程序由多个源文件组成时,C语言根据函数能否被其它源文件中的函数调用,将函数分为内部函数和外部函数。内部函数(又称静态函数)如果在一个源文件中定义的函数,只能被本文件中的函数调用,而不能被同一程序其它文件中的函数调用,这种函数称为内部函数。定义一个内部函数,只需在函数类型前再加一个“static”关键字即可,如下所示转载 2013-06-27 23:09:16 · 453 阅读 · 0 评论 -
联合
一个联合类型所有成员共享空间联合类型变量长度等于各成员最长的长度每次只能赋一种值,新值覆盖旧值。所以应用于选择。声明格式union 联合类型名{ 成员表}; 联合变量的定义1:先声明后定义union classorofiicetype{ intclass; charoffice[10];};转载 2013-07-02 10:58:41 · 460 阅读 · 0 评论 -
结构
结构:一种构造的数据类型声明结构一般形式:struct 结构类型名{ 成员表};struct StudentType{ intnum; char*name; charsex[3]; floatscore;};结构类型变量的定义1:先声明再定义struct 结构转载 2013-07-02 10:59:17 · 372 阅读 · 0 评论 -
C语言基本数据类型int float double
#include int main(){ int a=10; short b=11; long c=12; float d=13; double e=14; printf("%d\t%d\t%d\t%lf\t%lf",a,b,c,d,e); return 0;}结论:float和double型默认都是输出小数点后六位。原创 2013-06-22 23:00:26 · 969 阅读 · 1 评论 -
小写字母转大写字母
#include #include int ToUpper(int c);int main(){ char str[81]; int i=0; puts("input a string"); while (strcmp(gets(str),"quit")) /* while循环里只要条件不为0,就可以继续循环 一般形式:strcmp(字符串1,字符串2)说明:转载 2013-06-26 19:20:28 · 405 阅读 · 0 评论 -
统计输入最大行,并打印
#include int Getline(char nowline[]);void Strcpy(char to[],char from[]);int main(){ int length,maxlen; char longgest[10000]; char nowline[10000]; maxlen=0; while ((length=Getline(nowline))>0)原创 2013-06-24 22:37:08 · 470 阅读 · 0 评论 -
C语言main函数返回值问题
C语言之Main函数返回值问题分析很多人甚至市面上的一些书籍,都使用了void main( ) ,其实这是错误的。C/C++ 中从来没有定义过void main( )。C++ 之父 Bjarne Stroustrup 在他的主页上的 FAQ 中明确地写着 The definition void main( ) { /* ... */ }is not and neve转载 2013-06-24 18:04:56 · 761 阅读 · 0 评论 -
二分查找
#include #include void insertsort(int a[],int i);void BinarySearch(int x,int f,int l,int a[]);int main(){ int a[100],x; int i=1; printf("输入数据"); while(scanf("%d",&a[i++])!=EOF) { ; } i-=原创 2013-06-26 22:00:56 · 342 阅读 · 0 评论 -
冒泡排序
#include void buble(int a[],int i);int main(){ int a[100],i,j; i=1; while(scanf("%d",&a[i++])!=EOF) { ; } i-=2; buble(a,i); for (j=1;j<=i;j++) { printf("%d\t",a[j]); } return 0;}vo原创 2013-06-26 22:21:38 · 335 阅读 · 0 评论 -
统计键盘输入个数
#include int main(){ intlcount; lcount=0; while(getchar()!=EOF) { lcount++; } printf("%d",lcount); return0;}//回车空格原创 2013-06-24 01:16:35 · 487 阅读 · 0 评论 -
单词计数
#include int main(){ int wcount,ch; wcount=0; while ((ch=getchar())!=EOF) { if (ch==' '||ch=='\n'||ch=='\t') { ++wcount; } } printf("%d",wcount); return 0;}//空格或者‘\n’或者'\t'等价于单词个数原创 2013-06-24 01:32:07 · 400 阅读 · 0 评论 -
键盘输入个数,行,单词计数
#include int main(){ int lcount,rcount,wcount,ch; lcount=rcount=wcount=0; while ((ch=getchar())!=EOF) { lcount++; if (ch=='\n'||ch==' '||ch=='\t') { ++wcount; if (ch=='\n') {原创 2013-06-24 01:42:03 · 586 阅读 · 0 评论 -
计算X的Y次方
#include int Pow(int x,int y);int main(){ int x, y; scanf("%d%d",&x,&y); printf("%d",Pow(x,y)); return 0;}int Pow(int x,int y){ int i,p; p=1; for(i=1;i<=y;i++) { p=p*x; } return p;}原创 2013-06-24 18:18:47 · 1897 阅读 · 0 评论 -
自定义字符串长度计算Strlen()
#include int Strlen(char s[]);int main(){ char cArry[81]; int length=80; while (length>0) { gets(cArry); length=Strlen(cArry); printf("%d\n",length); } return 0;}int Strlen(char s[])原创 2013-06-25 11:47:57 · 697 阅读 · 0 评论 -
Strcat链接俩字符串
#include void StrCat(char target[],const char source[]);int main(){ char cTarget[80]="hello"; char cSource[40]="world"; StrCat(cTarget,cSource); printf("%s\n",cTarget);}void StrCat(char targe转载 2013-06-25 22:53:13 · 371 阅读 · 0 评论 -
typedef
定义新的类型名来代替已有的类型名typedef 原类型名 新类型名;typedef int Countype Countype m 等价于int mtypedef struct{ intnum; char*name; charsex[2]; intage; floatscor转载 2013-07-02 10:59:46 · 380 阅读 · 0 评论