You can also make a list of numbers, ey? Let's go and have some fun in tweaking the values of each element, but let's give it some twist to add on some fun to the code.
Let's have a go at it!
Instructions:
Output
The squares and cubes of the elements in the array.
4
1
1
8
27
.
.
.
#include <stdio.h>
int main() {
int arr[40] = {3, -3, 4, 5, -4, 1, -3, 4, 6, 7,
4, -3, -2, 6, 0, -5, 3, 8, -5, -7,
-3, -3, 3, 5, 6, -11, -6, 7, 3, -2,
8, -6, 5, 8, -2, -1, 8, -4, 4, 6 };
for (int i=0; i<40; i++) {
int res = arr[i]*arr[i];
if (arr[i] > 0) {
res *=arr[i];
}
printf("%d\n", res);
}
return 0;
}
Comments
Leave a comment