Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define N 8 // (i) kritiria
- #define M 3 //(i) xores
- int i; //( boithitiki metavliti )
- int j;
- char criterion[N][40]={"kuvernitiki statherotita","statherotita ethnikou nomismatos",
- "forologiki politiki","eggutita se agores","eggutita se promitheftes",
- "morfotiko epipedo ergazomenwn","koultoura ,nootropia ,paragwgikotita","kostos ergasias"}; //(ii)
- int weights[N]; //(iii)
- int scores[N][M]; //(iv)
- float finalscores[M]; //(v)
- void read_weights();//dilosi sunartisis read_weights
- void read_scores();//dilosi sunartisis read_scores
- void best_country();//dilosi sinrtisis best_country
- //void print_test();
- int main()
- {
- printf ("kataxwrisi sunteleston varutitas 8 kritirion \n");
- printf ("prepei na einai akeraios thetikos kai sto sunolo toys na exoyn athroisma 100 \n");
- printf("dwse to suntelesti varititas gia \n");
- read_weights(&weights);
- read_scores(&scores);
- best_country();
- printf("\nPinakas\n");
- int j=0;
- int i=0;
- for (i=0;i<=N-1;i++){
- for (j=0;j<=M-1;j++){
- printf("[%d][%d] ->%d\t ",i,j,scores[i][j]);
- }
- }
- }
- void read_weights(int*pweights){//( erotima B
- int j=0;
- //int sumweights=0;
- int upoloiposuntelesti = 100;
- do {
- printf("to kritirio (%s) upoloiponte %d : " , criterion[j], upoloiposuntelesti );
- scanf ("%d" , pweights);
- if (*pweights<=0||*pweights>100){
- printf("kanate lathos dwste pali suntelesti\n");
- }
- else{
- upoloiposuntelesti= upoloiposuntelesti - *pweights;
- if (upoloiposuntelesti<0){
- printf("kseperasate to 100 dwste apo tin arxi tous suntelestes \n");
- j=-1;
- upoloiposuntelesti=100;
- }
- j++;
- pweights++;
- }
- } while(j<N-1);
- j=(N-1);
- printf("gia to kritirio (%s) einai angastika to upoloipo : %d\n" , criterion[j], upoloiposuntelesti );
- *pweights = upoloiposuntelesti;
- }
- void read_scores(int*pscores){
- int j;
- do {
- j=0;
- printf("dwste gia tin %d xwra tis vathmologies twn kritiriwn apo 0 ews 5 :\n" , (i+1));
- do{
- printf("bathmologia gia to kritirio (%s) me suntelesti(%d) :",criterion[j],weights[j]);
- scanf ("%d",&scores[j][i]);
- if (scores[j][i]<0 || scores[j][i]>5){
- printf("kanate lathos dokimaste pali \n");
- }
- else{
- j++;
- }
- }
- while (j<N);
- i++;
- }
- while (i<M);
- }
- void best_country(){
- int j;
- int i;
- //float sum = 0;
- for (j=0;j<M-1;j++){
- for(i=0;i<N-1;i++) {
- finalscores[j] = finalscores[j] + (weights[i] * scores[i][j] / 100) ;
- printf ("Weight[%d]=%d, Scores[%d][%d]=%d, finalscores[%d]=%.2f \n",i,weights[i],i,j,scores[i][j],j,finalscores[j]);
- //sum=finalscores[j] +sum;
- //sum=finalscores[j] +sum;
- //finalscores[j] = sum;
- }
- }
- for(j=0;j<M;j++){
- printf(" %d , %.2f " , j, finalscores[j] );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement