Question

_delay_ms( ) function accepts only a constant in milliseconds as parameter, write a function void delay(int...

_delay_ms( ) function accepts only a constant in milliseconds as parameter, write a function void delay(int a) that produces a delay where “a” is a variable in C

Homework Answers

Answer #1

i'm writing a function to produce a milliseconds of delay, you can run this code on any c ide:

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

void delay(int a){//a is number of seconds
 int mls = 1000*a; //convert to milliseconds...if you want a to be in milliseconds just comment this line
 clock_t f = clock();
 while(clock()< f+mls){}// do nothing i.e. create delay
}

void main()
{
int i;
for (i= 1; i <= 10; i++) {
delay(1);

printf("%d second\n", i );

}

}
 
Know the answer?
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
Similar Questions
[ Write in C not C++] Define a C function void placeElements(int *a, int i, int...
[ Write in C not C++] Define a C function void placeElements(int *a, int i, int j) that inter-exchange the array elements at indexiandj. For a[] = {5,7,4,2,1},a callto placeElements(a,2,4) makesa[] = {5,7,1,2,4}. [8]
javascript 1.Write a function delay that accepts two arguments, a callback and the wait time in...
javascript 1.Write a function delay that accepts two arguments, a callback and the wait time in milliseconds. Delay should return a function that, when invoked waits for the specified amount of time before executing. HINT - research setTimeout(); 2.Create a function saveOutput that accepts a function (that will accept one argument), and a string (that will act as a password). saveOutput will then return a function that behaves exactly like the passed-in function, except for when the password string is...
The function martian() has a prototype of: void martian(int ch); and an implementation of: void (int...
The function martian() has a prototype of: void martian(int ch); and an implementation of: void (int ch) { printf("%c" ,ch); return; } it is called from main as int md= 0x45; martian(md); What is printed on the screen?
C++ only: Please implement a function that accepts a string parameter as well as two character...
C++ only: Please implement a function that accepts a string parameter as well as two character arguments and a boolean parameter. Your function should return the number of times it finds the character arguments inside the string parameter. When both of the passed character arguments are found in the string parameter, set the boolean argument to true. Otherwise, set that boolean argument to false. Return -1 if the string argument is the empty string. The declaration for this function will...
Write a method called countChar which accepts a string parameter and a character parameter and returns...
Write a method called countChar which accepts a string parameter and a character parameter and returns an integer, that is: int countChar (String s, char c) This method should count the number of occurrences of the character c within the string s, and return the count to the caller. Also write a main method that tests countChar. All of the print statements and user interaction belong in the main method, not in countChar.
Using C++ Write a template function that accepts an integer parameter and returns its integer square...
Using C++ Write a template function that accepts an integer parameter and returns its integer square root. The function should return -1, if the argument passed is not integer. Demonstrate the function with a suitable driver program .
//1. Write out the output for eaching of following: /* Consider this function. void myMethod( int...
//1. Write out the output for eaching of following: /* Consider this function. void myMethod( int counter) { if(counter == 0) return; else { System.out.println(""+counter); myMethod(--counter); return; } }
Write a function that accepts an int array arr, the array’s size sz and integer n,...
Write a function that accepts an int array arr, the array’s size sz and integer n, the function should create a new array that it’s n times the array arr. The fucntion copy the content of arr to the new array n times. The Example arr = {5, 2, 1} n=3 Newarr = {5, 2, 1, 5, 2, 1, 5, 2, 1} (c++)
Given the following function in C++: int main(void) { int a = 2; int b =...
Given the following function in C++: int main(void) { int a = 2; int b = myFunction(a); a = b + 1; b = myFunction(a); cout << ”b = ” << b << endl; return 0; } int z = myFunction(int x) { static int n = 0; n = n + 1; int z = x + n; return z; } What is printed by the cout on the screen?
Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than...
Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by "seconds". End with a newline. Example output for ounces = 7: 42 seconds import java.util.Scanner; public class PopcornTimer { public void printPopcornTime(int bagOunces) { /* Your solution goes here */ } public static void main (String [] args) { PopcornTimer popcornBag = new PopcornTimer();...