Write a C program to get the desired output.


1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
.
.
.
1 n..............n 1
Note: n is a positive integer entered by the user.

Answer Posted / sandip pal

#include<stdio.h>
#include<conio.h>
int ncr(int,int);
int fact(int);
void main()
{
int i,j;
clrscr();
for(i=0;i<=5;i++)
{
printf("\n\n");
for(j=0;j<=5-i;j++)
printf(" ");
for(j=0;j<=i;j++)
printf(" %2d ",ncr(i,j));
}
getch();
}
int ncr(int n,int r)
{
int f;
f=fact(n)/(fact(n-r)*fact(r));
return f;
}
int fact(int n)
{
if(n==0)
return 1;
else
n=n*fact(n-1);
return n;
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Suggesting that there can be 62 seconds in a minute?

586


write a program to print largest number of each row of a 2D array

1860


develop a breakfast order booking system using Functions, Structures and Arrays. The system is to support the operations shown to the user in the following system’s menu: Welcome to Asim's Restaurant Select an operation? 1 Make a breakfast order 2 Modify existing order 3 Cancel existing order 4 Print Bill 5 Exit Type in your selection (1, 2, 3, 4 or 5): The program will include an array of structures. The structure type is called MenuItem, and the array of structures should be declared as menu[50] to store upto 50 breakfast menu items. The MenuItem structure must have the following 4 data fields (i.e. members): Code, description, unitprice, and quantity. Your program must define at least the following functions:  Function LoadData(…) that loads the data of breakfast menu items from an input file menu.txt into the array menu.  Five separate functions to handle the program main menu five tasks shown above. In general, function main() should load the data into the array menu and display the main menu of the above mentioned tasks. Based on the option selected, the corresponding function should be called. Users must make an order before requesting modify, cancel or print order bill (See the given sample run). Here is a more detailed explanation on the above tasks and functions. LoadData(…) Opens the input file menu.txt (you will create it) containing breakfast menu items data (See below) and assign these values to the corresponding array menu structure fields. Assign zero to the quantity field of the loaded menu items. Welcome to Asim's Restaurant Select an operation? 1 Make a breakfast order 2 Modify existing order 3 Cancel existing order 4 Print Bill 5 Exit Type in your selection (1, 2, 3, 4 or 5): MakeOrder(…) This function is called when the user selects option 1 from the main menu. It first displays the breakfast menu items to the user (stored in the array menu) along with all the necessary information (item code, description and unit price). It then requests the user to select an item using the item code (see the sample run). When the user enters an item code number the program should verify the code number and increment the quantity of the selected item in the array menu. Your program should reject invalid item codes and request the user to re-enter the item code or stop the entry. PrintBill(…) This function is called when the user selects option 4 from the main menu. The function displays the breakfast menu items in the breakfast order by printing the values of all MenuItem members of the array menu that have quantity value above zero. Print a nicely formatted bill (See the sample run). CancelOrder(…) This function is called when the user selects option 3 from the main menu. It will cancel the breakfast order by setting the quantity value of all the array menu structures to zero. ModifyOrder(….) This function is called when the user selects option 2 from the main menu. The task of this function is to allow the user to edit an existing breakfast order with two operations: Adding more breakfast items and/or altering the breakfast item that were ordered before (examine the sample program run). Handling Errors and Invalid Input Your program should reply safely to any erroneous situation or input with appropriate message to the user and flow nicely and correctly to the next operation (Examine the sample program run). Additional functions Use of functions is highly recommended for any additional special tasks needed by your solution. Global variables are not allowed except for max array menu size 50. You must pass the needed parameters through functions parameter lists.

1962


How many types of arrays are there in c?

585


How to draw the flowchart for structure programs?

8750






Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college. 1.write a function to print names of all students who joined in a particular year 2.write a function to print the data of a student whose roll number is given

2499


What is static memory allocation?

595


What are the types of functions in c?

558


What is the difference between typedef struct and struct?

585


Why are all header files not declared in every c program?

592


What is the process to create increment and decrement stamen in c?

579


How can I automatically locate a programs configuration files in the same directory as the executable?

614


What is structure packing in c?

593


There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?

802


Which of the following operators is incorrect and why? ( >=, <=, <>, ==)

649