Ch1. Intro to Programming
1-1 Input three integers and output the average number. Keep three decimal places.
#include<stdio.h>
//#include<math.h>
int main()
{
int a, b, c;
scanf("%d%d%d",&a,&b,&c);
printf("%.3f\n", (a+b+c)/3.0);
}
1-2 Input Fahrenheit temperature f, output the centigrade degree c. Keep three decimal places. Hint: c=5(f-21)/9.
#include<stdio.h>
#include<math.h>
int main()
{
float f,c;
scanf("%f",&f);
c=*(f-)/;
printf("%.3f\n", c);
}
1-3 Input a positive integer n, output the value of 1+2+3+...+n.
Hint: Solve the problem rather than exercise programming.
#include<stdio.h>
//#include<math.h>
int main()
{
int n,sum;
sum=;
scanf("%d", &n);
/*if(n == 1)
printf("1\n");
else */
{
for(int i=; i<=n; i++)
sum=sum+i;
printf("%d\n", sum);
} }
1-4 Input positive integer n (n<360), output the sin and cos value of n.
Hint: Use math functions.
#include<stdio.h>
#include<math.h>
int main()
{
int n;
scanf("%d", &n);
printf("%f %f\n", sin(n), cos(n));
}
1-5 A piece of clothes costs 95 yuan, and if the amount adds up to 300 yuan, it will have a 85% discount. Input the sales number of clothes and output the money one should pay (yuan). Keep two places of decimal.
#include<stdio.h>
//#include<math.h>
int main()
{
int n;
float total;
scanf("%d", &n);
total=n*;
if (total<)
printf("%.2f\n", total);
else
printf("%.2f\n", total*0.85);
}
1-6 Input three lengths of a triangle (all possitive integers), and determine whether they can be three sides of a triangle. If so, output yes; otherwise, output not a triangle.
#include<stdio.h>
//#include<math.h>
int main()
{
int a,b,c;
scanf("%d%d%d", &a, &b, &c);
if ((a+b>c) && (a+c>b) && (b+c>c))
printf("yes");
else
printf("not a triangle");
return ;
}
1-7 Input a year and determine if it is a leap year. If yes, output yes; otherwise, output no.
#include<stdio.h>
//#include<math.h>
int main()
{
int n;
scanf("%d", &n);
if ((n% == ) || ((n% == ) && (n% != )))
printf("yes");
else
printf("no");
return ;
}
Q1 What's the minimum and maximum number of int integers? (give accurate number)
#include<stdio.h>
//#include<math.h>
int int_min()
{
int n=, i=;
while(n>=i)
{
n=i;
i--;
}
return n;
}
int int_max()
{
int n=, i=;
while(n <=i)
{
n=i;
i++;
}
return n;
} int main()
{
printf("%d\n", int_min());
printf("%d\n", int_max());
}
Q2 How actuate decimal places can double floats can be? Or, is it a right question?
#include<stdio.h>
//#include<math.h>
int main()
{
double i =1.0, j = 3.0;
printf("%.500f\n", i/j);
return ;
}
Ref. https://www.zhihu.com/question/36662447/answer/68630339
It shows 0.333333333333333310000000000... (sixteen 3s ) so, there are maximum 16 decimal places in a double float. And a double float can not acturately describe decimals.
Q3 What's the minimum and maximum positive integer of double floats? (no need to give accurate numbers)
(I don't know...)
Ref. http://blog.csdn.net/architect19/article/details/8551145
http://www.faceye.net/search/87209.html
Not working through...
Q4 What's the precedence of these logical operators, "&&", "||", and "!" ? How do you interpret a&&b||c ?
"&&" and "||"at the same precedence level, and are operated from left to right.
#include<stdio.h>
//#include<math.h>
int main()
{
int a=, b=,c=;
printf("%d", b&&c||a);
return ;
}
It shows 1.
"!" has higher priority than "&&" and "||" .
#include<stdio.h>
//#include<math.h>
int main()
{
int a=, b=,c=;
printf("%d", !b&&c||a);
return ;
}
It shows 1.
#include<stdio.h>
//#include<math.h>
int main()
{
int a=, b=,c=;
printf("%d", !(b&&c||a));
return ;
}
It shows 0.
Q5 What's the accurate meaning of if(a) if(b) x++; else y++? The else matches which if? Any accturate way to express the match?
The esle matches the second if.
#include<stdio.h>
int main()
{
int a, b,x, y;
if(a){
if (b)
x++;
else
y++;
}
return ;
}
Use braces to enclose a series of codes following if(a).
Ch1. Intro to Programming的更多相关文章
- The Go Programming Language. Notes.
Contents Tutorial Hello, World Command-Line Arguments Finding Duplicate Lines A Web Server Loose End ...
- <转载>国外程序员推荐的免费编程书籍资源
一.George Stocker 提供了一大串,分类如下: How to Design Programs: An Introduction to Computing and Programming 2 ...
- 转:Google技术开发指南:给大学生自学的建议
原文来自于:http://blog.jobbole.com/80621/ 技术开发指南 想要成为成功的软件工程师,必须拥有坚实的计算机科学的基础.本指南针对大学生,给出一条自学途径,让学生以科班和非科 ...
- [转]ORACLE递归查询
转自:http://www.oracle.com/technetwork/cn/articles/hartley-recursive-086819-zhs.html 递归数据库处理,也称为材料清单 或 ...
- [日常] Go语言圣经-匿名函数习题
Go语言圣经-匿名函数1.拥有函数名的函数只能在包级语法块中被声明,通过函数字面量(function literal),我们可绕过这一限制,在任何表达式中表示一个函数值2.通过这种方式定义的函数可以访 ...
- Github上的1000多本免费电子书重磅来袭!
Github上的1000多本免费电子书重磅来袭! 以前 StackOverFlow 也给出了一个免费电子书列表,现在在Github上可以看到时刻保持更新的列表了. 瞥一眼下面的书籍分类目录,你就能 ...
- Google Careers 程序员必修课
quote from : https://www.google.com/about/careers/students/guide-to-technical-development.html Techn ...
- Github 的一个免费编程书籍列表
Index Ada Agda Alef Android APL Arduino ASP.NET MVC Assembly Language Non-X86 AutoHotkey Autotools A ...
- 世界名校网络课程大盘点,美国大学CS专业十三大研究方向,世界50所知名大学提供开放课程
世界名校网络课程大盘点 加州大学伯克利分校http://webcast.berkeley.edu/ 加州大学伯克利分校与斯坦福大学. 麻省理工学院等一同被誉为美国工程科技界的学术 领袖,其常年位居 ...
随机推荐
- phpcms课堂笔记
获取父分类下面的子分类 {loop subcat(77) $k $v}{php $subcatid[] = $k;}{/loop}<?php $subcatid = implode(',', $ ...
- Elasticsearch搜索之most_fields分析
顾名思义,most_field就是匹配词干的字段数越多,分数越高,也可设置权重boost. 下面是简易公式(详细评分算法请参考:http://m.blog.csdn.net/article/detai ...
- 基于 Haproxy 构建负载均衡集群
1.HAPROXY简介 HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种负载均衡解决方案.HAProxy特别适用于那些负载特大的web ...
- 腾讯云无法绑定公网IP问题解释与解决方案。
http://blog.csdn.net/chenggong2dm/article/details/51475222 解释:公网IP并不直接配置在服务器上,而是在服务器外部的路由上,通过某种映射连接. ...
- Oracle数据泵(上)
导出 (以导出表空间为例) 1.给用户创建密码 alter user system identified by 00000000; 2.创建导出目录 create or replace dire ...
- AspNetCore-MVC实战系列(四)之结尾
AspNetCore - MVC实战系列目录 . 爱留图网站诞生 . git源码:https://github.com/shenniubuxing3/LovePicture.Web . AspNetC ...
- 不同浏览器的margin值与padding值
IE-7: 有默认外边距margin样式的元素: dd,menu, ol, ul, blockquote, body, dd, dl, form, h1-6, ul 有默认内边距padding样式的元 ...
- 如何使用angular-ui的弹出框
在开发项目时,我们经常性的会遇到弹出框的需求,例如登陆,注册,添加信息等等....面对这一需求,我们当然也可以使用自己的双手进行编写,如果你时间充足可以试试. 今天我们讲解一下如何在angular框架 ...
- C#集合之字典
字典表示一种复杂的数据结构,这种数据结构允许按照某个键来访问元素.字典也称为映射或散列表. 字典的主要特性是能根据键快速查找值.也可以自由添加和删除元素,这有点像List<T>(http: ...
- hdu 1254 推箱子(搜索)
我写的第一道感觉比较难的搜索 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1254 首先要推箱子的话要满足人能够在箱子旁边,而且人的对面也是可通的. ...