Write a c program to calculate card castling ?
example To built a 2 storeys of card castle you need
bottom ( 2 + 2)
Top ( 2 ) + 1 for support
so totally 7 cards.
Similarly write a program to compute the number of cards to build the castle to a given "N" storeys ..
{ with Solution }

1

Answers

2014-03-22T14:15:14+05:30
#include<stdio.h>
main(
int N;                      /*No. of storeys*/
int a,b;                    /*a=No. of standing cards, b= cards for support*/
int T;                       /*Total Cards*/

scanf("%d",&N);       /*Input from user about no. of storeys*/

a=N*(N+1);
b=(N*(N-1))/2;

T=a+b;

printf("Cards needed for a %d storeyed castle are %d",N,T);

return 0;
)
0
Sample values:
If N=1, T=2; N=2, T=7; N=3, T=15; N=4, T=26