Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

write a program that prints a pascal triangle based on the
user input(like how many stages) in an efficient time and
optimized code?

Answer Posted / vamsi krishna

#include<stdio.h>
#include<conio.h>
main()
{
int i,j,n;
clrscr();
printf("enter the highest power");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=0;j<(n-i);j++)
printf(" ");
for(j=0;j<=i;j++)
printf("%d ",c(i,j));
printf("\n");
}
getch();
}
c(int i,int j)
{
int k,N=1,D=1;
if(i==0)
return(1);
if(j==0)
return(1);
for(k=0;k<j;k++)
{
N=N*(i-k);
D=D*(j-k);
}
return(N/D);
}

Is This Answer Correct ?    7 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is linear search?

1143


Why do we use return in c?

1012


Write a program to swap two numbers without using third variable?

1316


What are local static variables? How can you use them?

1154


A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles

1182


Write the syntax and purpose of a switch statement in C.

1109


Explain what are compound statements?

1066


Why do we write return 0 in c?

1074


Can we change the value of static variable in c?

1035


What is wrong with this program statement? void = 10;

1261


write a c program for swapping two strings using pointer

2640


Apart from dennis ritchie who the other person who contributed in design of c language.

1406


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

1208


Explain about the functions strcat() and strcmp()?

1058


Are negative numbers true in c?

1069