Question

In: Computer Science

4. Construct a flowchart and the C ++ program that, receiving a four-digit integer as data,...

4. Construct a flowchart and the C ++ program that, receiving a four-digit integer as data, determines whether all the digits of the number are even. For example, if the number were 5688, it would not meet the condition since the most significant digit (5) is odd; if on the contrary, the number were 6244, it would be true, since all the digits are even.

5. Make the flowchart and the C ++ program that, when receiving N integers as data, obtains only the sum of the positive numbers.

Solutions

Expert Solution

4. Construct a flowchart and the C ++ program that, receiving a four-digit integer as data, determines whether all the digits of the number are even. For example, if the number were 5688, it would not meet the condition since the most significant digit (5) is odd; if on the contrary, the number were 6244, it would be true, since all the digits are even.

Answer:

FLOW CHART:

I WROTE THE CODE ALONG WITH THE COMMENTS

CODE:

#include <iostream>

using namespace std;

int main()
{
//variables declaration.
int num,digit,flag=0,temp;
  
//scan input.
cout<<"Enter four digit number: ";
cin>>num;
temp=num;
while(temp) //conditon temp not equal to zero.
{
digit=temp%10; //take each digit.
if(digit%2==0) //conditon digit is even
{
temp=temp/10; //take remainig numbers after digit checking.
flag=1;
}
else
{
flag=0;
break;
}
}
if(flag==1) //conditon flag 1 means contain all even digits.
cout<<num<<" contain all even digits.";
else
cout<<num<<" contains odd digts.";
return 0;
}

OUTPUT:

SCREENSHOT OF THE CODE:

5. Make the flowchart and the C ++ program that, when receiving N integers as data, obtains only the sum of the positive numbers.

Answer:

FLOW CHART:

I WROTE THE CODE ALONG WITH THE COMMENTS

CODE:

#include <iostream>

using namespace std;
int main()
{
int N,sum=0,i; //variables declaration.
  
cout<<"Enter how many elements you want: ";
cin>>N;
  
int arr[N];
cout<<"enter elements: ";
for(i=0;i<N;i++) //for loop used to scan elements.
cin>>arr[i];
for(i=0;i<N;i++) //for loop used to traverse each element.
{
if(arr[i]>0) //conditon element is positive.
sum=sum+arr[i]; //calculate sum.
}
cout<<"Sum of positive integers: "<<sum; //print sum.
return 0;
}

OUTPUT:

SCREENSHOT OF THE CODE:


Related Solutions

(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it in horizontal order of the screen
what is the best code to construct a C++ program that finds a five digit number;...
what is the best code to construct a C++ program that finds a five digit number; This number should reverses the order of its digits when multiplied by four. Also, how many five digits numbers are there in which the sum of the digits is even.
Write a C++ program that checks if the password is correct. The password is a 4-digit...
Write a C++ program that checks if the password is correct. The password is a 4-digit number combination. The program repeats to ask the password until the password is correct or you enter -1 to exit. Input: The password is set to ‘1123’. A user input the password to proceed, or -1 to exit. Sample Output: The program should display the following output. (The red text is a user input.) Test case 1: when you enter the correct password. Enter...
Write a program in C that takes as input a four-digit hexadecimal number and prints the...
Write a program in C that takes as input a four-digit hexadecimal number and prints the next 10 hexadecimal numbers. Define a hexadecimal number as int hexNum[4] Allow upper- or lowercase letters for input and use uppercase letters for the hexadecimal output. For example, 3C6f should be valid input and should produce output 3C6F, 3C70, 3C71, . . . .
write a c++ program an expression that determines if an integer, n is a negative four...
write a c++ program an expression that determines if an integer, n is a negative four digit number. write a c++ program an expression that determines if a string, wd, equals "so" ignoring case.
In C ++, Design and implement a program that reads from the user four integer values...
In C ++, Design and implement a program that reads from the user four integer values between 0 and 100, representing grades. The program then, on separate lines, prints out the entered grades followed by the highest grade, lowest grade, and averages of all four grades. Format the outputs following the sample runs below. Sample run 1: You entered:    95, 80, 100, 70 Highest grade: 100 Lowest grade:   70 Average grade: 86.25
in .java Write a program that reads an integer with 3 digits and prints each digit...
in .java Write a program that reads an integer with 3 digits and prints each digit per line in reverse order. Hint: consider what you get from these operations: 319%10, 319/10, 31%10, ... Enter an integer of exactly 3 digits(e.g. 538): 319 9 1 3 Hint: consider what you get from these operations: 319%10 319/10 31%10
What is the probability that a randomly chosen four-digit integer has distinct digits and is odd?
What is the probability that a randomly chosen four-digit integer has distinct digits and is odd?
Write a C++ program to find least common multiple (LCM) of two, three and four integer...
Write a C++ program to find least common multiple (LCM) of two, three and four integer values. The integer values are entered from the keyboard and the outputs are printed to the console. The LCM of two, three and four integer values are computed using Prime factorization method. You have to use arrays to hold input values and use functions/methods to get data from the keyboard, display output to the console, calculate LCM using Prime factorization method. Your program should...
Write a C++ program to find least common multiple (LCM) of two, three and four integer...
Write a C++ program to find least common multiple (LCM) of two, three and four integer values. The integer values are entered from the keyboard and the outputs are printed to the console. The LCM of two, three and four integer values are computed using Prime factorization method. You have to use arrays to hold input values and use functions/methods to get data from the keyboard, display output to the console, calculate LCM using Prime factorization method. Your program should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT