Write a C program using 2d arrays along with manual tracing?

MANUAL TRACING:
                                        The manual tracing procedure is we should trace out the values from our code at the same time we should print the values, whether the values are formed the sequence or not. Sometimes while we are inserting the values to some array, by our mistakes we left one input, but we have already declared some memory of the whole array if we missed the values in between of the array means that unallocated value memory going to be waste. so that we should give the correct values for each array place. 
         
            Why we need tracing is "While we are running our program sometimes our expected answer will not provide by our written program.  at the same time, this process is used to check the outputs and running procedure whether our program is correct. Everything we can glimpse by using tracing the code. Sometimes we have to zippy about the algorithm  Once we cant do tracing we can't find the absolute solution for our program.

       



WAY OF TRACING:
                                    
                                    1) Programmical Way
                                    2) Hand way (pen+paper)

In a programmatical way, You should implement some code for checking whether your program running smoothly or it's having any pyrrhic kinds of bug inside. while we running the implemented program we can get zippy about the code. 

In the hand way procedure, we should write the code on paper or whiteboard and we should do tracing from the first code to the last end.


PROGRAM:

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

int   trace (int n, int a[n][n]) {

                int i, j;

                double sum=0;

                for (i=0; i<n; i++ ){

                                for (j=0; j<n; j++) {

                                sum=sum+a[i][j];

                                }

                }

                return sum;

}

 

 int main(){

    int n,i,j;

    printf("enter the size of an array :");

    scanf("%d",&n);

                int a[n][n]; //allocate the size

               

                for (i=0; i<n;i++){

                                for ( j=0; j<n; j++){

                                                scanf("%d",&a[i][j]);

                                }

                }

                printf("Program got full size of the outputs");

               

                printf("enterd size of the array is: %d", n);

               

                printf("\n");

                printf("entered Matrix is:\n");

                for (i=0; i<n; i++ ){

                                                printf("\n");

                                for (j=0; j<n; j++ ){

                                                printf("%d\t", a[i][j]);

                                }

                }

                //function called

                int tr;

                tr= trace(n,a);

               

                printf("\nTracing Answer is:%d",tr);

               

}

 

 

 

the above program, It's matrix tracing. I have written the code format of the tracing, here is going to print the sum of the elements which has been present in the matrix. after that, it's going to give the final answer. At the same time, you can do tracing using the manual method. 




No comments:

Post a Comment