Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Thank you. Will be waiting for correct answer to reward Write a C program to pri

ID: 3550427 • Letter: T

Question


Thank you.

Will be waiting for correct answer to reward

Write a C program to print the triangle below where the user will be prompted for a number between 1 and 15 representing the highest number of * to be printed. If the value entered is less than 1 or greater than 15 prompt the user to enter a value between 1 and 15 (forStar. c) Write the program using a for loop (whileStar. c) Write the program using a while loop (gotoStar. c) Write the program using a go-to statement(s) If the user entered 10 the following should be output: * ** *** **** ***** ****** ******* ******** ********* *********

Explanation / Answer

//using for loop


#include<stdio.h>

int main()

{

int a;

a=0;

while (a<1 || a>15)

{

printf("enter number of stars : ");

scanf("%d",&a);

if (a<1 || a>15)

printf(" you have entered invalid number. ");

}


int i,j;


for(i=0;i<a;i++)

{

for(j=0;j<=i;j++)

printf("*");

printf(" ");

}


}




//using while loop


#include<stdio.h>

int main()

{

int a;

a=0;

while (a<1 || a>15)

{

printf("enter number of stars : ");

scanf("%d",&a);

if (a<1 || a>15)

printf(" you have entered invalid number. ");

}


int i,j;


i=0;

while(i<a)

{


j=0;

while(j<=i)

{



printf("*");

j=j+1;

}

i=i+1;

printf(" ");



}


}





Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote