In: Computer Science
Write a function cube_all_lc(values) that takes as input a list of numbers called values, and that uses a list comprehension to create and return a list containing the cubes of the numbers in values (i.e., the numbers raised to the third power). This version of the function may not use recursion.
#include <stdio.h>
#include<math.h>
int size=0;
int* cube_all_lc(int* cube )//Function for calculating cubes
{
int i;
for(i=0;i<size;i++)
{
cube[i]=pow(cube[i],3);
}
return cube;
}
int main()
{
int cube[10];
int index=0;
int* result;
printf("\nenter size of array: ");
scanf("%d",&size);//Reading Size of
array
printf("Enter elements:-");
for(index=0; index < size;
index=index+1)
{
scanf("%d",
&cube[index]);//Reading inputs to array.
}
result=cube_all_lc(cube);//Function
calling
printf("\nOutput:-\t ");
for(index=0;index<size;index++)
{
printf(" %d
",result[index]);
}
return 0;
}
Output :