1 Write Function Swap Two Double Values Pointers Parameters 2 Write Main Function Declare Q37038908

1. Write a function to swap two double values with pointers asparameters.

2. Write a main function which declare two double variables withinitial values: x=1.2 and y=4.5, print them out, then call swapfunction to switch x and y values, then print them out too.

C programming language


Solution


#include <stdio.h>void swap(double *n1, double *n2) { double temp = *n1; *n1 = *n2; *n2 = temp;}int main() { double x=1.2, y=4.5; printf(“Before swap, x=%lf and y=%lfn”, x, y); swap(&x, &y); printf(“After swap,

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.