Question

**Using C Language** Get a number from the user and use that number for loops and...

**Using C Language**

Get a number from the user and use that number for loops and to make some calculations.

Get a number from the user (n) (For example if the user enters a 3, each loop below will repeat 3 times)

//ask, get, and return an integer (by reference)

void GetIntPointer(int *numPtr);

//input: the number entered by the user (pass by copy)

//Calculates the product of the first (n)numbers using a while loop and store the result in *productPtr //For example, if the user entered a 3, you would calculate 1 * 2 * 3.

//Calculate the sum of the first (n)numbers using a for loop and store the result in *sumPtr.

//For example, if the user entered a 3, you would calculate 1 + 2 + 3.

void Calculations(int num, double *productPtr, int *sumPtr);

Remember to initialize the “value at” productPtr and “value at” sumPtr before making the calculations.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here is the C code with screenshot

========================================================================

#include<stdio.h>

//ask, get, and return an integer (by reference)
void GetIntPointer(int *numPtr) {
printf("Enter an integer: ");
scanf("%d",numPtr);
}

void Calculations(int num, double *productPtr, int *sumPtr) {
for(int i=1; i<=num; i++) {

*productPtr = *productPtr*i;
*sumPtr = *sumPtr + i;
}

}


int main() {

int num=0, product=1, sum=0;
GetIntPointer(&num);
Calculations(num,&product,&sum);


printf("\nProduct is %d",product);
printf("\nSum is %d",sum);

}

========================================================================

Start here X Calculate-c # include //ask, get, and return FChegg C+Calculate.exe nter an integer: 5 an integer (by reference) void GetIntPointer (int *numPtr) printf("Enter an integer:" scanf ("%d", numPtr) ; roduct is 120 um is 15 rocess returned 0 (0x0 execution time 2.383 S ress any key to continue. void Calculations (int num, double productPtr, int 'sumPtr) 10 for (int i-l: i- i++) productPtr productPtri 12 13 14 16 17 18 19 20 21 int main) int numo, product=1, sum=0; GetIntPointer (num) Calculations (num, &product, &sum) 23 24 25 26 27 28 29 30 printf("\nProduct is %d", product); printf("InSum is d",sum) C/C++ Windows (CR+LF) WINDOWS-1252 Line 27, Col 25, Pos 537 Insert

Add a comment
Know the answer?
Add Answer to:
**Using C Language** Get a number from the user and use that number for loops and...
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
  • C++ please 27.5 Loops (nested)**: Sum a given number of integers A user will enter an...

    C++ please 27.5 Loops (nested)**: Sum a given number of integers A user will enter an initial number, followed by that number of integers. Output those integers' sum. Repeat until the initial number is O or negative. Ex: If the user enters 3 96 1 0, the output is 16 Ex: If the user enters 396125 3 0, the output is 16 Hints: Use a while loop as an outer loop. Get the user's initial number of ints before the...

  • Write a program that calculates the average of a stream of non-negative numbers. The user can...

    Write a program that calculates the average of a stream of non-negative numbers. The user can enter as many non-negative numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, zero counts as a number that goes into the average. Of course, the negative number should not be part of the average (and, for this program, the average of 0 numbers is 0). You must use a method to read...

  • Using loops, write a C# program that asks the user to enter repeatedly an integer number,...

    Using loops, write a C# program that asks the user to enter repeatedly an integer number, it stops when the user enters -1, then the program should display how many numbers were entered, their the sum and their average

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to input 10 int numbers from the user...

  • 1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The...

    1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The program should use the for loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. If the user enters a zero or negative number, a message should be given and the program should not continue (see Sample Run...

  • PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end...

    PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end please include a main function that tests the functions that will go into a separate driver file. Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...

  • Objectives: Learn how to use the C++ while and for loops. Instructions: A perfect number is...

    Objectives: Learn how to use the C++ while and for loops. Instructions: A perfect number is a positive integer greater than 1 that is equal to the sum of the positive integer numbers, including 1 but not including itself, that evenly divide into it. First, you should prompt the user for a number. Next, you should indicate if the number is a perfect number or not. Finally, you should list the numbers that evenly divide into the number entered and...

  • Write a C++ program using "for" loop to allow user to guess a certain number say...

    Write a C++ program using "for" loop to allow user to guess a certain number say 55. The loop will end after 5 guesses or if he guesses the right number, which ever comes first. If user enters a number greater than 55, your program should print "You entered a bigger number". If user enters a number smaller than 55, your program should print "You entered a smaller number". If user enters 55 in less than 5 attempt, your program...

  • Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program...

    Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program will calculate and display the total of all numbers up to a specific number (entered by the user). Only positive numbers are allowed. Part B: User-controlled loop Part A Input Validation loop Part A: Summation loop Examples: When 5 is entered the program will calculate the total as 1+2+...+5 and display 15. When 2 is enterered the program will calculate the total as 1+2...

  • Answer using programming in C only. 6 pts Use a while loop to complete the following:...

    Answer using programming in C only. 6 pts Use a while loop to complete the following: Prompt the user to enter integers one by one, until the user enters a negative number to stop Calculate the sum and the average of all the numbers entered by the user Print the sum and the average onto the screen after the loop. Declare and initialize all variables. Be sure to keep a count of the numbers entered for the average calculation

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