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 / abhinav
call this recursive routine:
void pascal(int n)
{
if(n==1) {
printf("%d \n", n);
return;
}
pascal(n-1);
int i;
for(i=1;i<=n; i++)
printf("%d ",i);
for(i=n-1;i>=1; i--)
printf("%d ",i);
printf("\n");
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How can I make sure that my program is the only one accessing a file?
write a program in c language to print your bio-data on the screen by using functions.
c language interview questions & answer
Write a code to remove duplicates in a string.
Do you know the difference between malloc() and calloc() function?
Which built-in library function can be used to match a patter from the string?
What is include directive in c?
Can you please explain the difference between exit() and _exit() function?
What do you mean by a local block?
How would you use the functions fseek(), freed(), fwrite() and ftell()?
When we use void main and int main?
Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.
What is the use of structure padding in c?
Is main an identifier in c?
main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }