Question

write a c program that does not output anything, whose execution time is 1 second (use...

write a c program that does not output anything, whose execution time is 1 second (use nested loops). Then convert the program to Python, and run it using the Python interpreter. How long does the Python version take?

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

#in c program:

#include <stdio.h>
#include<time.h>

int main()

{
double time_check=0;
clock_t start=clock();
int i=0;
while(i<1){
i=i+1;
while(i<1)
i=i+1;
i=i+1;
}
clock_t finish=clock();
time_check += (double)(finish-start) / CLOCKS_PER_SEC;
printf("time is: %f seconds",time_check);
return 0;
}

#in python:

import timeit
i=0
start=timeit.timeit()
while(i<1):
i=i+1
while(i<1):
i=i+1
i=i+1
end=timeit.timeit()
print("the time is",end-start)

#if you have any doubt comment below..if you like give thumbs up...

Add a comment
Know the answer?
Add Answer to:
write a c program that does not output anything, whose execution time is 1 second (use...
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
  • Using python, create a program using nested loops to write a function called substring(s,b) that returns...

    Using python, create a program using nested loops to write a function called substring(s,b) that returns True or False depending on whether or not b is a substring of s. For example: String: "Diamond" Substring: "mond" The code will then state that this is true and "mond" is a substring of "Diamond". Example of what the program should output: Enter string: Tree Enter substring: Tre Yes, 'Tre' is a substring of 'Tree' Limitation: This program cannot use "find()" and "in"...

  • 4.12 LAB: Smallest number Write a program whose inputs are three integers, and whose output is...

    4.12 LAB: Smallest number Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 the output is: 3 I have to write this in python, having a hard time deciding how to approach this. Thank you!

  • Write a program whose inputs are three integers, and whose output is the smallest of the three values.

    # Python Write a program whose inputs are three integers, and whose output is the smallest of the three values. a.) Write out the steps of a computational thinking process b.) Write out the Pseudocode c.) Write out the Python code

  • to be done in c language. follow prompt Second Program: triples.c 8. Create a program named...

    to be done in c language. follow prompt Second Program: triples.c 8. Create a program named triples.c "C How to Program", 8th edition, problem 4.27 on page 154. In other editions, it may be on a different page Here's the problem... A right triangle can have sides that are all integers. The set of 3 integers for the sides of a right triangle is called a Pythagorean triple Write a C program to find all of the triples with hypotenuse...

  • Write a C++ program. Please use Codeblocks, show output. And provide all three files as asked...

    Write a C++ program. Please use Codeblocks, show output. And provide all three files as asked and instructions on the combination and anything else. The menu must ask how many names they wish to enter. Max is up to 20. And the end of each prompt please ask “Do you want to continue or Quit” so after each execution of the program it doesn’t automatically quit but gives the option to either repeat or quit through selection.

  • Write a program whose input is two integers, and whose output is the first integer

    5.20 (Ch 5) HW: Output range with increment of 10 Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer Ex: If the input is: -15 30 Then the output is: 15 -5 5 15 25 Ex: If the second integer is less than the first as in 20 5, the output is: Second integer can't be less than the...

  • 1. Write a C++ program to output a framed greeting. The program will produce five lines...

    1. Write a C++ program to output a framed greeting. The program will produce five lines of output. The first line begins the frame. It is a sequence of * characters as long as the person's name, plus some characters to match the salutation ("Hello, "), plus a space and an * at each end. The line after that will be an appropriate number of spaces with an * at each end. The third line is an *, a space,...

  • Use python to write a code Problem 1: Environmental Monitoring You are given a nested list...

    Use python to write a code Problem 1: Environmental Monitoring You are given a nested list in which the sublists contain tuples! Example: samples = [ [('frog','H'), ('toad','D') ], [('trout','H'), ('salmon','S'), ('catfish','H')] ] Here each species is either healthy H, dead D or sick S. Access the health status of a specified animal using multi-indexing. Count how many are healthy using two nested for loops. List will be bigger and different on each version.

  • Write a program that obtains the execution time of selection sort, radix sort, bubble sort, merge...

    Write a program that obtains the execution time of selection sort, radix sort, bubble sort, merge sort, quick sort, and heap sort for input size 50000, 100,000, 150,000, 200,000, 250,000, and 300,000. Your program should create data randomly and print a table like this: In the same program, obtain the execution time of selection sort, radix sort, bubble sort, and heap sort for input size 2,000,000, 3,000,000, 4,000,000, and 5,000,000. (Hint: You can use the code template below to obtain...

  • Write a program whose input is a string which contains a character and a phrase, and...

    Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: t this is a sentence with many t's the output is: 4 PLEASE WRITE USING PYTHON

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