C_02

02


接上自加自减

#include <stdio.h>
#include <stdlib.h>
//#include <float.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 i = 5,p;
//	printf("%d",i++);
//	printf("\n%d",i++);
//	printf("\n%d",i++);
//	i = 5;
//	printf("\n %d+%d+%d=",(i++),(i++),(i++));
//	i = 5;
//	p = (i++)+(i++)+(i++);
//	printf("%d",p);

	int i = 5,p;
	printf("%d",++i);
	printf("\n%d",++i);
	printf("\n%d",++i);
	i = 5;
	printf("\n %d+%d+%d=",(++i),(++i),(++i));
	i = 5;
	p = (++i)+(++i)+(++i);
	printf("%d",p);
	
   	return 0;
}



include <stdio.h> 系统头文件;

include "stdio.h" 自己写的头文件;



  • printf()求值顺序,不同的编译系统不一定相同


  • & 是运算符
  • &a 是表达式


格式输入输出

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <float.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,b,c;
	printf("input a,b,c\n");
	scanf("%d%d%d",&a,&b,&c);
	printf("a=%d\tb=%d\tc=%d",a,b,c);
	
	return 0;

}


回车键空格键作为分隔符(最好定义成空格,防止报不必要的错)

“*”符号:该输入项跳过赋值;

宽度:%5d,格式化位5位有效位;

  • %5.2f非法,scanf没有精度控制;(言下之意,printf有精度控制)

长整型长度为10:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <float.h>

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

int main(int argc, char *argv[]) {
	
	long a;
	printf("input a long integer:\t");
	scanf("%ld",&a);
	printf("%ld",a);
	return 0;

}


********************************************
input a long integer:   12345678901
-539222987
*****溢出***********************************


小写换大写

#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[]) {
	
	char a,b,c;
	printf("input your char:\t");
	scanf("%c %c %c",&a,&b,&c);
	printf("%d %d %d\n%c %c %c",a,b,c,a-32,b-32,c-32);
	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;
	long b;
	float f;
	double d;
	char c;
	printf("\nint:%d \nlong:%d \nfloat:%d \ndouble:%d \nchar:%d",sizeof(a),sizeof(b),sizeof(f),sizeof(d),sizeof(c));
	return 0;

}

******************************
int:4
long:4
float:4
double:8
char:1
*****************************


posted @ 2020-03-26 21:39  钱常来  阅读(142)  评论(0)    收藏  举报