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()
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) : 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;
}
Comments
Post a Comment