例子 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);
}