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 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.
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...
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?
Design a C program to print out the unsigned char (integer) values of the 4 bytes...
Design a C program to print out the unsigned char (integer) values of the 4 bytes in sequential order (i.e., the first byte is printed first). Using the code framework provided below, the printing is done by the function void byte_value(int *), in which only pointer variables can be declared and used. #include <stdio.h> ​ void byte_value(int *); ​ int main() { int n = 1; byte_value(&n); printf("Enter an integer: "); if (scanf("%d", &n) == 1) byte_value(&n); return 0; }...
Matlab program Create a function, when given a two-digit integer as input, prints the equivalent English...
Matlab program Create a function, when given a two-digit integer as input, prints the equivalent English phrase. For example, given 39, output thirty-nine. Limit the input numbers to be in the range 21 to 39.
Conversion of numeral to roman number: Create a FLOWCHART and C++ PROGRAM that prompts the user...
Conversion of numeral to roman number: Create a FLOWCHART and C++ PROGRAM that prompts the user to enter a number (from 1-3000 only) then output the number and its corresponding roman numeral number. ***validate the input (it must be 1-3000 only) SAMPLE OUTPUT: Enter a Number: 0 Number should be from 1-3000 only (Terminated) Enter a Number: -5 Number should be from 1-3000 only (Terminated) Enter a Number: 3500 Number should be from 1-3000 only (Terminated) Enter a Number: 1994...
6. Write a program in C programming (compile and run), a pseudocode, and draw a flowchart...
6. Write a program in C programming (compile and run), a pseudocode, and draw a flowchart for each of the following problems: a) Obtain three numbers from the keyboard, compute their product and display the result. b) Obtain two numbers from the keyboard, and determine and display which (if either) is the smaller of the two numbers. c) Obtain a series of positive numbers from the keyboard, and determine and display their average (with 4 decimal points). Assume that the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT