Question

In: Computer Science

CODE IN C PLEASE Ask for user to input 4 different numbers Use pointers in calculations...

CODE IN C PLEASE

Ask for user to input 4 different numbers

Use pointers in calculations instead of variables to calculate the sum of those 4 numbers

Print the sum

Use a pointer to a pointer for print operation

Solutions

Expert Solution

Answer:

Program:

#include<stdio.h>
int main()
{
   // variable declaration
   int a,b,c,d,tot,*total,**sum,*p,*q,*r,*s;
   // prompts the message
   printf("Enter four different numbers: ");
   // reads 4 integer values from the keyboard, and stores in the variables a,b,c,d
   scanf("%d%d%d%d",&a,&b,&c,&d);
   // storing the addresses of variables a,b,c,d into pointer variables p,q,r,s respectively
   p=&a;
   q=&b;
   r=&c;
   s=&d;
   // adding the contents of a,b,c,d using pointers and storing into the variable 'tot'
   tot=(*p+*q+*r+*s);
   // The address of 'tot' is stores into the pointer variable 'total'
   total=&tot;
   // The address of the pointer variable 'total' is again stored in pointer to poiter 'sum'
   sum=&total;
   // printing the resultant sum value using pointer to pointer
   printf("The sum of four numbers is=%d",**sum);
   return 0;
}

Program Screenshot:

Output Screenshot:


Related Solutions

Write a C++ code to ask the user to enter 4 values (whole numbers). Your code...
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code should print the numbers in descending order.
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
Write application in C# that enables a user to: Use Methods for user input and calculations...
Write application in C# that enables a user to: Use Methods for user input and calculations input the grade and number of credit hours for any number of courses. Calculate the GPA on a 4.0 scale using those values. Grade point average (GPA) is calculated by dividing the total amount of grade points earned, sometimes referred to as quality points, by the total number of credit hours attempted. For each hour, an A receives 4 grade or quality points, a...
python: ask the user to input a sequence of positive numbers. the end of the sequence...
python: ask the user to input a sequence of positive numbers. the end of the sequence is determined when the user enters a negative number. print out the maximum number from the sequence. output: keep entering positive numbers. to quit, input a negative number. enter a number: 67 enter a number: 5 enter a number: 8 enter a number: -3 largest number entered: 67 (note: i do not want to ask the user how many numbers they will input)
in C please! Write a code that asks user for input N and calculates the sum...
in C please! Write a code that asks user for input N and calculates the sum of the first N odd integers. There should be a "pure" method that calculates the sum separately that Main method should call when printing the output.
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Please use C++ 1. A Sequence of numbers and a sum is given as input. List...
Please use C++ 1. A Sequence of numbers and a sum is given as input. List all combinations of numbers that can add upto the given Sum. User input:- Enter numbers: -   1, 3,7,9,11 Enter a sum :- 20 Output: 11+9 = 20 1+3+7+9 = 20 2. Print absolute prime numbers between a given range:- Enter Range - 2,99 For eg Prime numbers are:- Prime numbers ==> 2,3,5,7,11,13,17,19,23 Absolute Prime numbers ==> 2,3,5,7,11,23 3. Write an encoder and decoder program,...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “Mahahanap mo na ang forever mo. Sana all!” If the user’s die is smaller, it should display, “Gising na friend,...
Define a problem with user input, user output, -> operator and destructors. C ++ please
Define a problem with user input, user output, -> operator and destructors. C ++ please
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The...
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The program will use a while loop to let the program keep running. The user will be allowed to use the program as long as the quitVariable is equal to 'y' or 'Y'. When the user decides to quit playing, say "Thanks for playing!". The program will use a for loop to test if the number are even or odd. If even print "number is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT