Printing a simple histogram in C
By: Ignatius
This simple C program prints a simple histogram.
#include <stdio.h>
#define SIZE 10
int main()
{
// declare and initialize an array named n with size SIZE...
int n[SIZE] = {19, 3, 15, 7, 11, 9, 13, 5, 17, 1};
int i, j;
// display the table header...
printf("%s%13s%17s\n","Element/index", "Value", "Histogram");
// do the iteration...
// the outer for loop, read row by row...
for(i=0; i <= (SIZE-1); i++)
{
printf("%9d%15d ", i, n[i]);
// the inner for loop, for every row, read column by column and print the bar...
for(j = 1; j<= n[i]; j++)
// print the asterisk bar...repeat...
printf("*");
// go to new line for new row...repeats...
printf("\n");
}
return 0;
}
Archived Comments
1. Return n....getch me kya difference h..
View Tutorial By: saloni nagar at 2016-04-03 03:23:08
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Sum of the elements of an array in C
Printing a simple histogram in C
Find square and square root for a given number in C
Simple arithmetic calculations in C
Passing double value to a function in C
Passing pointer to a function in C
Infix to Prefix And Postfix in C
while, do while and for loops in C