How to swap fragment in viewpager?

In the swap function how do i swap x and y value? Is there an easier way to write this program?

  • My values in the swap function did not return could someone help me out? #include<stdio.h> #include<math.h> double swap(double*); int main (void) { char character; int num1; double num2; double y; double x = swap(&y); printf("Enter a character...\n"); scanf("%c",&character); printf("Enter an integer...\n"); scanf("%d",&num1); printf("Enter a real number...\n"); scanf("%lf",&num2); printf("char = %c at memory location : Ox%p\n",character, &character); printf("char = %d at memory location : Ox%p\n",num1, &num1); printf("char = %lf at memory location : Ox%p\n",num2, &num2); printf("%lf %lf",x,y); return 0; } double swap(double*y) { double x = 5; double y = 10; double xx; double yy; xx = x; yy = y; x = yy; y = xx; return x; }

  • Answer:

    Adding to the above comment, try this edited code, maybe it will point you in the right direction (sample run): http://codepad.org/rjwrpp9R __ #include<stdio.h> #include<math.h> double swap(double*); int main (void) { char character='p'; int num1=8; double num2=7.4; double y=9.9; double x = swap(&y); printf("Enter a character...\n"); scanf("%c",&character); printf("Enter an integer...\n"); scanf("%d",&num1); printf("Enter a real number...\n"); scanf("%lf",&num2); printf("char = %c at memory location : Ox%p\n",character, &character); printf("char = %d at memory location : Ox%p\n",num1, &num1); printf("char = %lf at memory location : Ox%p\n",num2, &num2); printf("%lf %lf",x,y); return 0; } double swap(double*y) { double x = 5; double *xx; double *yy; xx = &x; yy = y; x = *xx; y = xx; return x; }

Joe Han at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Adding to the above comment, try this edited code, maybe it will point you in the right direction (sample run): http://codepad.org/rjwrpp9R __ #include<stdio.h> #include<math.h> double swap(double*); int main (void) { char character='p'; int num1=8; double num2=7.4; double y=9.9; double x = swap(&y); printf("Enter a character...\n"); scanf("%c",&character); printf("Enter an integer...\n"); scanf("%d",&num1); printf("Enter a real number...\n"); scanf("%lf",&num2); printf("char = %c at memory location : Ox%p\n",character, &character); printf("char = %d at memory location : Ox%p\n",num1, &num1); printf("char = %lf at memory location : Ox%p\n",num2, &num2); printf("%lf %lf",x,y); return 0; } double swap(double*y) { double x = 5; double *xx; double *yy; xx = &x; yy = y; x = *xx; y = xx; return x; }

.#include <keperkjr>

It doesn't work because you declare this in main() double y; double x = swap(&y); y is not assigned a value. in your function swap, you declare them again, so it will always return 10.

Rainmaker

It doesn't work because you declare this in main() double y; double x = swap(&y); y is not assigned a value. in your function swap, you declare them again, so it will always return 10.

Rainmaker

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.