c语言复习笔记1

C语言复习笔记1

依据《c语言程序设计》(郑关胜 李含光)

程序的基本结构

#include <stdio.h>
int product(int ,int);
int main(void){
    int x,y,s;
    scanf("%d %d",&x,&y);
    s=product(x,y);
    printf("the mul is:%d\n",s);
    return 0;
}
int product(int a,int b){
    int mul;
    mul=a*b;
    return mul;
}

简单的程序

  • 符号常量的使用
#define PRICE 30
#include <stdio.h>
int main(){
    int num,total;
    num=10;
    total=num*PRICE;
    printf("total=%d\n",total);
    return 0;
} 
  • 前置和后置运算
#include<stdio.h>
int main(){
    int i,j,m,n;
    i=8;
    j=10;
    m=++i;
    n=j++;
    printf("%d %d %d %d\n",i,j,m,n);
    return 0;
}
  • 字符变量的用法
 #include<stdio.h>
int main(){
    char c1='a' ,c2='b';
    c1=c1-('a'-'A');
    c2=c2-('a'-'A');
    printf("%c %c\n",c1,c2);
    return 0;
} 
  • 条件运算符
#include<stdio.h>
int main(){
    int x,y;
    scanf("%d",&x);
    y=x<0?1:x>0?-1:0;
    printf("%d\n",y);
}
  • getchar()函数的应用
#include<stdio.h>
int main(){
    char ch;
    ch=getchar();
    putchar(ch);
    printf("%d\n",ch);
    return 0;
} 
  • putchar()函数的应用
#include<stdio.h>
int main(){
    char c;
    c='B';
    putchar(c);
    putchar('\x42');
    putchar(0x42);
    return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值