Sunday, 10 November 2013

Drow Right Triangle using a C programming

#include<stdio.h>
 #include<conio.h>
void main() /* we can use "int main" in this place */
{
int i,j,k,n; /*intializing the variables and data type*/
printf("Please enter the rows for the right andled triangle \n");
scanf("%d",&n);
/*Loop for the uppart part of the pattern*/
for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
for(k=n;k>i;k--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
/*loop for lower part */
for(i=2;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
for(k=i;k<n;k++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
/* Run tis program on your pc .. ........ then comment here what happend */
the output of this program is look like this below......

0 comments: