C Language Programming Questions 001

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.