Question

*********C Language******* Write a file final_main.c 4. Inside main(void): Write a loop that oops until the...

*********C Language*******
Write a file final_main.c

4. Inside main(void):
Write a loop that oops until the entered number is 0 or negative
5. Ask the user to enter a positive int between 0 and 10 inclusive
6. If the number is < 1, it terminates.
7. Else: call the above four functions
8. Print the result of each function after its call.

Q2. Write a program that removes the punctuations letters from a file and display the output to the screen. It will only keep lettes, digits, and spaces, tabs, new lines.

Q1. Write a C program that has tools.h, tools.c, and final_main.c

1. In a file tools.h write the headers of these functions:
unsigned long long fac_rec(unsigned int x);
unsigned long long fac(unsigned int x);
unsigned long long fib_rec(int n);
unsigned long long fib(int n);
2. In a file tools.c, write the definitions of these functions:
unsigned long long fac_rec(unsigned int x)
unsigned long long fac(unsigned int x)
unsigned long long fib_rec(int n)
unsigned long long fib(int n)
3. Write a file final_main.c

4. Inside main(void):
Write a loop that oops until the entered number is 0 or negative
5. Ask the user to enter a positive int between 0 and 10 inclusive
6. If the number is < 1, it terminates.
7. Else: call the above four functions
8. Print the result of each function after its call.

Q2. Write a program that removes the punctuations letters from a file and display the output to the screen. It will only keep lettes, digits, and spaces, tabs, new lines.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

please do upvote.If you have any problem do comment and i shall be happy to help you.Thanks for using HomeworkLib.

Note: I have answered the first question only as per HomeworkLib's policy

-----------------------------

//tools.h

unsigned long long fac_rec(unsigned int x);
unsigned long long fac(unsigned int x);
unsigned long long fib_rec(int n);
unsigned long long fib(int n);

-----------------------------

//tools.c

#include "tools.h"

unsigned long long fac_rec(unsigned int x)


{
   if (x == 1) //factorial of 1 is 1
   {
       return 1;
   }
   else
   {
       unsigned long long answer = fac_rec(x - 1); //calculate factorial of previous number
       return x *answer;
   }
}

unsigned long long fac(unsigned int x)
{
   int a;
   int answer = 1;

   //calculate factorial of x using loop
   for (a = x; a > 1; a--)
   {
       answer = answer * a;
   }
   if (x == 0)
   {
       answer = 1;
   }
   return answer;
}

unsigned long long fib_rec(int n)
{
   if (n == 0)
   {
       return 0;
   }
   if (n == 1)
   {
       return 1;
   }

   //calculate fibonacci of previous two numbers
   unsigned long long a = fib(n - 1);
   unsigned long long b = fib(n - 2);

   return a + b;
}

unsigned long long fib(int n)
{

   int old = 1;
   int present = 1;
   int upcoming = 1;
   int a = 0;

   //calculate fibonacci of nth number using loop
   for (a = 3; a <= n; ++a)
   {
       upcoming = present + old;
       old = present;
       present = upcoming;
   }
   return upcoming;
}

---------------------

//final_main.c

#include<stdio.h>
#include<conio.h>
#include"tools.h"

void main()
{
   int num = 0;
   long result = 0;
   while (1)
   {
       //get input
       printf("enter a positive int between 0 and 10 inclusive: ");
       scanf_s("%d", &num);

       if (num < 1)
       {
           break;
       }

       //outputs
       result=fac_rec(num);
       printf("result of fac_rec : %ld \n", result);
       result = fac(num);
       printf("result of fac : %ld \n", result);
       result = fib_rec(num);
       printf("result of fib_rec : %ld \n", result);
       result = fib(num);
       printf("result of fib : %ld \n", result);


   }
}

----------------------------------

