C Online Compiler
Example: Simple Fixed-Scale Sales Bar Chart in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Simple Fixed-Scale Sales Bar Chart #include <stdio.h> int main() { // Step 1: Define product names and sales data char *products[] = {"Product A", "Product B", "Product C", "Product D"}; int sales[] = {50, 80, 30, 100}; int num_products = sizeof(sales) / sizeof(sales[0]); // Step 2: Iterate through products and print bars printf("--- Simple Sales Bar Chart ---\n"); for (int i = 0; i < num_products; i++) { printf("%-10s | ", products[i]); // Print product name, left-aligned // Step 3: Print asterisks based on sales value for (int j = 0; j < sales[i] / 10; j++) { // Divide by 10 for scaling (10 units = 1 asterisk) printf("*"); } printf(" (%d)\n", sales[i]); // Print actual sales value } printf("------------------------------\n"); return 0; }
Output
Clear
ADVERTISEMENTS