Concetti Chiave

  • The program calculates and prints polygonal numbers for a given side.
  • Users input the polygonal side, which must be greater than 2.
  • The program prompts for the number of polygonal numbers to display.
  • The core calculation is handled by the polynum function, which computes using the formula for polygonal numbers.
  • Invalid input for the polygonal side (less than 3) prompts an error message.

Download sorgente

 /*  * Il seguente programma stampa h numeri n-poligonali  * (Cfr. http://mathworld.wolfram.com/PolygonalNumber.html )  */ #include  unsigned int polynum(unsigned int, unsigned int); int main(void) { 	unsigned int side = 2, numbers, i; 	/* read polygonal side, how much numbers to print */ 	while (side  2): "); 		scanf("%u", &side); 		if (side 
"); 	} 	printf("How much numbers? "); 	scanf("%u", &numbers); 	for (i = 1; i  0) 		printf("...
"); return 0; } unsigned int polynum(unsigned int n, unsigned int h) { if (n

Domande da interrogazione

  1. What is the purpose of the program described in the text?
  2. The program is designed to print a specified number of polygonal numbers, which are a type of figurate number represented in a polygonal shape.

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community