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.
/* * Il seguente programma stampa h numeri n-poligonali * (Cfr. http://mathworld.wolfram.com/PolygonalNumber.html ) */ #includeunsigned 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
- What is the purpose of the program described in the text?
The program is designed to print a specified number of polygonal numbers, which are a type of figurate number represented in a polygonal shape.