BOMARBLE - D - Playing with Marbles Pablo was assigned in his class to construct pentagons inside pentagons with marbles but he doesn’t know how many marbles he will need. He knows that for one pentagon he needs 5 marbles The only way he knows to insert a second pentagon is putting a marble in the middle of each segment and drawing three lines as shown. He puts a marble in the intersecting lines and removes them. To insert a third pentagon inside he first divides all segments in two including the ones that are not needed, and repeats the procedure. Drawing a second pentagon will require 12 marbles. A third pentagon will require 22 marbles. Given the information of how many pentagons will be created, write a program to calculate the number of marbles needed. solution- #include<stdio.h> int main() {int n,k; while(scanf("%d",&n)!=EOF) { if(n==0) break; else { k=5*n+((n-1)*(3*n-2))/2; printf("%d\n",k); } ...
Comments
Post a Comment