Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 8 // (i) kritiria
  3. #define M 3 //(i) xores
  4. int i;  //( boithitiki metavliti )
  5. int j;
  6. char criterion[N][40]={"kuvernitiki statherotita","statherotita ethnikou nomismatos",
  7. "forologiki politiki","eggutita se agores","eggutita se promitheftes",                
  8. "morfotiko epipedo ergazomenwn","koultoura ,nootropia ,paragwgikotita","kostos ergasias"}; //(ii)
  9. int weights[N];  //(iii)
  10. int scores[N][M]; //(iv)
  11. float finalscores[M]; //(v)
  12. void read_weights();//dilosi sunartisis read_weights
  13. void read_scores();//dilosi sunartisis read_scores
  14. void best_country();//dilosi sinrtisis best_country
  15. //void print_test();
  16. int main()
  17. {
  18. printf ("kataxwrisi sunteleston varutitas 8 kritirion \n");
  19. printf ("prepei na einai akeraios thetikos kai sto sunolo toys na exoyn athroisma 100 \n");
  20. printf("dwse to suntelesti varititas gia \n");
  21. read_weights(&weights);
  22. read_scores(&scores);
  23. best_country();
  24. printf("\nPinakas\n");
  25. int j=0;
  26. int i=0;
  27. for (i=0;i<=N-1;i++){
  28.     for (j=0;j<=M-1;j++){
  29.         printf("[%d][%d] ->%d\t  ",i,j,scores[i][j]);
  30.     }
  31. }
  32.  
  33. }
  34. void read_weights(int*pweights){//( erotima B
  35.         int j=0;
  36.         //int sumweights=0;
  37.         int upoloiposuntelesti = 100;
  38.         do {
  39.                 printf("to kritirio (%s) upoloiponte %d : " , criterion[j], upoloiposuntelesti );
  40.                 scanf ("%d" , pweights);
  41.                 if (*pweights<=0||*pweights>100){
  42.                         printf("kanate lathos dwste pali suntelesti\n");
  43.                 }
  44.                 else{
  45.                         upoloiposuntelesti= upoloiposuntelesti - *pweights;
  46.                         if  (upoloiposuntelesti<0){
  47.                
  48.                    printf("kseperasate to 100 dwste apo tin arxi tous suntelestes \n");
  49.                    j=-1;
  50.                    upoloiposuntelesti=100;
  51.                
  52.                }
  53.                         j++;
  54.                         pweights++;
  55.                      
  56.                 }
  57.                
  58.         } while(j<N-1);
  59.         j=(N-1);
  60.        
  61.         printf("gia to kritirio (%s) einai angastika to upoloipo  : %d\n" , criterion[j], upoloiposuntelesti );
  62.         *pweights = upoloiposuntelesti;
  63. }
  64.  
  65. void read_scores(int*pscores){
  66.  
  67.     int j;
  68.     do {
  69.         j=0;
  70.     printf("dwste gia tin %d xwra tis vathmologies twn kritiriwn apo 0 ews 5 :\n" , (i+1));
  71.    
  72.         do{
  73.            
  74.             printf("bathmologia gia to kritirio (%s) me suntelesti(%d) :",criterion[j],weights[j]);
  75.             scanf ("%d",&scores[j][i]);
  76.             if (scores[j][i]<0 || scores[j][i]>5){
  77.                 printf("kanate lathos dokimaste pali \n");
  78.             }
  79.             else{
  80.            
  81.            
  82.             j++;
  83.         }
  84.         }
  85.    
  86.         while (j<N);
  87.             i++;
  88.     }
  89.     while (i<M);
  90. }
  91. void best_country(){
  92.  int j;
  93.  int i;
  94.  //float sum = 0;
  95.  for (j=0;j<M-1;j++){
  96.     for(i=0;i<N-1;i++) {
  97.  finalscores[j] = finalscores[j] + (weights[i] * scores[i][j] / 100) ;
  98.         printf ("Weight[%d]=%d, Scores[%d][%d]=%d, finalscores[%d]=%.2f \n",i,weights[i],i,j,scores[i][j],j,finalscores[j]);
  99.         //sum=finalscores[j] +sum;
  100.     //sum=finalscores[j] +sum;
  101.     //finalscores[j] = sum;
  102.    
  103.  }
  104. }
  105.   for(j=0;j<M;j++){
  106.  
  107.   printf(" %d  ,  %.2f  " , j, finalscores[j] );
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement