#include <fstream>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdlib>
#include <sstream>
using namespace std;
string IntToString(int a) // to_string() dev++ da default olarak calismiyor. c++11 özelliği çünkü. Ondan dolayı bu fonksiyonu kullanıyoruz (compiler ayarlarını yapmayı bilmiyorsundur diye.)
{
ostringstream temp;
temp << a;
return temp.str();
}
int num_count = 0;
int sum_numbers = 0;
double ortalama = 0;
int main()
{
srand((unsigned)time(0));
ofstream file;
ofstream file_2;
file.open("veri.txt");
file_2.open("sonuc.txt");
for (int i = 1; i <= 500; i++)
{
int random_sayi = rand() % 100;
file << random_sayi;
file << "\n";
if ((i%10) == 0)
if ((random_sayi % 3) == 0 && (random_sayi%2 != 0)) {
printf("%d. siradaki %d \n", i, random_sayi);
file_2 << IntToString(i) +". siradaki " + IntToString(random_sayi) + "\n";
sum_numbers = sum_numbers + random_sayi;
num_count++;
}
}
ortalama = (double)sum_numbers / (double)num_count;
printf("Sarti saglayan %d adet sayinin toplami = %d, ortalamasi = %f \n", num_count, sum_numbers, ortalama);
file_2 << "Sarti saglayan " + IntToString(num_count) + " adet sayinin toplami = " + IntToString(sum_numbers) + ", ortalamasi = " + IntToString(ortalama) + "\n";
file_2.close();
file.close();
system("pause");
}