diff --git a/vagen_till_c/ch2/exercise6.c b/vagen_till_c/ch2/exercise6.c new file mode 100644 index 0000000..edbcf26 --- /dev/null +++ b/vagen_till_c/ch2/exercise6.c @@ -0,0 +1,38 @@ +#include + +/* My solution to exercise 6 chapter 2 from "Vägen till C". + * Rewrite excercise 3 to let square and cube be functions + */ + +int square(int j) +{ + j = j*j; + return j; +} + +int cube(int k) +{ + k = k*k*k; + return k; +} + +int main() +{ + int n, i, s; + s = 1; + + printf("Enter an integer: "); + scanf("%d", &n); + + printf(" i i*i i*i*i \n"); + printf("=== ===== =======\n"); + + for(i=0; i<=n; i++) + { + printf(" %1d %7d %8d \n", s, square(s), cube(s)); + s++; + } + + return 0; +} +