Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)

Paste

Pasted as C by registered user henriquerm ( 14 years ago )
#include <stdio.h>
#include <math.h>

 double Loop(int x);
 double Calculo(int y);
 int l, I=0, J=0, X=0, Y=0, i;
 double rede[1000][1000];
main()
{
 printf("Digite o numero l de largura/altura da rede\n");
 scanf("%d" , &l);
 Loop(l);
}



double Loop ( int x ) {
 
 for (i=-1; i<=1; i=i+2){    
  rede[I][J]=i; 
  printf("%d %d %d\n", I, J, i); 
  if (I==x-1 && J==x-1){Calculo(x);}   
  else {  
   if (J==x-1 && I!= x-1){    
    I++;J=0; Loop(x);
   }
   else {
     J++; Loop(x);
   } 
  }
 }
}


double Calculo (int y) {
//int X, Y;
double E, M, K=1;  
  for (X=0;X<=y-1;X++) { 
   for (Y=0; Y<=y-1; Y++) {        
    if (X == y-1 && Y == y-1){
     E = E + K * rede[X][Y] * (rede[X][0] + rede [0][Y]);
    }
    else {
     if (X==y-1) {   
      E = E + K * rede[X][Y] * (rede[X+1][Y] + rede[X][0]); 
     }
     else { 
      if (Y==y-1) { 
       E = E + K * rede[X][Y] * (rede[0][Y] + rede[X][Y+1]);
      }
      else {
       E = E + K * rede[X][Y] * (rede[X][Y] + rede[X][Y+1]);
      }
    
     }
    }
   M = M + rede[X][Y];
   
   }
  }
 printf ("%lf %lf\n", E, M);
}

 

Revise this Paste

Parent: 45988
Children: 46116
Your Name: Code Language: