Write a function called counter using function declaration n

Write a function called \"counter\" using function declaration notation with the following parameters & return value: Parameters: This function has no parameters. Return value: A new function that returns a single number - one (1). However, every time this function is invoked (called) in the future, this function will return a number that is one greater than the previous time it was invoked (called). For example: var count = counter));//call the \"counter\" function and assign the return value (function) to count count();//returns 1; count();//returns 2; count));//returns 3;

Solution

/*

Following is the C program for the given problem statement.

*/

#include <stdio.h>
#include <stdlib.h>

int count=1; // count variable is declared as a global variable.
int counter()
{
count++;
return count-1;
}

int main()
{
printf(\"%d\ \",counter());
printf(\"%d\ \",counter());
return 0;
}

 Write a function called \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site