Question

Using C programming language

Question 1 a) through m)

Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each stepf. Comment out the calls for f1 and f2. Keep the assignment of a value to x and the print to check that it was properly set.k. Why do we go through all this rigamarole with addresses when we want to change a value in a function? Because in C (and ma

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

Note:

1. Change the variable names as per the requirement.

2. Comment the code that you do not need, every part is well separated.

#include <stdio.h>

int f1(int x)

{

return (x%100)/10;

}

int f2(int x)

{

return (x%10);

}

void f3(int *x)

{

printf("In f3: %d\n",(*x));

}

void f3_modified(int *x)

{

(*x) = (*x) + 4;

}

void f4(int y, int* addr1, int* addr2)

{

*addr1 = (y%100)/10;

*addr2 = (y%10);

}

int main()

{

// part(a)

while(1)

{

printf("Enter a number between 10 and 99:");

int x;

scanf("%d",&x);

if(x >= 10 && x <= 99)

{

break;

}

else

{

printf("Not in range!\n");

}

}

printf("\n");

// part(b)

int var1 = 59;

int out1 = var1/10;

printf("out1: %d\n",out1);

printf("\n");

// part(c)

int var2 = 59;

int out2 = var2%10;

printf("out2: %d\n",out2);

printf("\n");


// part(d);

int var3 = 145;

printf("var3: %d\n",var3);

int out3 = f1(var3);

printf("f1(%d) = %d\n",var3,out3);

printf("\n");

// part(e)

int var4 = 1345;

printf("var4: %d\n",var4);

int out4 = f2(var4);

printf("f2(%d) = %d\n",var4,out4);

printf("\n");

// part(g)

int var5 = 25;

printf("Before calling f3() from main: %d\n",var5);

f3(&var5);

printf("After calling f3() from main: %d\n",var5);

printf("\n");

// part(h)

int var6 = 87;

printf("Before calling f3_modified() from main: %d\n", var6);

f3_modified(&var6);

printf("After calling f3_modified() from main: %d\n", var6);

printf("\n");

// part(l)

int x = 135;

int num_of_tens, remainder;

f4(x,&num_of_tens,&remainder);

printf("x = %d\n", x);

printf("number of tens = %d\n",num_of_tens);

printf("reaminder = %d\n",remainder);

}

Add a comment
Know the answer?
Add Answer to:
Using C programming language Question 1 a) through m) Exercise #1: Write a C program that...
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
  • Exercise #1: Write a C program that contains the following steps (make sure all variables are...

    Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. Commenting out the existing coding, write the code to divide a...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You...

    Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You can initialize the variables to any legal value of your choosing. Next, declare and initialize a pointer variable to each of the variables Using printf), output the following: The address of each of the first three variables. Use the "Ox%x" format specifier to print the addresses in hexadecimal notation The value of each variable. They should equal the value you gave...

  • Please help me write in C++ language for Xcode. Thank you. In this lab you are...

    Please help me write in C++ language for Xcode. Thank you. In this lab you are going to write a time card processor program. Your program will read in a file called salary.txt. This file will include a department name at the top and then a list of names (string) with a set of hours following them. The file I test with could have a different number of employees and a different number of hours. There can be more than...

  • C++ CODE /* This is program project 2 on page 695. * Before you begin the...

    C++ CODE /* This is program project 2 on page 695. * Before you begin the project, please read the project description * on page 695 first. * * Author: Your Name * Version: Dates */ #include <iostream> #include <cmath> #include <cassert> using namespace std; class Fraction { public: // constructor Fraction(int a, int b); // generate a fraction which is a/b Fraction(int a); // generate a fraction which is a/1 Fraction(); // generate a fraction which is 0/1. i.e...

  • 11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl...

    11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...

  • USING C++ PROGRAM Instructions - Part C Write a program that has three functions: All characters...

    USING C++ PROGRAM Instructions - Part C Write a program that has three functions: All characters printed should be in White ► Call the first function from main().Print "I'm in main" (as shown in example) > Print "I'm in function 1" in the first function. Call the second function. ► Print "I'm in function 2” in the second function and then ask the user to enter a float value. Enter 25 Call a third function and pass the value to...

  • C++ CODE /* This is program project 2 on page 695. * Before you begin the...

    C++ CODE /* This is program project 2 on page 695. * Before you begin the project, please read the project description * on page 695 first. * * Author: Your Name * Version: Dates */ #include <iostream> #include <cmath> #include <cassert> using namespace std; class Fraction { public: // constructor Fraction(int a, int b); // generate a fraction which is a/b Fraction(int a); // generate a fraction which is a/1 Fraction(); // generate a fraction which is 0/1. i.e...

  • C - Language Create a recursive function to print a multi-digit number vertically. For example, 2378...

    C - Language Create a recursive function to print a multi-digit number vertically. For example, 2378 should be printed as 2 3 7 8 Be sure to test your program with numbers of different length. The recursive function should return an int and take an int as a parameter. The function should have a base case where the parameter is 0 and this should return 0 Define a temp variable using the remainder operator where temp is equal to the...

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