Concept explainers
A)
Explanation of Solution
Analysis of given code:
The given code is used to print “Hello world” once. The process is carried out using a “do…while” loop. Initially the “count” variable is assigned with a value “3”. The loop executes till the value of “count” is lesser than “1”.
Given code segment:
//Include necessary header file
#include <iostream>
using namespace std;
//Function main
int main()
{
// Declare and initialize a variable
int count = 3; //Line 1
//Loop
do //Line 2
{ //Line 3
// Print statement
cout<<"Hello World...
B)
Explanation of Solution
Analysis of given code:
The given code is used to print value of the variable “val”. The process is carried out using a “do…while” loop. Initially the “val” variable is assigned with a value “5”. The loop executes till the value of “val” is greater than or equal to “5”.
Given code segment:
// Include necessary header file
#include <iostream>
using namespace std;
// Driver function main()
int main()
{
// Declare and initialize variable
int val = 5; //Line 1
//Loop
do //Line 2
&...
C)
Explanation of Solution
Analysis of given code:
The given code is used to print the value of variables “number” and “count” on the screen. The “do…while” loop is used to increment the value of variable “number” by “2” add the value of variable “count” by “1”.
Given code segment:
// Include necessary header file
#include <iostream>
using namespace std;
// Function main
int main()
{
// Declare and initialize variables
int count = 0, number = 0, limit = 4; //Line 1
//Loop
do //Line 2
{ //Line 3
// Increment number by 2
number+=2; //Line 4
// Increament count by 1
count++; //Line 5
} //Line 6
//Condition
while(count < limit); //Line 7
//Display number and count
cout << number << " " << count <<endl; //Line 8
//Return value
return 0;
}
Explanation:
- In “Line 1”, declare the variables “count”, “number”, and “limit” and initialize it to “0”, “0”, and “4” respectively...
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Starting Out with C++: Early Objects
- #include<stdio.h>#include<stdlib.h> int cent50=0;int cent20=0;int cent10=0;int cent05=0; void calculatechange(int* change){if(*change>0){if(*change>=50){*change-=50;cent50++;}else if(*change>=20){*change-=20;cent20++;}else if(*change>=10){*change-=10;cent10++;}else if(*change>=05){*change-=05;cent05++;}calculatechange(change);}}void printchange(){if(cent50)printf("\n50cents:%d coins",cent50);if(cent20)printf("\n20cents:%d coins",cent20);if(cent10)printf("\n10cents:%d coins",cent10);if(cent05)printf("\n05cents:%d coins",cent05);cent50=0;cent20=0;cent10=0;cent05=0;}void takechange(int* change){scanf("%d",change);getchar();}int main(){int change=0;int firstinput=0;while(1){if(!firstinput){printf("\nEnter the amount:");firstinput++;}else{printf("\n\nEnter the amount to continue or Enter -1 to…arrow_forwardint x1 = 66; int y1 = 39; int d; _asm { } mov EAX, X1; mov EBX, y1; push EAX; push EBX; pop ECX mov d, ECX; What is d in decimal format?arrow_forwardbe recor #include #include minutes #include limit on int func(int, int, int, int); main(){ srand(time(NULL)); int a, b, c, fNum; printf("Choose three different numbers between 0-39:"); scanf ("%d%d%d", &a, &b, &c); fNum = func (a, b, c, 25); printf("\nThe result: %d", fNum); } int func (int ul, int u2, int u3, int iter){ srand (time (NULL)); int n1=0, i=0, count=0; for (;iarrow_forwardJAVA:arrow_forwardQuestion 7 //Determines if a number is PRIME or NOT. #include using namespace std; int prime(int n, int i-1); int main() { int num; cout > if (prime(num)== cout << " << endl; //Answer must either PRIME / NOT PRIME. else cout << " "<< endl; //Answer must either PRIME / NOT PRIME. system("pause"); int prime(int n, int { if (i n) return( ): else if (n % i == return( + prime(n, ): else return(0 + prime(n, i + 1));arrow_forward5- int fun() int a, b, c, result; cout>a>>b>>c; cout<<"The result is "; reutrn result; } The error is Your answerarrow_forwardNumber of digits int main() {int c=0;int i=3856; int l=i; while(l>0) {l=l/10; c++; } printf("%d",c); return 0; } Summation of digits int main() {int sum=0; int i=384; int l=i; while(l>0) { sum+=l%10; l=l/10;} printf("%d",sum); return 0; }arrow_forwardchange normal body temperature to 36.5–37.5 °C #include<iostream>using namespace std;int main(){ float temp;cout<<"Enter the body temperature in Celsius\n";cin>>temp;if (temp>=37){cout<<"The quarantine of the patient is required\n";cout<<"Enter the name of the patient\n";string patient;cin>>patient;cout<<"Where the passenger is from\n";string place;cin>>place;cout<<patient<<" from "<<place<<"is to be quarantined at Hospital"; }cout<<"Normal temperature\n";}arrow_forwardDetermine all the output from the following program as it would appear on the screen. void func1(int); void func2(int = 4, int = 5, int = 2); int func3(int &, int, int); %3D int main() { int x = 0, z = 0, y = 2; func1(y); cout << y << endl; func2(x, y, z); func2(); func3(x, y, z); = Z func1(x); cout << x << " " << y << " " << z << endl; return 0; } void func1(int b) { static int a;arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning