C语言 教程 02

例子  printf输出三角形

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {

    printf("     *\n");	
    printf("    ***\n");	
    printf("   *****\n");	
    printf("  *******\n");	
    printf(" *********\n");	   
    
}

 

例子 printf输出变量

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {

    int iutu;
    int intValue;
    int intCatNo;
    int XueHao;
    int xue_hao;

    int i_5=0;
    int i2=-2;

    int a,b,c;
    int i,j,k;
    int x=3,y=5,z=0;

    int xa=121;
    char cc='t';

    float f=6.2;

    printf("hi,monday!\n");
    printf("%d\n",98);
    printf("%f\n",3.26);
    printf("%c\n",'H');
    printf("%s\n","constant string ,这个中文固定不变");
    
    printf("%d\n",xa);
    printf("%f\n",f);
    printf("%c\n",cc);
 
    printf("%d\n",xa*2);
    printf("%f\n",f+1.6);
    printf("%c\n",cc-3);
    
}

例子 scanf输入数据计算后用printf输出
 

#include "Stdio.h"
#include "Conio.h"

int main()
{
    int a,b,c;
    printf(" Please enter a value: ");
    scanf("%d",&a);
    printf(" Please enter b value: ");
    scanf("%d",&b);
    c=a+b;
    printf("%d\n",c);
    getch();
    return 0;
}

例子 算数运算-四则运算

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {

    int a;
    int b;
    
    a=3;
    b=4;

    printf("%d\n",a+b);
    printf("%d\n",36-19);
    printf("%d\n",a*b);
    printf("%d\n",25/a);
    printf("%d\n",25%a);
    
}

例子 算数运算-自增自减

#include <stdio.h>
#include <stdlib.h>


int main(int argc, char *argv[]) {

    int a;
    int b;
    int c;
    
    a=3;
    b=3;
    c=3;

    printf("%d\n",a++);	
    printf("%d\n",++b);	
    printf("%d\n",c+++c);	
    
    printf("%d\n",a);	
    printf("%d\n",b);	
    printf("%d\n",c);  
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值