Question

Need help with code using pointer only in C Ask the user to enter a number...

Need help with code using pointer only in C

Ask the user to enter a number between 1 and 10

•Check if the user has complied.

•Keep asking the user for a number between 1 and 10 until the user complies.

•Then calculate N! (no recursion)

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

File: fact.c

#include<stdio.h>
   //Function to calculate Factorial
   void findFact(int num,int *fact)
   {
int i;   
*fact =1;   
for(i=1;i<=num;i++)
       {
*fact=*fact*i;
       }
}   
int main()
   {
int i,fact,num=0;
   //do While loop to to check complies
   do
   {
       printf("Enter a number between 1 and 10: ");
       scanf("%d",&num);
       if(num >=1 && num <=10)//checking number is between 1 and 10
       {
           findFact(num,&fact);
           printf("Factorial of %d is: %d",num,fact);
       }
   }while(num > 10 || num < 0);
return 0;
}

Screen:

Add a comment
Know the answer?
Add Answer to:
Need help with code using pointer only in C Ask the user to enter a number...
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
  • i need this in c program please Computing Factorials Lab #2 Name your program lab2.c Start...

    i need this in c program please Computing Factorials Lab #2 Name your program lab2.c Start by asking the user to enter a number between 1 and 15 Check if the user has complied. Keep asking the user for a number between 1 and 15 until the user complies. Then ask if recursion is desired or not. If recursion is not desired call a function to calculate N! (where N is the number entered) – If recursion is required call...

  • Write a code using loop and flag function in python jupitior notebook: Ask the user for...

    Write a code using loop and flag function in python jupitior notebook: Ask the user for the number of items they bought. Also ask the price of each item they bought and quantity purchased. Display the total amount they owe. Ask the user for a number n. Calculate 1+2+3+….+n. Ask the user for a number n. Calculate 1*2*3*…*n. Ask the user for number of rows (r) and columns (c). Print * for r rows and c columns. Ask the user...

  • Write code to repeatedly ask the user for a number. If the number is positive and...

    Write code to repeatedly ask the user for a number. If the number is positive and even, print out a happy message. If the number is positive and odd, print out a sad message. If the number is negative, print out an angry message If they enter zero, stop asking If they enter something that isn't an integer, print out a message telling them they are an idiot, but keep looping

  • This program is to ask the user N number of math (using only +, -, *,...

    This program is to ask the user N number of math (using only +, -, *, and /) questions. Once the program start it asks the user to enter how many questions will be asked (N, which is between 3-10). Then, the program asks N questions to the user. Each question will be one of four math operations (+, -, *, and /). The operation and operands will be selected randomly in your program.Operand are “unsigned short” between 0 and...

  • MATLAB ONLY PLEASE...ALSO AS SIMPLE AS POSSIBLE...NEW TO LANGUAGE Write a code that will ask the...

    MATLAB ONLY PLEASE...ALSO AS SIMPLE AS POSSIBLE...NEW TO LANGUAGE Write a code that will ask the user to input a positive number x. If the number is negative the program will keep asking again and again (as long as the value is negative) until the user inputs a positive value. At the end of the program, calculate the following: y = e-x

  • c++ QUESTION 9 Write a code that ask the user for the number n of decimal...

    c++ QUESTION 9 Write a code that ask the user for the number n of decimal to average. Then n times the code the user to enter all numbers that you save or accumulate each time. Finaly print to the console the average of the n values the user entered using the format: cout << " The average of the " << n << " number you entered is: " << averagedValue <<endl;

  • Write a C code using switch statement that will ask the user to enter a character....

    Write a C code using switch statement that will ask the user to enter a character. This character should be one of the first three characters of your name. The code then should check for the value of the character and output the following: If the character is the same as yo&r first letter then output "X=10" If the character is the same as your second letter then output "Y=5" If the character is the same as your Third letter...

  • C++ only Implement a program that prompts a user to enter a number N where N...

    C++ only Implement a program that prompts a user to enter a number N where N is a positive number. The program must validate a user input and ask a user to re-enter until an input is valid. Implement a function that pass N as an argument and return a result of calculates N! (N-factorial): The function must use loop for the implementation. Hint: Factorial: N! = N * (N-1) * (N-2) * …. * 1 ( This is only...

  • Write C code to repeatedly ask the user for a number, then once the user enters...

    Write C code to repeatedly ask the user for a number, then once the user enters 0, the code displays the min, max and average of all values entered. To get proper credit, name the variables as listed below and follow the directions carefully. Do not use any break or similar type of statements. To implement the above code, you will need to count the entries - name the counter variable num_count. You will also need to use a variable,...

  • write a c++ code be sure the user only enter A or a for packageA, B...

    write a c++ code be sure the user only enter A or a for packageA, B or b for packageB, C or c for packageC. If the user inputs some other value display an error message saying " invalid out". When you ask the user to input the number of minute and the user enters a negative value you should display the same error message "invalid input" in both cases, after you display the error message the program should stop...

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