how to draw a graph or histogram in c language

Solutions on MaxInterview for how to draw a graph or histogram in c language by the best coders in the world

showing results for - "how to draw a graph or histogram in c language"
Cassie
15 Feb 2020
1#define    N    5                                           
2   main()
3   {                                                               
4       intvalue[N];                                           
5       int i, j, n, x;                                            
6                                                               
7       for (n=0; n < N; ++n)                                      
8       {                                                           
9          printf("Enter employees in Group - %d : ",n+1);      
10          scanf("%d", &x);                                     
11          value[n] = x;                                        
12          printf("%d\n", value[n]);                                 
13       }                                                           
14       printf("\n");                                           
15                                                               
16       printf("          |\n");                                
17       for (n = 0 ; n < N ; ++n)                                  
18       {                                                           
19          for (i = 1 ; i <= 3 ; i++)                              
20          {                                                        
21              if ( i == 2)                                           
22                 printf("Group-%1d   |",n+1);                        
23              else                                                 
24                 printf("          |");
25
26
27
28
29                            
30              for (j = 1 ; j <= value[n]; ++j)                     
31                 printf("*"); 
32              if (i == 2)                                          
33                 printf("(%d)\n", value[n]);                       
34              else                                                 
35                 printf("\n");                                     
36          }                                                        
37          printf("          |\n");                                 
38       }                                                           
39   }                                                               
40                                                               
41Output                                                      
42                                                               
43   Enter employees in Group - 1 : 12                           
44   12                                                          
45   Enter employees in Group - 2 : 23                           
46   23                                                          
47   Enter employees in Group - 3 : 35                           
48   35                                                          
49   Enter employees in Group - 4 : 20                           
50   20                                                          
51   Enter Employees in Group - 5 : 11                           
52   11                                                          
53                                                               
54             |                                                 
55             |************                                     
56   Group-1   |************(12)                                 
57             |************                                     
58             |                                                 
59             |***********************                          
60   Group-2   |***********************(23)                      
61             |***********************                          
62             |                                                 
63             |***********************************              
64   Group-3   |***********************************(35)          
65             |***********************************              
66             |                                                 
67             |********************                             
68   Group-4   |********************(20)                         
69             |********************                             
70             |                                                 
71             |***********                                      
72   Group-5   |***********(11)                                  
73             |***********                                      
74               |                                                 
75