###### tags: `Basic` - [x] check # a005: Eva's homework :::info Eva is doing her math homework about fill-in-the-blank question. The rule are give you four integer and you have to fill in the fifth integer. Because the sequence is ether arithmetic sequence or geometric sequence. Please write a program to finish the homework. | input | output | | -------- | -------- | | 2 | | | 1 2 3 4 | 1 2 3 4 5| | 1 2 4 8 | 1 2 4 8 16| ::: ### 1st Ideas of solving a problem(slowly) >1. Because we should check the sequence is arithmetic or geomaetric sequence, we should use 'int' rather than 'char' to read the input data. >2. In main function, use a forloop to control how many sequences we should judge. >3. In the forloop, use if/else to check the sequence is arithmetic or geomaetric and print the sequence. ```=c #include<stdio.h> int main(){ int input,i,a,b,c,d,e; scanf("%d",&input); if(input!=0){ for(i=1;i<=input;i++){ scanf("%d%d%d%d",&a,&b,&c,&d); if((c-b)==(b-a)){ e=d+(b-a); } else{ e=d*(b/a); } printf("%d %d %d %d %d\n",a,b,c,d,e); } } return 0; } ``` ### 2nd Ideas of solving a problem(fast) >1. use a function named 'judge'. ```=c #include<stdio.h> int judge(int,int,int); int main(){ int input,i,a,b,c,d; scanf("%d",&input); if(input!=0){ for(i=1;i<=input;i++){ scanf("%d%d%d%d",&a,&b,&c,&d); printf("%d %d %d %d ",a,b,c,d); printf("%d\n",judge(b,c,d)); } } return 0; } int judge(int b,int c,int d){ int e; if((d-c)==(c-b)){ e=d+(c-b); } else{ e=d*(c/b); } return e; } ```