C++ Answers

Questions answered by Experts: 9 913

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Nishant does pretty weird stuff. Today, he wants to create a weird sequence.


According to Nishant, a sequence A of length N is called weird if:


N≥3

2⋅Ai>Ai−1+Ai+1 ∀i∈{2,3,4....,N−1}

Nishant wants to construct a long weird sequence to impress his weird friends, but there's a problem: he only knows how to count up to K, so the sequence can only contain integers in the range [1,K].


Help Nishant determine the length of the longest weird sequence he can construct using only integers from 1 to K.


Input Format

The first line contains a single integer T denoting the number of testcases. The description of T testcases follows.

The first and only line of each testcase contains a single integer K.

Output Format

For each testcase, print one line containing a single integer - the maximum length of a weird sequence which can be obtained using only integers in [1,K].


Constraints

1≤T≤105

2≤K≤109

Sample Input 1

3

3

5

1073

Sample Output 1

4

6

92



Input

required to input in two sequences. first sequence is the user will input the # of items which should be greater than 1 and not be greater than 30. If the input is outside the range display "OUT OF RANGE". After validating that the range is valid, the user moves on to entering the next sequence. second sequence will require the user to input the numbers.

Out

Once all the numbers are entered, the program will simply get the largest and smallest number from the second sequence. In addition, it will also count the number of times the largest number or smallest number occurred. If the user entered the same numbers in the second sequence, the program will display the largest number and the # of times it is repeated but will display "Smallest number is the same as the largest number." for the smallest number.


In

8
8 7 6 5 4 3 2 1

Out

8:1x
1:1x



15
-1 -2 -5 -1 -5 -1 -5 -2 -1 -2 -1 -5 -1 -2 -1

-1:7x

-5:4x


20

9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9


9:20x

Smallest number is the same as the largest number.







Program

Create a program that will accept a character array input with a maximum array size of 30 and will check if the input contains a number.


Sample Input #1

2sHO4p

Sample Output #1

Numbers Exist:24


Sample Input #2

love

Sample Output #2

No Number


Sample Input #3

g00d morn1ng (space between characters)

Sample Output #3

Number Exist:001


Input

The program will accept a single text input.

Output

After the user encodes his/her text input, the program examines the text's structure which includes:

  1. The number of letters (regardless if its uppercase/lowercase)
  2. The number of numeric characters
  3. The number of special characters
  4. The number of vowels together with the actual vowels from the input
  5. The number of consonants together with the actual consonants from the input
  6. The count of the numeric characters together with the actual numeric characters from the input
  7. The count of the special characters together with the actual special characters from the input

sample Input

october/15/1975

Sample Output

7:letters

6:numbers

2:special-characters

3:ooe

4:ctbr

6:151975

2://



Write a C++ program called PositiveNumbers.cpp.

The program must do the following:

 Prompt user to enter a positive number that is greater than 0 or a -1 to quit (See Figure 4.1).

NB: Make use of a post-test loop

 If the number is within the range, determine the following :

o how many numbers are entered,

o the total (sum) of all numbers entered,

o determine how many are even numbers and,

o determine the highest number entered.

 If the number is invalid display and appropriate message as indicated in Figure 4.2.

 This process must be repeated until an invalid number is entered (-1).When the process terminates, display the following (See Figure 4.1 and Figure 4.3)

o the total of the numbers entered,

o the total number of even numbers,

o the highest number and

o the sum of all numbers entered.


Make a c++ program of a simple menu program of the sample run below.


Sample Run:


Difficulty Levels

      1. - Easy

      2. - Normal

      3. - Hard

Choice : 1

 You picked Easy.

Play another game? (y/n): y

Difficulty Levels

      1. - Easy

      2. - Normal

      3. - Hard

Choice : 2

You picked Normal.

Play another game? (y/n): y

Difficulty Levels

      1. - Easy

      2. - Normal

      3. - Hard

Choice : 3

 You picked Hard.

Play another game? (y/n): y

Difficulty Levels

      1. - Easy

      2. - Normal

      3. - Hard

Choice : 4

Illegal Choice. Please try again.

Play another game? (y/n): y

Difficulty Levels

      1. - Easy

      2. - Normal

      3. - Hard

Choice : 2

You picked Normal.

Play another game? (y/n): n

Thanks for playing…

This terminates the process.

[ So, this portion the cycles repeat until expression test false,

 at which point the loop ends.]


1.A student with a temperature from 36.5°C to 37°C will be allowed to write their exams. The value of the students’ temperature will be stored in variable called temperature.


1.1 Write a C++ while clause that will allow the program to execute when the value in the temperature variable is within the required range.

1.2 Which data type of data is the student’s temperature.


1. Consider the for-loop statement in pseudocode below and answer the following questions number = 15

do while (number >=-25)

Display “number = “, number

number = number -2

Loop


1.1 Rewrite the do while loop using a for-loop in a C++ syntax. Write only the for loop statement, do not write the other instructions inside the body of the loop.

1.2 Rewrite the do while loop above in C++ syntax.

1.3 How many times will the loop execute?

1.4 The value of number after execution of the loop.


1.1 Which of the following program segments will display odd numbers up until to 31?

a. i = 1;

while (i < 31)

{ cout << "i = " << i << endl; i = i + 2; }

b. for(int i= 0; i < 32 ; i++)

{ cout << "i = " << i << endl; }

c. for(int i= 0; i <= 31 ; i= i + 2 )

{ cout << "i = " << i << endl; }

d. for(int i= 1; i < 32 ; i= i + 2 )

{ cout << "i = " << i << endl; }


1.1 A variable declared within the for-loop has _________ scope.

a. local

b. global

c. block

d. private

1.2 Which of the following statements is equivalent to the following: while (value < 18)

a. while (value <= 18)

b. while (value >=18)

c. while (! (value > 18) )

d. while (value < 17)

1.3 Which of the following equations will deduct a discount of 7.5% from an amount?

a. amount = amount – 7.5%

b. amount = amount * .925;

c. amount = amount – (amount * 0.075)

d. amount = amount – amount * 0.75;

1.4 Which of the following statement is equivalent to?

result *= a + 5;

a. result = result * a + 5;

b. result = result * (a + 5);

c. result = (result * a ) + 5

d. results = a+ 5;



LATEST TUTORIALS
APPROVED BY CLIENTS