In C++ programming Suppose that the first number of a sequence is x, in which x
ID: 672606 • Letter: I
Question
In C++ programming
Suppose that the first number of a sequence is x, in which x is an integer. Define a_0 = x; a_n + 1 = a_n/2 if a_n is even; a_n + 1 = 3 Times a_n + 1 if a_n is odd. Then, there exists an integer k such that a_k = 1. Write a program that prompts the user to input the value of x. The program output the integer k such that a_k = 1 and the numbers a_0, a_1, a_2, . . . , a_k. (For example, if x = 75, then k = 14, and the numbers respectively, are 75, 226,113, 340, 170, 85, 256, 128, 64, 32, 16, 8, 4, 2, 1.) Test your program for the following values of x: 75, 111, 678, 732, 873, 2048, and 65535. Write a program that uses while loops to perform the following steps: Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than secondNum). Output all odd numbers between firstNum and secondNum. Output the sum of all even numbers between firstNum and secondNum. Output the numbers and their squares between 1 and 10. Output the sum of the square of the odd numbers between firstNum and secondNum. Output all uppercase letters. Redo Programming Exercise 6 using for loopsExplanation / Answer
#include<iostream.h>
#include<conio.h>
void main()
{
int firstNum, secondNum,i,odsq=0,evsq=0,s;
clrscr();
cout<<"Enter no";
cin>>firstNum;
cout<<"Enter no";
cin>>secondNum;
if(firstNum>=secondNum)
{
cout<<"First no should be less than Second";
return;
}
i=firstNum;
while( i<=secondNum)
{
cout<<" "<<i;
odsq=odsq+(i*i);
i=i+2;
}
i=firstNum+1;
while( i<=secondNum)
{
cout<<" "<<i;
evsq=evsq+(i*i);
i=i+2;
}
i=1;
while (i<=10)
{
s=i*i;
cout<<" "<<s;
i++;
}
cout<<" SUM OF SQUARES OF ODD NUMBERS"<<odsq;
cout<<" SUM OF SQUARES OF EVEN NUMBERS"<<evsq;
getch();
odsq=0;
evsq=0;
for(i=firstNum; i<=secondNum;i=i+2)
{
cout<<" "<<i;
odsq=odsq+(i*i);
}
for(i=firstNum+1; i<=secondNum;i=i+2)
{
cout<<" "<<i;
evsq=evsq+(i*i);
}
for(i=1;i<=10;i++)
{
s=i*i;
cout<<" "<<s;
}
cout<<" SUM OF SQUARES OF ODD NUMBERS"<<odsq;
cout<<" SUM OF SQUARES OF EVEN NUMBERS"<<evsq;
getch();
}