资源描述:
《课堂c语言》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、教材P36/******计算圆的面积和周长******/#defineR2.0doublecalcuArea(doubler);doublecalcuCircum(doubler);intmain(){printf("area=%f",calcuArea(R));printf("tcircumference=%f",calcuCircum(R));return0;}doublecalcuArea(doubler){return(pi*r*r);}doublecalcuCircum(double
2、r){return(2.0*pi*r);}教材P37/******计算圆的面积和周长******(规范编程)/#include"stdio.h"#definepi3.141592654#defineR2.0doublecalcuArea(doubler);doublecalcuCircum(doubler);intmain(){printf("area=%f",calcuArea(R));printf("tcircumference=%f",calcuCircum(R));return0;}d
3、oublecalcuArea(doubler){return(pi*r*r);}doublecalcuCircum(doubler){return(2.0*pi*r);}P38/******符号位变为数据的最高位和最高为变为符号位******/#include"stdio.h"intmain(){unsignedshortus1=32767,us2=65535,us;signedshortss=-7;us=ss;printf("(1)ss=%d,us=%d",ss,us);ss=us1;prin
4、tf("(2)us1=%d,ss=%d",us1,ss);ss=us2;printf("(3)us2=%d,ss=%d",us2,ss);return0;}P40数据转换型例子#include"stdio.h"intmain(){doublea=123456.789098765;floatb;longc;shorti,j;b=a;c=a;i=a;j=c;printf("a=%f,b=%f,c=%d,i=%d,j=%d",a,b,c,i,j);return0;}P45长度修正符的用法#in
5、clude"stdio.h"intmain(){printf("%12.5f",123.1234567);printf("%12f",123.1234567);printf("%12.5g",123.1234567);printf("%5.10s%s","abcdefghigklm","a");printf("%12.8d",12345);return0;}P46美国各州面积表#include"stdio.h"intmain(){doublear,por,perc;printf(
6、"%-12s%12s%12s%","State","Area","Forest","Percent");printf("-------------------------------------------------");ar=50750;por=33945;perc=por/ar*100;printf("%-12s%12.0f%12.0f%10.2f%%","Alabama",ar,por,perc);ar=59;por=20;perc==por/ar*100;printf("%-1
7、2s%12s%12s%","Alaska",ar,por,perc);}P512.16#include"stdio.h"intmain(){inta;floatb,c;scanf("%2d%3f%4f",&a,&b,&c);printf("a=%d,b=%f,c=%f",a,b,c);return0;}P74/*三个数最大*/#include"stdio.h"floatmax3(floatx,floaty,floatz){floatmax=x;if(z>y){if(z>x)max=z;}else
8、{if(y>x)max=y;}printf("Themaxis:%f",max);}intmain(){floata,b,c;printf("Input3realnumbers:");scanf("%f%f%f",&a,&b,&c);max3(a,b,c);return0;}P75/*求一元二次方程的解*/#include"stdio.h"#include"math.h"voidsolv_quadr_equa(floata,floatb,floatc){if(a=