1/16 C
2016-01-16 18:49
246 查看
//指针实践 #include <stdio.h> int main(){ int a;int b;int *p1,*p2,*p; //calculate the maxmium of a and b; printf("please insert two integer\n"); scanf("%d %d",&a,&b); p1=&a;p2=&b; if(a<b){ p=p1;p1=p2;p2=p; } printf("a=%d b=%d \n",a,b); printf("max is %d min is %d",*p1,*p2); }
//数值型数据的存储 #include <stdio.h> int main(){ int a,b; a=2147483642; printf("a=%d\n",a); b=a+10; printf("b=%d\n",b); return 0; //b的实际值是-a-2 因为a+b的运算结果超过了int的范围 }
#include <stdio.h> int main() { float a,b,c; a=12345.67890; b=987.65432; c=a+b; printf("%12.5f\n",c); return 0; //double是15位 float7位 }
//项目1 分离个位数用空格分开 #include <stdio.h> int main(){ printf("insert a three-digit number"); int a,a1,a2,a3; scanf("%d",&a); a1=a%10;a=a/10; a2=a%10;a=a/10; a3=a%10; printf("%d %d %d",a1,a2,a3); }
//项目2分离整数和小数部分 #include <stdio.h> int main(){ printf("insert a float,with three digits after point\n"); float a;int b;float c; scanf("%f",&a); b=(int)a; //integer c=a-b; //points int b1,b2,b3,c1,c2,c3; b1=b%10;b/=10;b2=b%10;b/=10;b3=b%10; c1=(int)(c*10);c2=(int)(c*100)%10;c3=(int)(c*1000)%10; printf("%d %d %d %d %d %d",b3,b2,b1,c1,c2,c3); }
//Project 3:Buy roses #include <stdio.h> #define price 5 int main(){ int n;//money printf("Money is\n") ; scanf("%d",&n); int num_rose=(n/5);int addrose20=0;int addrose5=0; if(num_rose>5){ if(num_rose>=20){ addrose20=5*(num_rose/20);// add 5 roses when num is bigger than 20 addrose5=(num_rose%20)/5;//add 1 rose when remain num is bigger than 5 num_rose=num_rose+addrose20+addrose5;//sum them } else{ addrose5=num_rose/5;//add 1 when ... num_rose=num_rose+addrose5; } } printf("Ming can get %d roses\n",num_rose); }
//Project 4 play with numbers #include <stdio.h> #include <math.h> int main(){ printf("insert three doubles\n"); float a,b,c; //不可以是double scanf("%f %f %f",&a,&b,&c); //&a "&" cannot be ignored float sum,average,square_sum,sqrt_sum_of_square; sum=a+b+c; //summary average=(a+b+c)/3.0; square_sum=a*a+b*b+c*c; //calculate a*a+b*b+c*c sqrt_sum_of_square=sqrt(a*a+b*b+c*c); //calculate sqrt() printf("sum is:\n %f \naverage is:\n %f \nsum of square is:\n %f \nsqrt of their square's summary is:\n %f \n",sum,average,square_sum,sqrt_sum_of_square); }
//极坐标转换 将极坐标转换为直角坐标 // #include <stdio.h> #include <math.h> #define pi 3.141592653 int main(){ printf("please insert r theta (double)\n"); double r,theta;//坐标 scanf("%lf %lf",&r,&theta);//load x y double x,y; theta=theta/180.0*pi; //1°=pi/180 x=r*cos(theta); y=r*sin(theta); printf("x=%lf y=%lf\n",x,y); }
相关文章推荐
- C++智能指针auto_ptr和nuique_ptr
- 5.4 heapq--堆队列算法
- 5.4 heapq--堆队列算法
- height: auto; 会使transition失效
- height: auto; 会使transition失效
- Ubuntu安装docker
- Codeforces 282E Sausage Maximization(字典树)
- RMI与Hession使用
- virtual memory exhausted: Cannot allocate memory 解决方法
- 关于判断oracle中变量为空和空字符串
- eval获取使用字符串同名变量
- 你在发表理科学术文章过程中有哪些经验值得借鉴
- Sicily 3836. 计算组合数
- 云计算aws系列:scp上传下载文件
- DNS基本工作原理及正反向解析和主从同步等操作说明
- bzoj2338 数矩形
- POJ1860(Currency Exchange)(Bellman-Ford)
- 大北农董事长夫人莫云为何在美国被逮捕?
- 更新Windows ActiveX,Ios
- iOS--错误集锦--****is missing a [super ViewDidLoad]call