Wednesday 31 October 2012

Pointer003

Input two numbers and swap them.

#include<stdio.h>
#include<conio.h>
void swap ( int*, int* );
void main ( )
{                  
        int      m, n;
        clrscr ( );
                                     
        printf("\n\n\n\t\t   Enter 1st number..:"); scanf("%d",&m);
        printf("\n\t\t   Enter 2nd number..:"); scanf("%d",&n);
                                
        swap ( &m, &n );
        printf("\n\n\n\n\t\t -- Values after swapping --");
        printf("\n\n\t\t      First value   = %d",m);
        printf("\n\t\t      Second value = %d",n);
        getch ( );
}                           
                   
void swap ( int     *p, int     *q )
{                 
        int     t;
        t = *p;
        *p = *q;
        *q = t;
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...