Let Us C (Chapter 8 : Arrays) : Program-8

(h) Write a program which performs the following tasks:
1) initialize an integer array of 10 elements in main( )
2) pass the entire array to a function modify( )
3) in modify( ) multiply each element of array by 3
4) return the control to main( ) and print the new array elements in main()

let us c chapter 8 arrays problem 8

// Let Us C (Chapter 8 : Arrays) : Program-8
/* (h) Write a program which performs the following tasks:
1) initialize an integer array of 10 elements in main( )
2) pass the entire array to a function modify( )
3) in modify( ) multiply each element of array by 3
4) return the control to main( ) and print the new array elements in main() */
#include<stdio.h>
void modify(unsigned int *);    // Function declaration
void main()
{
    int i,j=1,Arr[10];
    clrscr();
    for(i=0;i<10;i++)
    {
        Arr[i]=j++;
        printf("%2d ",Arr[i]);
    }
    printf("\n");
    modify(Arr);    // Function call, passing array to function
    for(i=0;i<10;i++)
        printf("%2d ",Arr[i]);
}

void modify(unsigned int *New)    // Function definition
{
    unsigned char k;
    for(k=0;k<10;k++)
        New[k] = New[k] * 3;
}

OUTPUT

let us c chapter 8 arrays problem 8 output


Comments

Popular posts from this blog

Chapter 5 : Functions & Pointers (Let us C)

Let Us C (Chapter 8 : Arrays) : Program-9

Chapter 3: The Loop Control Structure (Let Us C)