1. ## Histogram help

Hi there!
I have the following code which generates a population of N Gaussian numbers.
Code:
```#include <stdio.h>
#include<math.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{

int iseed,i,j,N,l,m,k,y,z;
float a,b,e,stand,c,d,sum=0.00;
printf("Enter the number of Gaussion numbers needed\n");
scanf("%d", &N);
printf("Enter the standard deviation (larger or equal 1) \n");
scanf("%f", &stand);
z=(6*stand);
y=0-z;
int values[6+z+1];
for(j=0; j<6+z+1; j++) {
values[j] = 0; /* sets whole array set to 0 */
}
iseed=1934871;
srand(time(NULL));

for (j=0; j<N; j++) {

for (i=0; i<=12 ; i++)
{
a=(float)rand();
e=a/(float)RAND_MAX;
sum = sum + e;
}
b=sum-6;
c=stand*b;

for (l=y-1; l<=z; l++){ /* For loop starting at a value of -6xstandard dev and going to =6xstandard dev */
if((l-0.5)<=c)          /* If C falls withing +/- 0.5 of the current value of l then we add 1 to the array values */
d=c;
if(d<(l+0.5)) {
values[l+z] += 1;
break;
}                        /* if the if statement is satisfied exit the loop */
}

sum=0.00;
}
for (m=y;m<0;++m){
printf("%d %d",m,values[m+z]);
for(k=0; k<(values[m+z]);++k) {
printf("%c",'*');
}
printf("\n");
}
for (m=0;m<=z;++m){
printf(" %d %d",m,values[m+z]);
for(k=0; k<(values[m+z]);++k) {
printf("%c",'*');
}
printf("\n");
}
return 0;
}```
The programme currently generates a * every time an element is read in the array values[]. However, as I am using large population sizes it would be better if the programme generated a * for every n times the element is read. Could someone provide assistance on how to do this? Many Thanks! 2. k is the iterator in your for loop that prints out the stars. To get stars printed only on every num k's, instead of every k, you can use:

Code:
```for(k=0;k<something;k++) {
if(k % num==0)
printf("%c", '*');
}```
Logic like that. k%num will equal zero, when k is zero. If you don't want that add this:

if(k%num== 0 && k)

Cheers!  3. A small point to make, there is no need to do printf("%c", '*'). Just do printf("*"), it's much clearer. 4. Originally Posted by anduril462
A small point to make, there is no need to do printf("%c", '*'). Just do printf("*"), it's much clearer.
It would be even better to just write putchar('*'). 5. Cheers for your help guys! Popular pages Recent additions 