Can anybody explain this program? | Sololearn: Learn to code for FREE!

+1

Can anybody explain this program?

#include <stdio.h> #define LEN1 6 #define LEN2 6 int x[2*LEN1-1]={1,2,3,4,5,6,0,0,0,0,0}; int h[2*LEN1-1]={1,2,3,4,5,6,0,0,0,0,0}; int y[LEN1+LEN2-1]; int main() { int i=0,j; for(i=0;i<(LEN1+LEN2-1);i++) { y[i]=0; for(j=0;j<=i;j++) y[i]+=x[j]*h[i+j]; } for(i=0;i<(LEN1+LEN2-1);i++) printf("%d\n",y[i]); }

10/2/2021 12:17:10 PM

Lalitkumar Prajapat

2 Answers

New Answer

+2

Take pen copy and do dry run put values one by one you will understood better

+2

The #define statements are macros. These macros are handled by the C preprocessor which performs simple text substitution. Everywhere LEN1 or LEN2 appears in the code will be replaced by the numbers int the macro, in this example they are both 6.