pascal triangle program

Answers were Sorted based on User's Feedback



pascal triangle program..

Answer / azad sable, chiplun

void main()
{
int i,j,k,t,f1,f2,f3,z,sp;
sp=20;
clrscr();
for(i=0;i<=4;i++)
{
for(k=0;k<sp-1;k++)
printf("");
sp=0;
for(j=0;j<=i;j++)
{
f1=f2=f3=1;
t=i;
while(t!=0)
{
f1=f1*t;
t--;
}

t=j;
while(t!=0)
{
f2=f2*t;
t--;
}
t=i-j;

while(t!=0)
{
f3=f3*t;
t--;
}
z=f1/(f2*f3);
printf("%4d",z);
}
printf("\n");
}
getch():
}

Is This Answer Correct ?    1 Yes 0 No

pascal triangle program..

Answer / sevak.yatrik777

with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
with Ada.Text_Io; use Ada.Text_Io;

procedure Pascals_Triangle is
type Row is array(Positive range <>) of Integer;
type Row_Access is access Row;
type Triangle is array(Positive range <>) of Row_Access;
function General_Triangle(Depth : Positive) return
Triangle is
Result : Triangle(1..Depth);
begin
for I in Result'range loop
Result(I) := new Row(1..I);
for J in 1..I loop
if J = Result(I)'First or else J =
Result(I)'Last then
Result(I)(J) := 1;
else
Result(I)(J) := Result(I - 1)(J - 1) +
Result(I - 1)(J);
end if;
end loop;
end loop;
return Result;
end General_Triangle;
procedure Print(Item : Triangle) is
begin
for I in Item'range loop
for J in 1..I loop
Put(Item => Item(I)(J), Width => 3);
end loop;
New_Line;
end loop;
end Print;
begin
Print(General_Triangle(7));
end Pascals_Triangle;

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

what would be the output of the following program main() { int a[] = {1,2,3,4,5}; int *ptr = {a,a+1,a+2,a+3,a+4}; printf("%d %d %d %d",a,*ptr,**ptr,ptr); } }

1 Answers  


You are given a string which contains some special characters. You also have set of special characters. You are given other string (call it as pattern string). Your job is to write a program to replace each special characters in given string by pattern string. You are not allowed to create new resulting string. You need to allocate some new memory to given existing string but constraint is you can only allocate memory one time. Allocate memory exactly what you need not more not less.

2 Answers   Microsoft,


What is the meaning of this decleration? unsigned char (*pArray[10][10]); please reply.

1 Answers  


could u able to tell about suresoft technical session

1 Answers  


Write c-code for 5+55+555+5555+55555+555555+5555555. Output will be it's answer...

4 Answers   TCS,






write a c program for print your name .but,your name may be small letter mean print a capital letter or your name may be capital letter mean print a small letter .example \\enter ur name : sankar The name is: SANKAR (or) enter your name:SAnkar The name is:saNKAR

5 Answers  


How to find the given no is odd or even without checking of any condition and loops. (Hint: Using array)

4 Answers  


what is the difference between NULL('\0') and 0?

14 Answers   Microsoft,


sir i got 146 correct question & i have also the advantage of height so will they consider my marks as 146+3=149.can any body tell me how they consider my height marks.

1 Answers  


Is c dynamically typed?

0 Answers  


Please send me WIPRO technical question to my mail ID.. its nisha_g28@yahoo.com please its urgent

0 Answers  


Are the expressions * ptr ++ and ++ * ptr same?

0 Answers  


Categories