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.
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);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.