Saturday, July 2, 2011

C vs. Groovy

A quick program in C and Groovy, You can compare and contrast

/***Cost.groovy***/
//Calculate Cost
def cost (s,r,m) {
s+(r*m)
}

//main portion of progam
(1..10).each{
println "cost for month $it is ${cost(100,10,it) }"
}


/***Cost.c ***/

#include

/* Function protoypes */
float cost(float,float,float);/*Calulates Costs */

/* main function */
void main (void) {
float c=0;
int n;
for (n=1; n<11; n++) {

c=cost(100,10,n);
printf ("Cost for month %i is %f\n",n,c);
}

}



/* Cost Formula */
float cost(float s, float r, float m) {
return (s+(r*m) );
}