Done with exercise 6 chapter 2
This commit is contained in:
parent
c0efe9db77
commit
0dbfe8f78a
38
vagen_till_c/ch2/exercise6.c
Normal file
38
vagen_till_c/ch2/exercise6.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user