pointers q 2
- Write a program to change the value of a variable to n times its current value. Write a function and pass the value by reference.
#include <stdio.h>
int n_mulplier( int *a , int n ){
int c = (n * (*a));
*a=c;
printf(" multiplication is %d\n", c );
return ;
}
int main() {
// Write C code here
int a , n ;
printf(" enter value of a : ");
scanf("%d",&a);
printf(" enter value of n : ");
scanf("%d",&n);
printf("a and n are %d and %d before fuction\n", a , n );
n_mulplier(&a , n);
printf("a and n are %d and %d after function\n", a , n );
printf("value of a after multiplier is %d", a );
return 0;
}
Comments
Post a Comment