Question

Write a function with the function prototype int f(void); that prints out n asterisks, where n...

Write a function with the function prototype

int f(void);

that prints out n asterisks, where n represents the number of times it has been called. If it is called three times for instance, the output will be

*

* *

* * *

Test the function by calling it five times.

(A) Use a static variable inside the function.

(B) Use a global variable inside the function.

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

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

A)

#include <iostream>
#include<cstdlib>
using namespace std;
int f(void)
{
static int n=1;
for(int i=0;i<n;i++)
{
cout<<"*";
}
cout<<endl;
n++;
return n;
}
i
nt main()
{
for(int i=0;i<5;i++)
{
f();
}
return 0;
}

B)

#include <iostream>
#include<cstdlib>
using namespace std;
int n=1;
int f(void)
{
for(int i=0;i<n;i++)
{
cout<<"*";
}
cout<<endl;
n++;
return n;
}

int main()
{
for(int i=0;i<5;i++)
{
f();
}
return 0;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Write a function with the function prototype int f(void); that prints out n asterisks, where n...
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
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