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

i need help with c program assignment. Write a program that displays an isoscele

ID: 3665179 • Letter: I

Question

i need help with c program assignment.

Write a program that displays an isosceles triangle. The program will ask the user whether they want the triangle
oriented so that the base is at the top or the bottom. The program will let the user specify the character used to
construct the triangle. The program will also let the user specify the size of the base of the triangle in characters.
(Note: The base should be an odd integer in the range 1-29 inclusive.)
Your program must include appropriate input validation.
Sample output from a program that satisfies the requirements of this exercise is given below.

Example #1:

This program prints an isosceles triangle.
The user selects the orientation of the triangle,
the character the triangle is constructed from,
and the width of triangle base in characters.
If you want the base of the triangle to be at the top, enter 1.
If you want the base of the triangle to be at the bottom, enter 2.
Enter 1 or 2: 1
Enter the character that should be used to construct the triangle: ~
Enter the width of the base (must be an odd whole number 1-29): 7

This program prints an isosceles triangle.
The user selects the orientation of the triangle,
the character the triangle is constructed from,
and the width of triangle base in characters.
If you want the base of the triangle to be at the top, enter 1.
If you want the base of the triangle to be at the bottom, enter 2.
Enter 1 or 2: 2
Enter the character that should be used to construct the triangle: $
Enter the width of the base (must be an odd whole number 1-29): 29
$
$$$
$$$$$
$$$$$$$
$$$$$$$$$
$$$$$$$$$$$
$$$$$$$$$$$$$
$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ (pyramid)

Explanation / Answer

#include<conio.h>
#include<stdio.h>
#include<process.h>

char pchar;
int w;
void getinfo()
{
   clrscr();
   printf(" Enter character to used to print Traingle");
   fflush(stdin);
   scanf("%c",&pchar);
   getagain:
   printf(" Enter the width of the base (must be an odd numberr 1-29)");
   scanf("%d",&w);
   if(w%2==0 || (w > 29 || w <1))
   {
       goto getagain;
   }
}
void print(int base)
{
int i,j,k;
if(base==1)
{
   for(i=(w/2)+1;i>=1;i--)
   {
       for(j=1;j<=i;j++)
       {
           printf("%c",pchar);
       }
       for(k=i-1;k>=1;k--)
       {
           printf("%c",pchar);
       }
       printf(" ");

   }

}
if(base==2)
{
   for(i=1;i<=(w/2)+1;i++)
   {
       for(j=1;j<=i;j++)
       {
           printf("%c",pchar);
       }
       for(k=i-1;k>=1;k--)
       {
           printf("%c",pchar);
       }
       printf(" ");

   }
}

}
void main()
{
   int ch;
   while(1)
   {
       fflush(stdin);
       printf(" Print the Isoscles Triangle ");
       printf(" 1. Base on Top ");
       printf(" 2. Base on Bottom");
       printf(" 3. Exit");
       printf(" Enter your Choice ");
       scanf("%d",&ch);
       switch(ch)
       {
           case 1:
               getinfo();
               print(1);
               getch();
               break;
           case 2:
               getinfo();
               print(2);
               getch();
               break;

           case 3:
               exit(0);
       }

   }
}