1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
// DR.cpp : Defines the entry point for the console application.//
#include "stdio.h"
#include "math.h"
#include "string.h"
#include "stdlib.h"
double Var1[20][20];
double Var2[20];
double Pout[20][20];
const int n = 3;
void InitStr(char *str, int iSize)
{
int i= 0;
for(;i < iSize;i++)
str[i] = '\0';
}
void EnterData1(void)
{
int i = 0;
int j = 0;
int k = 0;
int iNext = 0;
char string[90000];
char str[90000];
InitStr(str, 90000);
InitStr(string, 90000);
printf("Enter the values for Var1 separated by ',' and ';' for new line: \n");
gets(string);
for(i = 0, k = 0; i < sizeof(string) || string[i] == '\0'; i++,j++)
{
if(string[i] == ';') { k++; iNext = 0; i++; }
if(string[i] == ',')
{
if(str[j] == '\0')
{//store data
Var1[k][iNext] = atof(str);
j = -1;
iNext++;
InitStr(str, 90000);
}
}
else
{
str[j] = string[i];
}
}
}
void EnterData2(void)
{
int i = 0;
int j = 0;
int iNext = 0;
char string[90000];
char str[90000];
InitStr(str, 90000);
InitStr(string, 90000);
printf("Enter the values for Var2 separated by ',': \n");
gets(string);
for(i = 0; i < sizeof(string) || string[i] == '\0'; i++,j++)
{
if(string[i] == ',')
{
if(str[j] == '\0')
{//store data
Var2[iNext] = atof(str);
j = -1;
iNext++;
InitStr(str, 90000);
}
}
else
{
str[j] = string[i];
}
}
}
void PrintData1(void)
{
for(int i = 0; i < 20;i++ )
for(int j = 0; j < 20 ; j++)
printf("[%d][%d] = %f\n",i,j,Var1[i][j]);
}
void PrintData2(void)
{
for(int i = 0; i < 20;i++ )
printf("[%d] = %f\n",i,Var2[i]);
}
void CalcModuleA(int n)
// here n is the number of comonomer - when the function call is actually set as a parameter (between 2 and 20 incl.)
{
for(int i = 0; i < n; i++)
// i is an index of the row of Pout
{
double sum = 0.0;
// this sum goes to the i-th row of Pout
for(int j = 0; j < n; j++)
sum += Var2[j] / Var1[i][j];
// this sum has already been calculated and can now calculate the i-th row of Pout
for(int j = 0; j < n; j++)
Pout[i][j] = Var2[j] / (Var1[i][j] * sum);
// i-th row of Pout is ready and continue to the next ...
}
}
int main(int argc, char* argv[])
{
char *s;
EnterData1();
EnterData2();
PrintData1();
PrintData2();
CalcModuleA(n);
gets(s);
return 0;
}
|