Add a comment
Know the answer?
Add Answer to:
*********C Language******* Write a file final_main.c 4. Inside main(void): Write a loop that oops until the...
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 a program that prompts for a sentence and calculates the number of uppercase letters, lowercase...

    Write a program that prompts for a sentence and calculates the number of uppercase letters, lowercase letters, digits, and punctuation. Output the results neatly formatted and labeled in columns. how I can make this program in a more simple way. # get user input user_string = input("Enter a sentence: ") # create and initialize variables upper_case = 0 lower_case = 0 digits = 0 spaces = 0 punctuations = 0 x = len(user_string) #loop conditions and increment for i in...

  • Write a C++ program that repeatedly reads lines until an EOF is encountered. As each line...

    Write a C++ program that repeatedly reads lines until an EOF is encountered. As each line is read, the program strips out all characters that are not upper or lower case letters or spaces, and then outputs the line. Thus, the program acts as a filter and issues no prompt. There are many ways this program could be written, but to receive full credit, you must observe the following: Place your code in a file called filterChars.cpp. The program should...

  • #include <stdlib.h> #include <stdio.h> #include "main.h" #define MAX_NUM_LENGTH 11 void usage(int argc, char** argv) { if(argc...

    #include <stdlib.h> #include <stdio.h> #include "main.h" #define MAX_NUM_LENGTH 11 void usage(int argc, char** argv) { if(argc < 4) { fprintf(stderr, "usage: %s <input file 1> <input file 2> <output file>\n", argv[0]); exit(EXIT_FAILURE); } } /* This function takes in the two input file names (stored in argv) and determines the number of integers in each file. If the two files both have N integers, return N, otherwise return -1. If one or both of the files do not exist, it...

  • General Requirements . . . Write a program that reads letters from a file called "letters.txt"....

    General Requirements . . . Write a program that reads letters from a file called "letters.txt". Your program will open the letters.txt file read in one character at a time For this assignment the test file will contain at least 30 letters, uppercase OR lowercase In your program you will change each letter (solution) to uppercase Use the function toupper in #include <ctype.h> You create a numerical version of the uppercase letter from the file . o Use int numberSolution...

  • C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional...

    C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional arrays. Your program should include three functions: one for getting input data, one for calculating the sum of matrices, and one for printing the result. a) Function inputMatrix: This Function prompts the user to enter the data and stores data inside two-dimensional array. b) Function addMatrices: This function calculatesthe sum result of two matrices. c) Function printMatrix: This function prints the matrix to screen....

  • What to do Write a C program that computes Pi with the approximation algorithm that I...

    What to do Write a C program that computes Pi with the approximation algorithm that I introduced in class. I want you to write the program in two different ways: The first version will add up the first 28284277 elements of the approximation series in a simple for loop. I ask you to put the code into a function with this signature: float get_pi_for(void); The second version will break out of a while loop depending on whether a pair of...

  • In C please! 4.20 LAB: Countdown until matching digits Write a program that takes in an...

    In C please! 4.20 LAB: Countdown until matching digits Write a program that takes in an integer in the range 20-98 as input. The output is a countdown starting from the integer, and stopping when both output digits are identical. Ex: If the input is: 93 the output is: 93 92 91 90 89 88 Ex: If the input is: 77 the output is: 77 Ex: If the input is: 15 or any number not between 20 and 98 (inclusive),...

  • c++. please show screenshots of output This project will continue to familiarize the student with using...

    c++. please show screenshots of output This project will continue to familiarize the student with using arrays. Store all the function proto-types in project11_funch and store all the functions in project11_func.cpp. Make sure you have proper header comments in each.h,.cpp file. When you run your program, your sample output should show your name. Your report should include the following: 1) project11_func.h 2) project11_func.cpp 3) project11.cpp 4) sample output Write the following functions: a) void fill_array_with_random_nums(int array(), int N): Fill array...

  • Topics: Arrays in C. For this assignment, you will write a C program that uses its...

    Topics: Arrays in C. For this assignment, you will write a C program that uses its first command line parameter to compute and display a histogram of characters that occur in it. Requirements: Your program must compile and run correctly using the gcc compiler on ale. You must write the corresponding function definitions for the following function prototypes: // set all elements of the histogram to zero void init_histogram(int histo[]); // construct the histogram from string void cons_histogram(char string[], int...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

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