#include
int cubit(int k){
return k*k*k;
}
int main(void){
int j;
for(j=1;j<100;j+=2)
printf("%d ",cubit(j));
return 0;
}
/*
** filename: stup.c
*/
#include
int cub(int);
int main(void) {
int i;
for (i = 1; i < 100; ) {
printf("The cube of %d is %d\n", i, cub(i));
i += 2;
}
return 0;
}
int cub(n) {
return n*n*n;
}
>
> John (gnujohn@gmail.com) [There are times when you don't need tricky modular %]
int main (int argc, const char * argv[])
{
int i;
for(i=1;i<=100;i++)
{
if(i%2==1)
{
printf("%d cubed is %d\n",i,cubelt(i));
}
}
}
int cubelt(int num)
{
return num*num*num;
}
Here's a screenshot of the code.http://tinypic.com/r/2j5exzl/8
I tested it and it works.
Best Regards,
Write a program that will calculate and print out the third power of the ODD numbers between 1 and 100. You must use the following:
counter-controlled loop
function cubeIt that takes one integer as an argument and returns that number cubed
output looks like this:
1 cubed is 1
3 cubed is 27
5 cubed is 125