/* Write a C Program to draw a histogram. */
=================================
#include<stdio.h>
#include<conio.h>
#define N 5
void main()
{
int value[N];
int i, j, n, x;
for(n=0; n<N; ++n)
{
printf(“enter employees in group-%d: ”, n+1);
scanf(“%d”, &x);
value[n]=x;
printf(“%d”, value[n]);
}
printf(“\n”);
printf(“|\n”);
for(n=0; n<N; ++n)
{
for(i=1; i<=3; i++)
{
if(i= =2)
printf(“ Group-%d | “, n+1);
else
printf(“|”);
for(j=1; j<=value[n]; ++j)
printf(“*”);
if(i= =2)
printf(“(%d)”, value[n]);
else
printf(“\n”);
}
printf(“|\n”);
}
}
Output:
======
Enter employees in Group -1:12
12
Enter employees in Group -2:23
23
Enter employees in Group -3:35
35
Enter employees in Group -4:20
20
Enter employees in Group -5:11
11
|
|************
Group-1 |************ (12)
|************
|
|***********************
Group-2 |***********************(23)
|***********************
|
|***********************************
Group-3 |***********************************(35)
|***********************************
|
|********************
Group-4 |********************(20)
|********************
|
|***********
Group-5 |***********(11)
|***********
|
=================================
#include<stdio.h>
#include<conio.h>
#define N 5
void main()
{
int value[N];
int i, j, n, x;
for(n=0; n<N; ++n)
{
printf(“enter employees in group-%d: ”, n+1);
scanf(“%d”, &x);
value[n]=x;
printf(“%d”, value[n]);
}
printf(“\n”);
printf(“|\n”);
for(n=0; n<N; ++n)
{
for(i=1; i<=3; i++)
{
if(i= =2)
printf(“ Group-%d | “, n+1);
else
printf(“|”);
for(j=1; j<=value[n]; ++j)
printf(“*”);
if(i= =2)
printf(“(%d)”, value[n]);
else
printf(“\n”);
}
printf(“|\n”);
}
}
Output:
======
Enter employees in Group -1:12
12
Enter employees in Group -2:23
23
Enter employees in Group -3:35
35
Enter employees in Group -4:20
20
Enter employees in Group -5:11
11
|
|************
Group-1 |************ (12)
|************
|
|***********************
Group-2 |***********************(23)
|***********************
|
|***********************************
Group-3 |***********************************(35)
|***********************************
|
|********************
Group-4 |********************(20)
|********************
|
|***********
Group-5 |***********(11)
|***********
|
No comments:
Post a Comment