Question

In: Computer Science

C programming language. **I am aware that I am only supposed to ask one question so...

C programming language.

**I am aware that I am only supposed to ask one question so if you cant do all of this could you please do part 2? thank you!

This lab, along with your TA, will help you navigate through applying iterative statements in C. Once again we will take a modular approach to designing solutions to the problem below. As part of the lab you will need to decide which C selection structure and iterative structure is best suited for a particular function. You will have the option to use "if", "switch", "while", "do-while", and/or "for" statements for the below problem.

Labs are held in a “closed” environment such that you may ask your TA questions. Please use your TAs knowledge to your advantage. You are required to move at the pace set forth by your TA. Have a great time! Labs are a vital part to your education in CptS 121 so work diligently.

Tasks:

1.    a. With your team, write a program that reads in each of the integer values in a file and determines if the sum of the integers is prime. Use functions where appropriate!

     b. Determine if the sum of the individual digits, in the sum of the integers, is prime. Use functions where appropriate!

2. With your team, write a program that determines the factorial of n, represented n!, where n is entered by the user. Make sure that your program checks to see if n is greater than or equal to 0. As long as n is negative your program should continue to prompt for another value for n. Recall 0! is equal to 1 and 1! is also equal to 1. The factorial of a number such as n! is equal to n * (n – 1) * (n – 2) *… * 1. Use functions where appropriate!

3. Write a program that determines the Fibonacci number for the nth term. Recall, the first Fibonacci number is 0 and the second Fibonacci number is 1. The next number in the sequence is always determined by the sum of the previous two terms or numbers in the sequence. Fib (n) = Fib (n-1) + Fib (n-2). The n value should be entered by the user. Use functions where appropriate!

4. Write a program that generates a random number between -100 to 100 and requires that the user guesses which number was generated. If the user guesses too high, then the program should say so. If the user guesses too low, then the program should say so again. The program should continue to loop until the user guesses the correct number. If the user guesses a number outside the range of -100 to 100, then the program should just prompt the user to re-enter a number without indicating if the guess was too high or too low. Keep track of the total number of guesses taken by the user. Use nested loops to solve this problem. Use functions where appropriate!

Solutions

Expert Solution

SOLUTION FOR PART 2:-

CODE FOR THE FOLLOWING PROGRAM:-

#include <stdio.h>

int main()
{
    //variables used in the program
    int factorial=1,n;
    //If user enter negative value of n prompt user to enter again
    do{
        printf("Enter the number whose factorial you want to calculate: \n");
        scanf("%d",&n);
    }while(n<0);
    
    //If n is greater than 0 calculate it's factorial
    if(n>0){
        for(int i=1;i<=n;i++){
            factorial*=i;
            }
            printf("The factorial of %d is %d",n,factorial);
        }
    //If the number is zero then print 1
    else if(n==0){
        printf("The factorial of %d is 1",n);
    }
    return 0;
}

STEPS FOR FINDING FACTORIAL:-

Our program is asking user to enter a number whose factorial user want to find, if he/she enters a negative number we will prompt them to enter a value again because factorial of negative number doesn't exsist. Then we will check whether the entered value is 0 or greater than 0 if it is 0, we will simply print 1 as its factorial, if it is greater than 0 we will calculate it's factorial using a for loop and then print it's factorial.

SCREENSHOT OF THE PROGRAM AND SAMPLE OUTPUT:-

SAMPLE OUTPUT:-

HAPPY LEARNING


Related Solutions

C programming language. **I am aware that I am only supposed to ask one question so...
C programming language. **I am aware that I am only supposed to ask one question so if you cant do all of this could you please do part 3? thank you! This lab, along with your TA, will help you navigate through applying iterative statements in C. Once again we will take a modular approach to designing solutions to the problem below. As part of the lab you will need to decide which C selection structure and iterative structure is...
I am building a game in C programming language where I need to add objects of...
I am building a game in C programming language where I need to add objects of various length into a game board. The game board is 8X8 and we must account for the boundaries for the board and not go over them with our objects. The boards upper left corner is at 0x0 and we must return 1 if it fits and -1 if it does not fit. I have the following 2 functions to start with: ```int add_object_vert(int r,...
I thought for this type of question I am supposed to make a chart with the...
I thought for this type of question I am supposed to make a chart with the inventory, purchases, sales, etc., but instead, these questions are throwing me off for the little understanding I have on this new topic... Kayla Company uses the perpetual inventory system and the LIFO method. The following information is available for the month of June: June 1 Beginning inventory 200 units @ $5 12 Purchase on account 400 units @ $6 15 Sales on account 440...
I am not aware of GR, but due to curiosity i have a question in my...
I am not aware of GR, but due to curiosity i have a question in my mind. Please let me know if it is inappropriate to ask here. My question is about singularity. I am under the assumption that singularity means in mathematical terms equivalent to a discontinuity in a function. My question is what type of discontinuity are the ones corresponding to Penrose-Hawking singularity theorems and also to the the naked singularity ? by type i mean removable (left...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
You are using ONLY Programming Language C for this: In this program you will calculate the...
You are using ONLY Programming Language C for this: In this program you will calculate the average of x students’ grades (grades will be stored in an array). Here are some guidelines to follow to help you out: 1. In your program, be sure to ask the user for the number of students that are in the class. The number will help in declaring your array. 2. Use the function to scan the grades of the array. To say another...
Only Program in C for this. No other programming language is allowed. Using a function, we...
Only Program in C for this. No other programming language is allowed. Using a function, we will add a range of values of an array. The range is going to be determined by the user. In this example, if you put the following array down as: 1.5 -5.6 8.9 4.6 7.8 995.1 45.1 -5964.2 … and the user tells you to add from the 3rd element to the 6th element, your program is going to need to add the values:...
Be sure to use only C for the Programming Language in this problem. Before we start...
Be sure to use only C for the Programming Language in this problem. Before we start this, it is imperative that you understand the words “define”, “declare” and “initialize” in context of programming. It's going to help you a lot when following the guidelines below. Let's begin! Define two different structures at the top of your program. be sure to define each structure with exactly three members (each member has to be a different datatype). You may set them up...
The following is for C programming language: I want to scan for initials in a line...
The following is for C programming language: I want to scan for initials in a line of text. my line of text is as follows: 12345 3.5000 a j 12346 4.1000 s p The first number represents the student ID, the second number represents the gpa, the third character represents the first initial and the fourth character represents the last initial of the student. My text file contains these values. The following is my code: fscanf(fp, "%d %c %c", &studentID,...
The following question must be answered in the C programming language and may not be written...
The following question must be answered in the C programming language and may not be written in C++ or any other variation. Problem 5 This problem is designed to make sure you can write a program that swaps data passed into it such that the caller's data has been swapped. This is something that is done very frequently in manipulating Data Structures. The Solution / Test Requirements I want your program to demonstrate that you understand how to swap information...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT