Answer:
#include <iostream>
using namespace std;
int func(int n)//function..
{
if(n>1)
{
if(n%2==0)//checking if the number is even.
{
return n/2;
}
else
{
return (3*n+1);
}
}
}
int main() {
int num;//taking input of the n.
cin>>num;
while(num>1)//looping while the value of num is greater than 1.
{
int a=func(num);//calling function.
cout<<a<<" ";//printing .
num=a;//changing the value of num.
}
return 0;
}
Input:-
10
Output:-
5 16 8 4 2 1
Explanation:
I have created the function named func. Then returning the values according to the problem.In the main function taking the input of integer num. Then calling a loop and calling the function till the value of n is greater than 1 and printing all the values returned by the function.
<span>Sizing handles are used in Microsoft Word to resize an object.</span>
COMPLETE QUESTION
I. public class Test {
public static void main(String[] args){
System.out.println("Welcome to Java!");
}
}
II. public class Test { public static void main(String[] args) {System.out.println("Welcome to Java!");}}
Answer:
Both codes will compile and run and display Welcome to Java, but the code in II has a better style than I
Explanation:
When written codes, paying attention to proper coding styles and efficient memory management enables us to create programs that are highly efficient, coding styles refer to proper indentions and avoiding too lenghty lines of code (as is in code I), adding approprite comments etc.