Write C function INC(int array[5],int n) that accepts two parameters array of five integers and integer, and adds the integer n to all array elements , then it returns the new array , as example if array[5]={1,5,7,0,2} and n =5 after function call we have array[]={6,10,12,5,7}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void INC(int *pointer,int n) | |
{ | |
for(int x=0;x<=4;x++) | |
{ | |
*(pointer+x)+=n; | |
} | |
return; | |
} | |
int main() | |
{ | |
int N;printf("enter the number you want to add to all array elements\n"); | |
scanf("%d",&N); | |
int array[5]={1,5,7,0,2}; | |
INC(array,N); | |
printf("array after function call\n"); | |
for(int i=0;i<=4;i++) | |
{ | |
printf("%d\t",array[i]); | |
} | |
return 0; | |
} |
No comments:
Post a Comment