Friday, 20 July 2018

C Program Array Example Multiply by index value

ARRAY EXAMPLE IN C:-

information of this program basically header file include stdio.h then start the main function array declared size is equal to 10 defined an array with 10 element then print function use show screen in original values of array then for loop used initial value in 0 for loop exceute in less then 10 then  array index values multiply by 5 then show the result

CODE:-

#include <stdio.h>

int main(void){
// array is a type of variable which can store multiple items of the same data type
// in following simple program we will define an array of 10 elements
//After that we will multiply each element of array with 5 and then we will output the value of each element of the array

int arrayName[10] = {1,2,3,4,5,6,7,8,9,10,}; // defined an array with 10 elements

//output each element of array
printf("Original values of the array\n\n");
printf("Array index\t\t\tValue\n");
for(int i=0; i<10; i++)
{
printf("%11d\t\t\t%4d\n", i, arrayName[i]);
}

//output each element of array
printf("\n\nValues of the array after multiplication\n\n");
printf("Array index\t\t\tValue\n");
for(int i=0; i<10; i++)
{
arrayName[i] = arrayName[i] * 5;
printf("%11d\t\t\t%4d\n", i, arrayName[i]);
}


return 0;
}

No comments:

Post a Comment

Thanks for comment