Question

Question:Write a C program to input an integer k. Compute 10^k and store the result in...


Question:Write a C program to input an integer k. Compute 10^k and store the result in a double variable. Display
the result on the standard output using printf.

Implementation
° The program is named lab4c . c. Use the given template lab4c .c (BELOW ) and fill in your code.

° Assume that the input integer k is small enough so that 10^k can be stored in a double variable
named my_double.

° Display on the standard output the result using the printf statement as follows:
printf( "% . 15lf\n", my_double );
--------------------------------------------------------------

Sample Inputs/Outputs

indigo 152 % a.out
Enter an integer>0
1.000000000000000
indigo 153 % a.out
Enter an integer>3
1000.000000000000000
indigo 154 % a.out
Enter an integer>12
1000000000000.000000000000000
indigo 155 % a.out
Enter an integer>15
1000000000000000.000000000000000
indigo 156 % a.out
Enter an integer>-1
0.100000000000000
indigo 157 % a.out
Enter an integer>-10
0.000000000100000
indigo 158 % a.out
Enter an integer>-14
0.000000000000010
indigo 159 % a.out
Enter an integer>-15
0.000000000000001
indigo 160 % a.out
Enter an integer>—16
0.000000000000000

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

#include <stdio.h>

void power_of_ten( receive k and my_double from main function )
{

   /* Add your code here */

}  /* end power_of_ten */

main()
{
   int k;
   double my_double;
   
   scanf( "%d", &k );
   
   power_of_ten( pass k and my_double to the function );
   /* Hint: my_double must be passed by reference (i.e., using a pointer). */
   
   /* Do not modify the following line. */
   printf( "%.15lf\n", my_double );
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here I've provided the code.

*** CODE STARTS HERE ***

#include <stdio.h>

void power_of_ten( int k, double *mydouble )
{

/* Add your code here */
double result = 1;
  
// compute power k times
while (k--) {
result = result * 10;
}

*mydouble = result;
} /* end power_of_ten */

main()
{
int k;
double my_double;

scanf( "%d", &k );

power_of_ten( k, &my_double);
/* Hint: my_double must be passed by reference (i.e., using a pointer). */

/* Do not modify the following line. */
printf( "%.15lf\n", my_double );
}

*** CODE ENDS HERE ***

for any queries please do comment.

Add a comment
Know the answer?
Add Answer to:
Question:Write a C program to input an integer k. Compute 10^k and store the result in...
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
  • Convert the C program into a C++ program.Replace all C input/output statements with C++ statements (cin,...

    Convert the C program into a C++ program.Replace all C input/output statements with C++ statements (cin, cout, cin.getline) . Re-make the func function by the following prototype: void func( double, double &); #include int user_interface(); double func(double); void print_table(); int main (int argc, char *argv[]) {    print_table(user_interface());    return 0 ; } int user_interface(int val){    int input = 0;    printf("This function takes in x and returns an output\n");    printf("Enter Maximum Number of X:");    scanf("%d", &input);...

  • C program--write a program to find whether the given number of three digits is an integer...

    C program--write a program to find whether the given number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is since 3**3 + 7**3 + 1**3 = 371. Output: Enter a number, or * to quit : 432 4**3 + 3**3 + 2**3 is not = 432 Enter a number, or * to quit : 371 3**3 + 7**3 + 1**3 is = 371...

  • 1. Specification Write a C program to implement a simple calculator that accepts input in the...

    1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...

  • Create another program that will prompt a user for input file. The user will choose from...

    Create another program that will prompt a user for input file. The user will choose from 4 choices: 1. Display all positive balance accounts. 2. Display all negative balance accounts. 3. Display all zero balance accounts. 4. End program. C PROGRAMMING my code so far #include<stdlib.h> #include<stdio.h> int main(void) { int request; int account; FILE *rptr; char name[20]; double balance; FILE *wptr;    int accountNumber;    if((wptr = fopen("clients.dat","w")) == NULL) { puts("File could not be opened"); } else {...

  • Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the O...

    Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the OpenMP parallel program much longer? Serial Program #include <stdio.h> #include <string.h> #include <time.h> int main(){    char str[1000], ch;    int i, frequency = 0;    clock_t t; struct timespec ts, ts2;       printf("Enter a string: ");    gets(str);    int len = strlen(str);    printf("Enter a character...

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • (Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byt...

    (Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byte unsigned int variable. Write a program that inputs four characters from the keyboard and passes them to function packCharacters. To pack four characters into an unsigned int variable, assign the first character to the unsigned intvariable, shift the unsigned int variable left by 8 bit positions and combine the unsigned variable with the second character using the bitwise inclusive OR operator....

  • Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int...

    Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...

  • c++ please (1) Write a program that prompts the user to enter an integer value N...

    c++ please (1) Write a program that prompts the user to enter an integer value N which will rpresent the parameter to be sent to a function. Use the format below. Then write a function named CubicRoot The function will receive the parameter N and return'its cubic value. In the main program print the message: (30 Points) Enter an integer N: [. ..1 The cubic root of I.. ] is 2 update the code om part and write another function...

  • Write a program whose input is two integers and whose output is the two integers swapped....

    Write a program whose input is two integers and whose output is the two integers swapped. Write in C language 7.3 LAB: Swapping variables Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 38 then the output is: 83 Your program must define and call a function. SwapValues returns the two values in swapped order. void SwapValues(int* userVali, int* userVal2) ACRIVITY 7.3.1: LAB: Swapping variables 0/10 ] main.c...

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