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>
#include <stdlib.h>
int main(){
int nums[] = { -2, 1, 1, 2, 3,
9, 10, -3, 100, 2,
4, -5, 1, 10, -100,
5, 2, 3, -1, 1,
-3, -4, -5, -6, -7,
9, 9, 9, 9, 9,
1, 2, 3, 4, 5,
100, 50, 20, -51, -99};
int i;
for(i=0;i<40;i++){
if(nums[i]<0){
printf("%d\n",nums[i]*nums[i]);
}else{
printf("%d\n",nums[i]*nums[i]*nums[i]);
}
}
getchar();
getchar();
return 0;
}
Comments
Leave a comment