Create an index multiplier using C beginner level
Hey guys once again welcome to the Decoders blog, I hope you all are doing well and today I'm present with another logic but this time with something different it is a C logic which will help us to multiply the given element of an array with it's corresponding index.
Here's the code which you can go through...........
#include<stdio.h>
int main()
{
int array[50];
int len,n,i,answer=0;
printf("Enter the length of the array:\n");
scanf("%d",&len);
//Storing the values of the array
printf("Enter the value for the array:\n");
for(i=0;i<len;i++)
{
scanf("%d",&array[i]);
}
//Logic to multiply the element of the array with it's index
for(i=0;i<len;i++)
{
answer += array[i]*i;
}
//Displaying the final output
printf("The required value is %d",answer);
return (0);
}
Comments
Post a Comment