QuestionQuestion

1. Reading Binary File and Addition: Write a C program that reads a N number of integer pairs n1 and n2 from a binary file f and for each of the N pairs n1 and n2, display their summation (i.e., n1 + n2) followed by a newline character in the standard output. Your program should take the name of the binary file f as a command line argument. The first 4-bytes of the binary file constitutes the value N ; the number of integer pairs to follow. For each of the N integer pairs, display their summation in the ASCII format in the standard output. Each element of the pairs is represented as a 4-byte integer.
Please name this C file “Problem1.c”

2. Number Addition: Write a C program that reads N number of integer pairs n1 and   n2 from an ASCII file fin and for each of the N pairs n1 and n2, store their summation (i.e., n1 + n2)   in a binary file fout. Your program should take the name of the binary files fin (argument 1) and fout (argument 2) as command line arguments.
The first line of the fin file contains the value N and N pairs of integers n1 and n2 follow. For each such pair of n1 and n2, store the value of n1 + n2 in the binary file fout. We do not need to print newlines after each summation.
Please name this C file “Problem2.c”

3. Big Integer Addition: Int datatype can hold an integer of size 4 bytes, long long int can hold up to 8 bytes however sometimes the number required for calculations exceeds this. For example, often while doing cryptographic operations (e.g., encryption, decryption) you are required to add and multiply integers that are much bigger than standard libraries can support.
Your goal is to implement the addition operation of big integers and print the result to standard output.
These integers WILL NOT fit in a typical primitive data type.
You’ll be required to store these integers in a different form. For example, you can store these in a char array where each digit in such numbers occupy one position in that array.
You will be provided a skeleton C file (Inside the “Problem 10” folder). Your objective is to finish coding the “add and print” function which takes care of the addition and prints the results to the standard output.
Your program should take the name of the input file as a command line argument. Just like the following
s h e l l% . / Problem10 <INPUT FILE>
Please name this C file “Problem3.c”

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

int main(int argc, char** argv) {
   
    FILE * f;
    int i;
    int N, n1, n2;
   
    // be sure that the user had passed an argument to the
    if (argc < 2) {
       return EXIT_FAILURE;
    }
    // open the binary file
    f = fopen(argv[1], "rb");
   
    if (f != NULL) { // if the file can be opened
       // read the first 4 byte integer
       fread(&N, sizeof(int), 1, f);
      
       // iterate over the file
       for (i = 0; i < N; i++) {
            // read 2 4-bytes integers
            fread(&n1, sizeof(int), 1, f);
            fread(&n2, sizeof(int), 1, f);
            // print out their sum
            fprintf(stdout, "%d\n", n1 + n2);
       }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$76.00 $38.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats