by CodeChum Admin
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 array[40] = {-2, -1, 1, 2, 3, 4, 3, -2, 1, 3,
-1, 2, 3, -3, 5, 2, -2, 3, 1, -2,
2, 3, -1, -3, 2, 4, 5, 7, -5, -3,
4, 3, -2, -1, -4, -5, 3, 2, -2, 3 };
for (int i=0; i<40; i++) {
if (array[i] < 0)
printf("%d\n", array[i]*array[i]);
else
printf("%d\n", array[i]*array[i]*array[i]);
}
return 0;
}
Comments
Leave a comment