valid xhtml valid
css valid

feed site feed
blog feed
Latest Project:
Follow Me:
Let's Play:
  • »  Call Of Duty 4
  • »  GTA IV
  • »  Metal Gear Solid 4
PSN ID: mystery-man
  • »  Team Fortress 2
  • »  Counter Strike Source
steam ID:marioandrei
A series of Tubes!:
Currently Reading:
  • »  Kafka on the Shore
  • »  The Shock Doctrine
  • »  Terror And Power
Flickr

Programming by the people for the people

Some Basic Pascal and C Examples first: (You should not try to learn how to programm with me, you need a good book or teacher. Knowing Syntax does not make you a programmer.)

  • while/if/for
  • Recursion
  • RTFM

Sorting Algorithms

First You should go to wikipedia and try to learn what every single sort algorithm does, the "classics" are Bubblesort, Quicksort, Mergesort, Heapsort. Take a look to my code and maybe it may help! of course, you should try to doit by yourself but a little help is not bad. Bubblesort
    1 int bubblesort(int* tabla, int ip, int iu)
    2 {
    3     int i, j , temp , swapped;
    4     swapped=1;
    5     i=iu;
    6     while ( (i>=ip+1) && (swapped==1)) {
    7         swapped=0;
    8         for ( j=ip ; j <= (i-1) ; j++) {
    9             if ( tabla[j] > tabla[j+1] ){
   10                 /* SWAP */
   11                     temp=tabla[j];
   12                     tabla[j]=tabla[j+1];
   13                     tabla[j+1]=temp;
   14                     swapped=1;
   15             }
   16         }
   17         i--;
   18     }
   19     return OK;
   20 }

Pascal

    1 program cadena;
    2 
    3 function powersOf10(e:integer):integer;
    4     var
    5         i,n:integer;
    6     begin
    7         n:=1;
    8         for i:=1 to e do
    9             n:=n*10;
   10         powersOf10:=n;
   11     end;
   12 
   13 function stringToInt(s:string):integer;
   14     var
   15         i,j,n:integer;  
   16     begin
   17         i:=0;
   18         j:=0;
   19         n:=0;
   20         for i:=ord(s[0]) downto 1 do
   21             begin
   22                 n:=n+(ord(s[i])-ord('0'))*powersOf10(j);
   23                 j:=j+1;
   24             end;
   25         stringToInt:=n;
   26     end;
   27     
   28 var
   29     s:string;
   30 begin
   31     read(s);
   32     writeln(stringToInt(s)+1);
   33 end.

ANSI C

n!

Don't worry, I'll update this page with more useful algorithms.


    1 /* factorial!*/
    2 float factorial (int n)
    3 {
    4     int producto=1;
    5     
    6     if(n==0)
    7         return 1;
    8     else
    9     {
   10         producto=n*factorial(n-1);
   11         return producto;
   12     }   
   13 }
   14 
   15 /* programa principal*/
   16 int main()
   17 {
   18     /*variables*/
   19     int iteraciones,i;
   20     float numero_e=0;
   21 
   22printf("e \n numero de iteraciones");
   23     scanf("%d", &iteraciones);
   24     for (i = 0; i < iteraciones; i++)
   25numero_e=numero_e+(1/(factorial(i)));
   26     printf("el numero e = %4.8f \n", numero_e); 
   27     return 0;
   28 }
back to top