Programming Example
C Program to add array Elements with a constant
add array Elements with a constant
// How to add array Elements with a constant
#include<stdio.h>
void main()
{
int array[] ={0,1,2,3,4,5,6,7,8,9,10,11};
// Here the constant vale is 10
ExtOp(array,10,0,11); // function calling
}
void ExtOp(int array[],int MyCon,int start,int finish)
{
int i=start;
for(i=0;i<=finish;i++)
{
//multiplication with every element
array[i]+= MyCon;
printf("%d ",array[i]);
}
}
10 11 12 13 14 15 16 17 18 19 20 21
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.