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 }
Answers
Answered by
0
#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;
)
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;
)
megusta:
Sample values:
Answered by
4
Explanation:
bottom ( 2 + 2)
bottom ( 2 + 2)Top ( 2 ) + 1 for support
bottom ( 2 + 2)Top ( 2 ) + 1 for support so totally 7 cards.
bottom ( 2 + 2)Top ( 2 ) + 1 for support so totally 7 cards.Similarly write a program to compute
Similar questions