Question

In: Computer Science

c program Identify type of library file that need to be used when the program needs...

c program

  1. Identify type of library file that need to be used
    1. when the program needs to returns the absolute value of its integer argument such as : if x is -5, abs(x) is 5.
    2. When the program needs to return a randomly chosen integer between 0 and the value associated with RAND_MAX,
    3. When the program needs to return the base-10 logarithm of x for x>0.0: example if x is 100.0, log 10(x) is 2.0

Solutions

Expert Solution

I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments(read them for better understanding).

When libraries are not given,in some cases (some compilers) warnings will appear and we will get output.But not all the time.

Question no.1

Images of the Code:


Note: If the below code is missing indentation please refer code Images

Typed Code:

/*it is used for input and output operations*/
#include <stdio.h>
/*this is the library that needs to be used for abs()*/
#include <stdlib.h>
int main()
{
/*declaring "a" as integer*/
int a;
printf("Enter a value to return the absolute value: ");
/*taking the value from the user*/
scanf("%d",&a);
/*abs() function returns the absolute value of integer*/
int x= abs(a);
/*printing the absolute value of an integer*/
printf("The absolute value is %d",x);
return 0;
}

/*code ended here*/

Output:

Question no.2

Images of the Code:


Note: If the below code is missing indentation please refer code Images

Typed Code:

/*it is used for input and output operations*/
#include <stdio.h>
/*this is the library that needs to be used for rand()*/
#include <stdlib.h>
int main()
{
/*LOWER values is starting value and UPPER value is last value*/
int LOWER = 0, UPPER;
printf("Enter the value for Upper limit: ");
/*UPPER value is taken from the user*/
scanf("%d",&UPPER);
/*this formula is used to generate the random number
with in a range [LOWER,UPPER]*/
int num = (rand() % (UPPER - LOWER + 1)) + LOWER;
/*printing the random value*/
printf("%d",num);
return 0;
}

/*code ended here*/

Output:

Question no.3

Images of the Code:


Note: If the below code is missing indentation please refer code Images

Typed Code:

/*it is used for input and output operations*/
#include <stdio.h>
/*this is the library that needs to be used for log10()*/
#include <math.h>
/*this is the library that needs to be used for exit()*/
#include <stdlib.h>
int main()
{
/*declaring double value*/
double a;
printf("Enter a value to return log10() value: ");
/*taking the value from the user*/
scanf("%lf",&a);
/*if a value is less than or equal to 0*/
if(a<=0)
{
/*exit the program*/
exit(0);
}
/*apply log10() and storing it in x*/
double x = log10(a);
/*printing the value*/
printf("log10(%lf) = %lf\n", a, x);
return 0;
}
/*code ended here*/

Output:

If You Have Any Doubts. Please Ask Using Comments.

Have A Great Day!


Related Solutions

This problem needs to be solved with source code. I need a C++ program that will...
This problem needs to be solved with source code. I need a C++ program that will help me solve this question. I need it in C++, please. Writing with comments so it maybe cleared. 1.2. We received the following ciphertext which was encoded with a shift cipher: xultpaajcxitltlxaarpjhtiwtgxktghidhipxciwtvgtpilpit ghlxiwiwtxgqadds. 1. Perform an attack against the cipher based on a letter frequency count: How many letters do you have to identify through a frequency count to recover the key? What is...
Need to create a program in C++ that can display/write into a file called marks.txt. I'm...
Need to create a program in C++ that can display/write into a file called marks.txt. I'm not too worried about the functions, but I don't know how to store the different marks into a arrays. Any help would be appreaciated. Here's some details about the assignment. Student marks are kept in a text file as a single column. Each student may have a different number of assessments and therefore scores. The data recorded in the file for each student start...
I need C++ program that Read an input file of text.txt one word at a time....
I need C++ program that Read an input file of text.txt one word at a time. The file should consist of about 500 words. The program should remove all punctuations,keep only words. Store the words in a built-in STL container, such as vector or map.Can someone help with any additional comments that I can understand the logic?thank you
This is a beginner C++ class Your program will be creating 10 library books. Each library...
This is a beginner C++ class Your program will be creating 10 library books. Each library book will have a title, author and publishing year. Each library book will be stored as a structure and your program will have an array of library books (an array of structures). After creating the struct, the next task is to create a new separate array for book genres. You will create this corresponding array of book genres: Mystery, Romance, Fantasy, Technology, Children, etc....
When a user tries to write a file, the file system needs to detect if that...
When a user tries to write a file, the file system needs to detect if that file is a directory so that it can restrict writes to maintain the directory’s internal consistency. Given a file’s name, how would you design NTFS to keep track of whether each file is a regular file or a directory?
c++ language Create a file program that reads an int type Array size 10; the array...
c++ language Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.
Need to check if File is successfully opened? C++ It works when I input the right...
Need to check if File is successfully opened? C++ It works when I input the right txt file. But, it keeps stating, File successfully open." even I put in a non-existing file. Here are the specifications: Develop a functional flowchart and then write a C++ program to solve the following problem. Create a text file named first.txt and write your first name in the file. You will be reading the name of the file from the keyboard as a string,...
A C PROGRAM *Edit/Update I do not need the file loading script, but I am not...
A C PROGRAM *Edit/Update I do not need the file loading script, but I am not against it being included in the answer* I must read off of an excel file (comma separated) to input five different things for a book, all comma separated, there are 360 books in the file. The book title, author, ISBN number, number of pages, and finally the year it was published. Now some of the ISBN or Pg numbers may be missing and will...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT