B. 嘉娃的难题
问题描述
嘉娃的家庭作业里有很多数列填空练习题。填空练习题的要求是:已知数列的前四
项,填出第五项。因为已经知道这些数列只可能是等差或者等比数列,所以他决定写一
个程序来完成这些练习。
输入格式
第一行是数列的数目 T (0 ≤ T ≤ 40)。接下来 T 行每行均包含四个整数,表示一个
数列的前四项。数列的前五项均为绝对值不大于 109 的自然数,等比数列的比值也是自
然数。
输出格式
对输入的每个数列,输出它的前五项,每一行的末尾没有多余空格。
样例输入
2
-1 -2 -3 -4
1 2 4 8
样例输出
-1 -2 -3 -4 -5
1 2 4 8 16
#include<cstdio>
int main(){
int i,j;
int n;
double a[5];
scanf("%d",&n);
for(i=0;i<n;i++){
for(j=0;j<5;j++){
a[j]=0;
}
for(j=0;j<4;j++){
scanf("%lf",&(a[j]));
}
if((a[3]+a[1]==2*a[2])&&(a[2]+a[0]==2*a[1])){
a[4]=a[3]*2-a[2];
}else if((a[3]*a[1]==a[2]*a[2])&&(a[2]*a[0]==a[1]*a[1])){
a[4]=a[3]*a[3]/a[2];
}
for(j=0;j<4;j++){
printf("%d ",(int)a[j]);
}
printf("%d\n",(int)a[4]);
}
return 0;
}
分享到:
相关推荐
Understanding Automotive Electronics 8th Appendix B - Discrete Time Systems Theory
Biomedical Image Registration 2018 8th International Workshop, WBIR 2018 Leiden, The Netherlands, June 28–29, 2018 Proceedings
此文档为原书的电子版,PDF,欢迎下载参考,微型计算机技术及原理
With the introduction of vehicle stability systems like ESP®, and passive safety systems like seat belts and airbags, driving safety has been improved and the number of road traffic ...
Appendix B. Operator Precedence. Appendix C. Character Sets. Appendix D. Operators Overloading. Appendix E. Additional C++ Topics. Appendix F. Header Files. Appendix G. Memory Size On A System And ...
PART B: THE WORKFLOWS OF THE SOFTWARE LIFE CYCLE Chapter 10 Key Material from Part A Chapter 11 Requirements Chapter 12 Classical Analysis Chapter 13 Object-Oriented Analysis Chapter 14 Design Chapter...
CISSP All-in-One Exam Guide, Eighth Edition By 作者: Shon Harris – Fernando Maymi ISBN-10 书号: 1260142655 ISBN-13 书号: ...Appendix B About the Online Content Glossary Index 英文原版超清
Psychology as a first course in science for 8th graders 68 Jerry B. Hutton, Timothy G. Roberts, Jane Walker, and Joe Zuniga DOHRENWEND, B. S., & DOHRENWEND, B. P. (1974). Stressful life events: ...
针对PolSARpro软件的专业指导,D2P2为7th ADVANCED TRAINING COURSE ON LAND REMOTE SENSING, D3B为8th ADVANCED TRAINING COURSE ON LAND REMOTE SENSING,来源欧空局开放文件...
Fundamentals, 8th Edition.pdf 03 Java Performance- The Definitive Guide.pdf 04 JBPM工作流开发指南 .pdf 05 MySQL高性能书籍_第3版(中文).pdf 06 MySQL技术内幕 InnoDB存储引擎 第2版.pdf 07 Practical.API....
Date: Monday, May 8th, 2013 We highly encourage being environment friendly and trying all problems on your own. 0/1 Knapsack Problem. There are 5 items that have a value and weight list below, the ...
In 8th Intl Workshop on Expert Systems and their Applications, Avignon, France. pages 59-78, 1988. Within machine-learning, this dataset was used for the evaluation of HINT (Hierarchy ...
主板 联想 20KNA002CD ( 7th/8th Generation Intel Processor Family I/O - 9D4E 笔记本芯片组 ) 显卡 AMD Radeon RX 550 ( 2 GB / 联想 ) 内存 8 GB ( 记忆科技 DDR4 2666MHz ) 主硬盘 HFM128GDHTNG-8310B ( 128...
Theoretically a b+tree is O(N log k N) or log base k of N, now for the typical values of k which are above 200 for example the b+tree should outperform any binary tree because it will use less ...
Biddle, B. J., & Brophy, J. E. Teachers make a difference. New York: Holt, Rinehart, & Winston, 1975, 267 pp., [dollar]5.95 (paper) 390 Psgchology in the Schools, July, 1977, Vol. 14, No . 3. ...
Psychology as a first course in science for 8th graders 68 Jerry B. Hutton, Timothy G. Roberts, Jane Walker, and Joe Zuniga DOHRENWEND, B. S., & DOHRENWEND, B. P. (1974). Stressful life events: ...
约旦 其他R数据分析块 一个R包,具有一组用于数据分析的通用功能。 该工具主要供个人使用,除了限制我在我认为可以再次使用的东西的搜索位置上花费的时间之外,没有其他目的,因为它可以很好地...date_from_partial( b
Xiao, M -H Lee,“多径信道上的低复杂度 MIMO-LDPC CDMA 系统”, IEICE 通信交易,v E89-B,第 5 期,2006 年 5 月,第 1713-1717 页[2] J. Fan, Y. Xiao,“一种计算 LDPC 码周期数的方法”, 8th Internatio
原名: Sams Teach Yourself HTML and CSS in 24 Hours (Includes New HTML 5 Coverage), 8th Edition 作者: Julie C. Meloni Michael Morrison 资源格式: PDF 版本: 英文文字版/更新EPUB版本/更新源代码 出版社: ...