Write a program in C. It takes an int parameter, which must…
- User
Assistant: User: User: Write a program in C. It takes an int parameter, which must correspond to the size of the star's sides. This program must display a star with * outlines. This star must have 10 dimensions and 10 stops. Your program must comply with the epitech norm. User:
Write a program in C. It takes an int parameter, which must correspond to the size of the star's sides. This program must display a star with * outlines. This star must have 10 dimensions and 10 stops. Your program must comply with the epitech norm.
Assistant: Below is a C program that takes an integer parameter representing the size of the star's sides and displays a star with
*outlines. This program complies with the Epitech norm, which emphasizes code readability and maintainability.c#include <stdio.h> void print_line(int total_width, int offset) { for (int i = 0; i < offset; ++i) printf(" "); printf("*"); for (int i = 0; i < total_width - 2 * offset - 2; ++i) printf(" "); if (offset != total_width / 2 - 1) printf("*"); printf("\n"); } void draw_star(int size) { int total_width = size * 4 + 1; // Upper part of the star for (int i = size - 1; i >= -(size / 2); --i) { print_line(total_width, abs(i)); } // Lower part of the star for (int j = -(size / 2) + 1; j <= size -1 ; ++j) { print_line(total_width, abs(j)); } } int main(int argc, char **argv) { if(argc !=2){ fprintf(stderr,"Usage: %s <size>\n", argv[0]); return(84); } int size = atoi(argv[1]); if(size <=0){ fprintf(stderr,"Size must be positive.\n"); return(84); } draw_star(size); return(0); }Explanation:
-
print_line: This function prints a single line of the star. It calculates how many spaces to print before and between stars based on
offset. -
draw_star: This function constructs both upper and lower parts of the star using loops.
-
- Assistant
Para generar un programa en C que dibuje una estrella con el contorno formateado usando asteriscos , necesitaremos ajustar algunas partes de código para alinearnos con tus expectativas y requisitos. Considerando tu ejemplo visual y la descripción anterior, aquí hay una implementación que cumple con la norma de Epitech: