Assume the availability of a function called printStars . The function receives
ID: 3759099 • Letter: A
Question
Assume the availability of a function called printStars. The function receives an int argument . If the argument is positive, the function prints (to standard output ) the given number of asterisks. Thus, if the printStars(8) is called, ******** (8 asterisks) will be printed.
Assume further that the variable starCount has been declared and initialized to a positive integer .
Write some code that prints starCount asterisks to standard output by:
first printing a single asterisk (and no other characters )
then calls printStars to print the remaining asterisks.
cna someone please help me the code needs to be in c code.
Explanation / Answer
Answer:
#include<stdio.h>
void printStars(int n)
{
int i;
if(n>0){
for(i= 0; i<n; i++)
{
printf("*");
}
}
}
void stars(int n)
{
if(n>0)
{
printf("*");
printStars(n-1);
}
}
int main(){
int n;
scanf("%d",&n); //read n
stars(n);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.