Question

Write C program to take four integer inputs from user (A, B, C, D) then, your...

Write C program to take four integer inputs from user (A, B, C, D) then, your program should return the sum of even numbers (if there any even numbers) and the multiplication of the odd numbers (if there any odd numbers). For example: if A=1, B=2, C=3, D=4, your program will return: sum=6, multiplication=3. if A=6, B=2, C=8, D=4, your program will return: sum=20, multiplication=0. if A=1, B=3, C=5, D=4, your program will return: sum=4, multiplication=15.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

void getSumProduct(int A,int B,int C,int D,int* sum,int* product){
    if(A%2==0){
        *sum += A;
    }
    else{
        *product *= A;
    }
    if(B%2==0){
        *sum += B;
    }
    else{
        *product *= B;
    }
    if(C%2==0){
        *sum += C;
    }
    else{
        *product *= C;
    }
    if(D%2==0){
        *sum += D;
    }
    else{
        *product *= D;
    }
}
int main(){
   int A, B, C, D, T;
   int sum = 0, product = 1;
   
   printf("Enter value for A: ");
   scanf("%d",&A);
   
   printf("Enter value for B: ");
   scanf("%d",&B);
   
   printf("Enter value for C: ");
   scanf("%d",&C);
   
   printf("Enter value for D: ");
   scanf("%d",&D);
   
   getSumProduct(A,B,C,D,&sum,&product);
   if(product==1)
    product = 0;
   printf("sum=%d, multiplication=%d.\n",sum,product);
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write C program to take four integer inputs from user (A, B, C, D) then, your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write C program to take four integer inputs from user (A, B, C, D) then use...

    Write C program to take four integer inputs from user (A, B, C, D) then use pointers to swap A&B, C&D. For example, if A=1, B=2, C=3, D=4, your program will return: A=2, B=1, C=4, D=3. You must use pointers for the swap.

  • In Python 3 - Write a program that reads a sequence of integer inputs from the...

    In Python 3 - Write a program that reads a sequence of integer inputs from the user. When the user is finished entering the integers, they will enter a 'q'. There is no need to check if the entry is a valid integer. All integers in the test data (input) will be between -255 and 255. The program should then print: The smallest and largest of the inputs. The number of even and odd inputs (0 should be considered even)...

  • Please write a C++ program that will accept 3 integer numbers from the user, and output...

    Please write a C++ program that will accept 3 integer numbers from the user, and output these 3 numbers in order, the sum, and the average of these 3 numbers. You must stop your program when the first number from the user is -7. Design Specifications: (1) You must use your full name on your output statements. (2) You must specify 3 prototypes in your program as follows: int max(int, int, int); // prototype to return maximum of 3 integers...

  • # Write PYTHON programs that read a sequence of integer inputs and print # a.  The...

    # Write PYTHON programs that read a sequence of integer inputs and print # a.  The smallest and largest of the inputs. # b.  The number of even and odd inputs. # c.  Cumulative totals. For example, if the input is 1 7 2 9, the program should print # 1 8 10 19. # d.  All adjacent duplicates. For example, if the input is 1 3 3 4 5 5 6 6 6 2, the # program should print...

  • Write a C program to do the following 1) request user to enter 10 integer into...

    Write a C program to do the following 1) request user to enter 10 integer into an array 2) sort the array in ascending order 3) display the sorted array 4) count the number of odd and even number in the array and print out the result 5) add the value of the odd number and even number and calculate the average of the odd and even number. display the result 6) write function addNumber() to add all the number...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Write a complete Java program, including comments in both the main program and in each method,...

    Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...

  • 1. Write a program called Numbers that a. prompts the user for a file name. b....

    1. Write a program called Numbers that a. prompts the user for a file name. b. reads that file assuming that its contents consist entirely of integers. c. prints the maximum, minimum, sum, count (number of integers in the file), and average of the numbers. For example, if the file numberinput.dat has the following content: 4 -2 18 15 31 27 Your program should produce the following output: csc% java Numbers Enter file name: numberinput.daft Maximum31 Minimum- -2 Sum -...

  • C++ Problem #1 Write a program that prompts user to enter an integer up to 1000...

    C++ Problem #1 Write a program that prompts user to enter an integer up to 1000 and displays back a message about the number of digits in this number and if number is odd or even. For example, if user enters 93 message back should be "93 has 2 digits and is odd".

  • For Java Write a program that reads a sequence of integer inputs all on one line...

    For Java Write a program that reads a sequence of integer inputs all on one line and prints: 1.)The smallest and largest of the inputs 2.)The number of odd and even inputs 3.)Cumulative totals. If the input is 1 7 2 9, the program prints 1 8 10 19. 4.)All adjacent duplicates. If the input is 1 3 3 4 5 5 6 6 6 2, the output is 3 5 6.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT