![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C语言
c语言编程基础笔记
yyhhd55
这个作者很懒,什么都没留下…
展开
-
条件运算
#include<stdio.h>#define fee 45int main(void){ int cup,money,yushu; char stop; char name[30]; char ch; //char num[20]; printf("enter char to start:\n"); stop=getchar(); printf("how much you have:"); while((scanf("%d",&money))==1.原创 2020-10-16 18:26:46 · 151 阅读 · 0 评论 -
条件编译
#include<stdio.h>#define NUM ok//去掉此行则执行else语句main(){ struct stu { int num; char *name; char sex; float score; } *ps; ps=(struct stu*)malloc(sizeof(struct stu)); ps->num=102; ps->name="yyh"; ps->sex='M'; ps->score=62..原创 2020-10-16 18:26:05 · 97 阅读 · 0 评论 -
数值类型大小范围
#include<stdio.h>int main(void){ int x=100; long y=26354736; long int a=67899569; unsigned int z=263547364; long b=45676378889; short c=656; printf("%d,%o,%x\n",x,x,x); printf("%d,%#o,%#x\n",x,x,x); printf("%ld,%ld,%ld\n",y,y+1,y+2); pri.原创 2020-10-16 18:25:34 · 205 阅读 · 0 评论 -
输入字符串到文件
#include<stdio.h>#include<stdlib.h>main(){FILE *fp;charstr[256]/*={"jkldjfkllerkkldflkedfefdsfdsfdsrrerfsdfsdfdfdf}*/;charch;if((fp=fopen("C:\\学习地带\\编程\\输入字符串\\string","at"))==NULL){printf("failure to open\n");getch();ex..原创 2020-10-16 18:24:45 · 222 阅读 · 0 评论 -
枚举
#include<stdio.h>/*main(){ enum weekenday//枚举类型只能是整型; { sun,mon,tue,wed,thu,fri,sat } a,b,c; a=sun; b=mon; c=tue; printf("sun=%d,mon=%d,tue=%d\n",a,b,c); }*//*只能把枚举值赋予枚举变量,不能把元素的数值直接赋予枚举变量。如: a=sum; b=mon; 是正确的。而: a=0; b=.原创 2020-10-16 18:24:11 · 73 阅读 · 0 评论 -
汉诺塔程序
#include<stdio.h>move(int n,int x,int y,int z){ if(n==1) { printf("%c-->%c\n",x,z); } else { move(n-1,x,z,y);//借Z盘到Y盘 move(n-1,y,x,z); printf("%c-->%c\n",x,z); //move(n-1,y,x,z); //printf("%c-->%c\n",x,z); }}main()...原创 2020-10-16 18:23:19 · 304 阅读 · 0 评论 -
分配空间
#includestdio.hmain() { struct stu { int num; char name; char sex; float score; } ps; ps=(struct stu)malloc(sizeof(struct stu));分配一块结构体大小的空间 若分配多块则ps=(struct stu)calloc(n,sizeof(struct stu)) ps-num=102; 或(.原创 2020-10-16 18:22:01 · 251 阅读 · 0 评论 -
文件读取与随机
#include<stdio.h> struct stu { char name[10]; int num; int age; char addr[15]; }boya[2],boyb[2],*pp,*qq; main() { FILE *fp; char ch; int i; pp=boya; qq=boyb; if((fp=fopen("C:\\学习地带\\编程\\多块读取\\stu_list","wb+"))==NUL.原创 2020-10-16 18:19:00 · 75 阅读 · 0 评论 -
递归和迭代的效率比较
#include<stdio.h>unsigned long fanc(int n)//递归调用{ if(n<=0) { return 1; } else { return (n*fanc(n-1)); }}unsigned long factorical(int n)//迭代算法{ int result=1; while(n>0) { result*=n; n-=1; } return result;}main(.原创 2020-10-16 18:17:34 · 791 阅读 · 0 评论 -
C语言心路历程
include<stdio.h>intmain(void){unsigneda,b;intc=678;doubled=789.56;intn;printf("enter a is:");scanf("%d",&a);printf("show %*d\n",a,c);//显示无*对应的数printf("now enter :");scanf("%d,%d",&a,&b);printf("the result i...原创 2020-10-16 18:14:43 · 156 阅读 · 0 评论