There is a tree, two growth cycle a year, the spring it is taller one times, the summer height of 1m, ask N cycles after the tree how high? Assuming that the tree height is 1m from spring and the No. 0 period tree is 1m high.
Requirements: 1, can enter multiple growth cycles at the same time
Such as: 3//indicates that there are several growth cycles below
0
1
4
Output Result: 1
2
7
I don't know if it's right, everybody, look.
1#include <stdio.h>2#include <string.h>3#include <math.h>4#include <stdlib.h>5 6 intMain () {7 8 /*Enter your code here. Read input from STDIN. Print output to STDOUT*/ 9 intNum;//number of Save cyclesTen intarray[Ten];//save a specific cycle One intHeight//height of the tree A intI,j,k;//Loop Variable -printf"number of cycles to be entered: \ n"); -scanf"%d", &num);//Get input the if(Num <1) -num =1; - if(Num >Ten) -num =Ten; + -printf"How many cycles?!\n"); + for(i =0; i < num; i++) A { atscanf"%d", &array[i]);//Get Cycle - } - - //cyclic traversal cycle - for(j =0; J <num;j++) - { inHeight =1; - //Calculate the height of the tree within each period to for(k=1; k<=array[j];k++) + { - if(Array[j] = =0)//if the No. 0 cycle, the tree height is 1 the { *Height =1; $ }Panax Notoginseng if(k%2==0)//even cycles plus 1 - { theHeight + =1; + } A Else//double Odd Cycles the { +Height *=2; - } $ } $ //Output Tree Height -printf"The%d period tree height is:%d\n", array[j],height); - the } - Wuyi GetChar (); the return 0; -}
View Code
C Language Programming Questions 001