Yüz Rastgele Sayı Dizini İle Histogram Yapımı

mustaphos

MB Üyesi
Kayıt
14 Eylül 2015
Mesajlar
35
Tepkiler
8
Yaş
28
Meslek
Öğrenci
Üniv
Anadolu University
Merhaba.
Program 100 adet rastgele sayı üretir ve bununla ilgili grafik (histogram) çıkarır.
İyi çalışmalar.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
void main()
{
int sayi;
int dizinim[100];
int deger;
int sayac[10]={0};
int yazdir;
int satir;
int sutun;
int saydir;
srand(time(NULL));
printf("One hundred random number array\n");
printf("\n");
for (sayi=0;sayi<100;sayi++) /* For loop for create 100 random numbers */
{
dizinim[sayi] = rand() % 10 ; /* Creates random numbers */
printf("%d",dizinim[sayi]); /* Prints random numbers */
for (deger=0;deger<10;deger++) /* For loop for calculate how much numbers created for each numbers */
{
if (deger==dizinim[sayi]) /* If created random number is match to the number which is increasing on "deger" variable */
{
sayac[dizinim[sayi]]++; /* Increase the counter which has the same value with random numbers */
}
}
}
printf("\n");
for (yazdir=0;yazdir<10;yazdir++) /* For loop for find how much numbers found for each numbers */
{
printf("Number of %ds : %d \n",yazdir,sayac[yazdir]); /* Print the counted values for each numbers */
}
printf("\n");
printf("HISTOGRAM\n");
printf("\n");
for (satir=20;satir>0;satir--) /* For loop for create rows */
{
printf("%2d | ",satir); /* Print row values */
for(saydir=0;saydir<10;saydir++) /* For loop for create the X columns*/
{
if (satir<=sayac[saydir]) /* If row value less than or equal to the numbers counter value */
printf("X "); /* Print the X columns */
else
printf(" "); /* If if condition is not satisfied than print a space */
}
printf("\n"); /* Go to the next row */
}
printf(" ------------------------------\n");
printf(" ");
for (sutun=0;sutun<10;sutun++) /* For loop for create columns */
{
printf("%d ",sutun); /* Print column numbers */
}
printf("\n");
getch(); /* Wait for user to press enter */
}
 
Yukarı Alt