#include<stdio.h>
#include<conio.h>
int main()
{
int a[10],i,j,n,max,copy_max;;
printf("Enter the no. of elements: ");
scanf("%d",&n);
//input array
for(i=0;i<n;i++)
{
printf("Enter the element %d: ",i+1);
scanf("%d",&a[i]);
}
//finding max no.
max=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
max=a[i];
}
copy_max=max;
//logic for vertical histogram
for(i=0;i<copy_max;i++,max--)
{
for(j=0;j<n;j++)
{
if(a[j]>=max)
printf(" * ");
else
printf(" ");
}
printf("\n");
}
return 0;
}
output..
Enter no of Elements: 3
Enter element 1: 4
Enter element 1: 5
Enter element 1: 3
*
* *
* * *
* * *
* * *
#include<conio.h>
int main()
{
int a[10],i,j,n,max,copy_max;;
printf("Enter the no. of elements: ");
scanf("%d",&n);
//input array
for(i=0;i<n;i++)
{
printf("Enter the element %d: ",i+1);
scanf("%d",&a[i]);
}
//finding max no.
max=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
max=a[i];
}
copy_max=max;
//logic for vertical histogram
for(i=0;i<copy_max;i++,max--)
{
for(j=0;j<n;j++)
{
if(a[j]>=max)
printf(" * ");
else
printf(" ");
}
printf("\n");
}
return 0;
}
output..
Enter no of Elements: 3
Enter element 1: 4
Enter element 1: 5
Enter element 1: 3
*
* *
* * *
* * *
* * *
how to print star from starting vertically
ReplyDelete