Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C PROGRAM. When the user inputs a iteration, the program produces a pentagon sha

ID: 3735266 • Letter: C

Question

C PROGRAM. When the user inputs a iteration, the program produces a pentagon shape using dots.

THE PENTAGON Using C-language, have the variable num which will be a positive integer and determine how many dots exist in a pentagonal shape around a center dot on the Nth iteration. For example, in the image below you can see that on the first iteration there is only a single dot, on the second iteration there are 6 dots on the third there are 16 dots, and on the fourth there are 31 dots Your program should return the number of dots that exist in the whole pentagon on the Nth iteration Sample Test Cases: Input:2 Output:6 ader

Explanation / Answer

/*Here we are adding 5 more dots in every new pentagon
iteration 1 =1 dots
iteration 2 = 1+5 dots
iteration 3 = 6+2(5) dots
iteration 4 = 16 + 3(5)dots
iteration 5 = 31+ 4(5) dots */

#include <stdio.h>

int main()
{ int a,i=0,sum=0,num=1;
printf("Enter the number of interations ");
scanf("%d",&a);
for(i=0;i<=(a-1);i++)
{
sum=sum+i;
}
if(a>1)
{
num = (num+(5*sum));
}
printf("number of dots = %d",num);
return(0);
}