sobota, 20 sierpnia 2016
first numbers and structs
#include <iostream>
#include <stdio.h>
#define max 100
using namespace std;
bool is_first(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+1;i++)
if(x%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
int how_many_first(int first)
{
int i,sum;
sum=0;
for(i=1;i<first;i++)
if(is_first(i))
++sum;
return sum;
}
int sum_first(int first)
{
int i,sum;
sum=0;
for(i=1;i<first;i++)
if(is_first(i))
sum+=i;
return sum;
}
double down_zero(double x, double y)
{
double z;
if(x<y)
z=x/y;
else
z=y/x;
return z;
}
double up_zero(double x, double y)
{
double z;
if(x>y)
z=x/y;
else
z=y/x;
return z;
}
double div_value(double x, double y)
{
return x/y;
}
double one_value(double x, double y)
{
return up_zero(x,y)*down_zero(x,y);
}
int *tab_first;
int *temp_tab;
struct first_functions
{
int size;
int div_sum;
double up_first;
double down_first;
};
struct result
{
double one_zero;
int how_many;
int m_sum;
};
int main(int argc, char **argv)
{
tab_first=new int[max];
temp_tab=new int[max];
struct first_functions *first_fun=new struct first_functions[max];
struct result *first_result=new struct result[max];
int i,j;
i=0;
j=0;
do
{
if(is_first(j))
{
tab_first[i]=j;
++i;
}
++j;
}while(i<max);
for(i=0;i<max;i++)
{
first_fun[i].size=how_many_first(tab_first[i]);
first_fun[i].div_sum=sum_first(tab_first[i]);
}
double temp1[max];
for(j=0;j<max;j++)
{
temp1[j]=1.0*tab_first[j];
}
for(i=1;i<max+1;i++)
{
first_fun[i-1].down_first=down_zero(temp1[i-1],temp1[i]);
first_fun[i-1].up_first=up_zero(temp1[i-1],temp1[i]);
}
for(i=0;i<max;i++)
{
first_result[i].one_zero=one_value(first_fun[i].down_first,first_fun[i].up_first)*
one_value(1.*first_fun[i].div_sum,div_value(1.,first_fun[i].div_sum))*
one_value(1.*first_fun[i].size,div_value(1.,first_fun[i].size))*
tab_first[i];
first_result[i].how_many=first_fun[i].size;
first_result[i].m_sum=first_fun[i].div_sum;
cout<<first_result[i].one_zero<<" "<<first_result[i].how_many<<" "<<first_result[i].m_sum<<endl;
}
delete temp_tab;
delete first_result;
delete first_fun;
delete tab_first;
return 0;
}
Subskrybuj:
Komentarze do posta (Atom)
Brak komentarzy:
Prześlij komentarz