Q. Write a program to generate a following @'s triangle?
@ | ||||
@ | @ | |||
@ | @ | @ | ||
@ | @ | @ | @ | |
@ | @ | @ | @ | @ |
Ans.
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c,sp;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
for(r=1; num>=r; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf("@");
printf("\n");
}
getch();
}
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
***********************************/
/*************OUTPUT**************
Enter loop repeat number(rows): 5
@ | ||||
@ | @ | |||
@ | @ | @ | ||
@ | @ | @ | @ | |
@ | @ | @ | @ | @ |
***********************************/
sir can u please tell me in details what is the work of "sp--"..
ReplyDeleteSp-- tell us about the decrease of space in the pattern like
Deletessssss@
sssss@@
ssss@@@
sss@@@@
ss@@@@@
s@@@@@@
Here 's' indicates the decreasing order of space in pattern. Just like sp
this is wrong
ReplyDeleteThis is wrong plz tell correct solution
ReplyDeletethe program is correct
DeleteAnish Pls run it once!!! Program is absolutely correct..
Deletethanku for uploading the code
ReplyDeletetell me the c program for following structure:
ReplyDelete1 1
12 21
123 321
1234 4321
123454321
#include
Deleteint main(void) {
int rows,i,k;
int ary[10];
scanf("%d",&rows);
for(i=1;i<=rows;i++)
{
for(k=1;k<=i;k++)
{
ary[k]=k;
printf("%d",k);
}
printf(" ");
for(k=(k-1);k>=1;k--)
{
printf("%d",ary[k]);
}
printf("\n");
}
return 0;
}
=1; $space--)
ReplyDeleteprintf("    ");
for($c=0; $c<=$r; $c++)
echo "@";
echo"
";
}
?>
import java.util.*;
ReplyDeleteclass Pattern5
{
public static void main(String[] args)
{
System.out.println("Enter the number of rows:");
Scanner sc=new Scanner(System.in);
int num=sc.nextInt(); //Number of rows taking from keyboard
for(int row=1;row<=num;row++) // NUmber of rows
{
for(int space=num;space>row;space--)
{
System.out.print(" ");
}
for(int col=1;col<=row;col++) //column stars printing
{
System.out.print("#");
}
System.out.println();
}
}
}
There is no basic difference between the following programs. But when I run these two they show difference shaped pyramids. Can anybody tell me why?
ReplyDelete................................................................................................
Programe of Q. NO-5 of this blog:
#include
#include
void main()
{
clrscr();
int num=5,r,c,sp;
for(r=1;r<=num;r++)
{
for(sp=num-r;sp>=1;sp--)
{
printf(" ");
}
for(c=1;c<=r;c++)
{
printf("*");
}
printf("\n");
}
getch();
}
........
my programe:
#include
#include
void main()
{
clrscr();
int row, space, star;
for(row = 1; row<=5; row++)
{
for(space = 5-row; space >=0; space--)
{
printf(" ");
}
for(star = 1; star<=row; star++)
{
printf(" * ");
}
printf("\n");
}
getch();
}
Your program is right...thank u..
Delete#include
ReplyDeletemain()
{
int i,j,k,n;
printf("Enter the number of rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=n;k>i;k--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("@");
}
printf("\n");
}
}
12,
ReplyDelete12,13,
13,14,12,
15,12,13,14,
13,14,15,16,12,
16,17,12,13,14,15,
13,14,15,16,17,18,12,
17,18,19,12,13,14,15,16,
13,14,15,16,17,18,19,20,12,
18,19,20,21,12,13,14,15,16,17,
13,14,15,16,17,18,19,20,21,22,12,
how i get this number triangle?? in easy way!! please help me
please tell me the solution of
ReplyDelete&
&
& &
& & &
#Anil Saini
DeleteYour required symbol triangle pattern C program source code solution as:
http://cprogrammingcodes.blogspot.com/2011/09/4design-tringle-praymid.html