Concetti Chiave

  • The program calculates and prints a specified number of n-polygonal numbers, which are related to polygons.
  • The user is prompted to enter a polygonal side number greater than 2, ensuring valid input for calculations.
  • The program uses a loop to repeatedly ask for a valid polygonal side number, displaying a message for invalid entries.
  • The `polynum` function computes the n-polygonal number using a mathematical formula based on the side number and sequence position.
  • The main function handles user input and manages the flow of the program to display the sequence of polygonal numbers.

Download sorgente

 /*  * Il seguente programma stampa h numeri n-poligonali  * (Cfr. http://mathworld.wolfram.com/PolygonalNumber.html )  */ #include 

Entrada do usuário

h> 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 polygonal number ( > 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 n-poligonal numbers, which are a type of figurate number related to polygons.

  3. How does the program ensure the user inputs a valid polygonal side number?
  4. The program prompts the user to enter a polygonal number greater than 2 and continues to request input until a valid number is provided, displaying an "Invalid value!" message for incorrect entries.

  5. What is the function of the `polynum` function in the program?
  6. The `polynum` function calculates and returns the n-poligonal number based on the given side number `n` and the sequence position `h`, using the formula provided in the code.

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community