Thread: Kind of logic problem,could use some help :)

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    18

    Kind of logic problem,could use some help :)

    Ok so my professor left us 5 programs we need to do. Sadly he only gave us these sort of header's wich we need to somehow figure out what the program is supposed to do and do it >.< problem is im stumped. I did the first one,was preety easy, logic was to order the numbers from highest to lowest. The other 4 have me stumped though, so i was wondering if you guys could help me out a bit by telling me what you think the program is supposed to do. Again the homework is not figuring out what the structure's are supposed to do, it's doing the actual program's. Anyway's the structure's are the following:

    1st
    Code:
    for i= 1 to n
    	for j= 1 to n
    		suma= 0
    		for k= 1 to n
    			suma= suma + a[i, k]•b[k, j]
    		endfor
    		c[i, j]= suma
    	endfor
    endfor
    2nd
    Code:
    Calculate the time of execution and the exact order of the algoritm:
    
    p = 0
    for i = 1 to n
    	p = p + i*i
    	for j = 1 to p
    		write (a[p, j])
    	endfor
    endfor
    3rd
    Code:
    PROCEDURE invierte (A: array [0..n, 0..n] of integer);
    var
    	i, j: integer;
    begin
    	for i:= 0 to n-1 do
    		for j:= i+1 to n do
    			A[i, j]:= 2*A[j, i]+A[i, j];
    end;
    Any help would be appreciated. Thank you all for your time.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I'm supposing that since your homework has a lot of pseudocode floating around, if you knew how to read it, you would find thinking a whole lot easier.
    http://ironbark.bendigo.latrobe.edu....ode_guide.html

    I notice that how one writes psuedocode is something that varies from person to person, so just try to exercise your interpreting skills.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    18
    Quote Originally Posted by citizen
    I'm supposing that since your homework has a lot of pseudocode floating around, if you knew how to read it, you would find thinking a whole lot easier.
    http://ironbark.bendigo.latrobe.edu....ode_guide.html

    I notice that how one writes psuedocode is something that varies from person to person, so just try to exercise your interpreting skills.
    Although i do appreciate the advice this is due tomorrow,and i really need to have this done before i need to go to work so i do appreciate the guide's but learning by example is much easier, what i mean is once i actually know what these are supposed to do i'll prob have a much better grasp of pseudocode.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >we need to somehow figure out what the program is supposed to do and do it >.<
    I don't see where you need to figure out what the program is supposed to do. Why not just take the pseudocode your professor gave you and convert it to C? How long can that take? Every piece of code given is under ten lines.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Quote Originally Posted by yrostran
    Although i do appreciate the advice this is due tomorrow,and i really need to have this done before i need to go to work
    Please don't tell us you waited til the last minute.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    18
    Quote Originally Posted by swoopy
    >we need to somehow figure out what the program is supposed to do and do it >.<
    I don't see where you need to figure out what the program is supposed to do. Why not just take the pseudocode your professor gave you and convert it to C? How long can that take? Every piece of code given is under ten lines.
    Nay tried that, how can you do a program without know what it's supposed to do? Sure you can do all the for's,else's,etc but in the end what are you going to print out if you have no idea what you're supposed to be doing. I know it has to do with matrixes it seem's so bi-dimensional array's but that's about it sadly

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    18
    Quote Originally Posted by swoopy
    Please don't tell us you waited til the last minute.
    I got home from class an hour ago i got work in 3 hour's,i don't leave anything till the last minute but my schedule in the day is really hectic sadly can't even quit my job and only study it sux.

  8. #8
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Since I'm somewhat sympathetic to your plight, I'll give you some hints. But I don't see how you can't be understanding these. Learn to read pseudocode. You'll get nowhere if you can't read it and you're likely to fail the class.

    1) It's matrix multiplication.

    2) This one is strictly understanding the question. You don't even NEED to know what the code does to do this question.

    3) I'm not quite sure of this one, it seems to be doing some kind of matrix operation again. I'm not sure if it's the inverse or not (don't think so). But it is some sort of manipulation with matrix elements.

    Again, learn pseudocode. Fast.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  9. #9
    Registered User
    Join Date
    May 2006
    Posts
    18
    Quote Originally Posted by Happy_Reaper
    Since I'm somewhat sympathetic to your plight, I'll give you some hints. But I don't see how you can't be understanding these. Learn to read pseudocode. You'll get nowhere if you can't read it and you're likely to fail the class.

    1) It's matrix multiplication.

    2) This one is strictly understanding the question. You don't even NEED to know what the code does to do this question.

    3) I'm not quite sure of this one, it seems to be doing some kind of matrix operation again. I'm not sure if it's the inverse or not (don't think so). But it is some sort of manipulation with matrix elements.

    Again, learn pseudocode. Fast.
    I'm trying belive me i was doing good till these hit me,probably because i don't really remember matrixes much.

  10. #10
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    How about coding as best you can, and seeing what comes out ? I mean you can almost copy-paste what's on the assignment and you'll pretty much have a working program...
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  11. #11
    Registered User
    Join Date
    May 2006
    Posts
    18
    Quote Originally Posted by Happy_Reaper
    How about coding as best you can, and seeing what comes out ? I mean you can almost copy-paste what's on the assignment and you'll pretty much have a working program...
    Ok ill try it

  12. #12
    Registered User
    Join Date
    May 2006
    Posts
    18
    This is the 1st one,i think at least,take a look:

    Code:
    #include "stdio.h"
    #include "conio.h"
    
    void main()
    {
       static int a[10] [10];
       static int b[10] [10];
       static int c[10] [10];
    
       int i,j,k,l,m,n,p,q;
    
       clrscr();
    
       printf ("Ponga las dimensiones para el arreglo A filas x columnas \n");/*Dimensions Array for Matrix A*/
       scanf ("%d %d",&m,&n);
    
       printf ("Ponga las dimensiones para el arreglo B filas x columnas \n");/*Dimensions Array for Matrix B*/
       scanf ("%d %d",&p,&q);
    
       if (n!=p)
       {
          printf("Multiplicacion de matrices no es posible\n");
    
          printf ("Dimension de matrices no es valida");
    
       }
    
       else
       {
    
    
          printf ("Introduzca los elementos en el arreglo A \n");/*Reading the arrays for matrix A*/
    
    
          for (i=0; i<m; i++)
          {
    
    	 for (j=0; j<n; j++)
    	 {
    	    scanf ("%d",&a[i] [j]);
    
    	 }
    
          }
    
          printf("\nEl arreglo A es el siguiente: \n");/*prints on screen matrix A*/
    
    
          for(i=0; i<m; i++)
          {
    
    	 for(j=0;j<n;j++)
    	 {
    
    
    	    printf("%d ", a[i][j]);
    
    	 }
    	 printf("\n");
    
         }
    
    
    
          printf ("\nIntroduzca los elementos en el arreglo B \n");/*Reading the arrays for matrix A*/
    
    
    
          for (k=0; k<p; k++)
          {
    
    
    	 for (l=0; l<q; l++)
    	 {
    
    	    scanf ("%d",&b[k] [l]);
    	 }
          }
    
          printf("\nEl arreglo B es el siguiente: \n");/*prints on screen matrix B*/
    
          for(k=0;k<p;k++)
          {
    
    	 for(l=0;l<q;l++)
    	 {
    	    printf("%d ", b[k][l]);
    
    	 }
                     printf("\n");
           }
    
          for (i=0; i<m; i++)
          {
    	 for (l=0; l<q; l++)
    	 {
    	    for (j=0; j<n; j++)
    	    {
    	       c[i] [l] = c[i] [l] + a[i] [j] * b[j] [l];
    	    }
    
    
    	 }
    
    	  }
    	  clrscr();
          printf("\n");
          printf("El resultado de la multiplicacion es el sig: \n");/*Printing of result of the multiplication*/
    
          for (i=0; i<m; i++)
          {
    	   l=0;
    	   while (l<q)
    	   {
    	      printf (" %d ",c[i] [l]);
    	      l++;
    
    	   }
                       printf ("\n");
    
          }
    
       }
    
       getch();
    }
    Sorry it's in spanish, im from latinamerica

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Digital Logic
    By strokebow in forum Tech Board
    Replies: 3
    Last Post: 12-09-2006, 01:05 PM
  2. Logic
    By LordBronz in forum C++ Programming
    Replies: 6
    Last Post: 05-23-2006, 05:41 PM
  3. Actors, cues, event based logic.
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 04-27-2006, 10:58 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM