Search
 
SCRIPT & CODE EXAMPLE
 

C

variable swap in c

// swap variables in C
void swap(int *x, int *y){
	int temp = *x;
    *x = *y;
    *y = temp;
}
swap(&a, &b); // address of a and b
Comment

swapping of two numbers without using third variable in c

#include<stdio.h>
void main()
{
	int x = 10, y = 20;
    printf("Before swap x=%d y=%d",x,y);
    x=x+y;
    y=x-y;
    x=x-y;
    printf("
After swap x=%d y=%d",x,y);
}
Comment

swapping two numbers in c

//Author: Subodh
        //! Swap two number using XOR operation
        cout << "Before, n1 = " << num1 << ", n2 = " << num2 << endl;
        num1 = num1 ^ num2, num2 = num1 ^ num2, num1 = num1 ^ num2;
        cout << "After, n1 = " << num1 << ", n2 = " << num2 << endl;
Comment

c program for swapping of two numbers using temporary variable

#include <stdio.h>
int main()
{
    int a, b, temp;
    printf("enter the values of a and b: 
");
    scanf("%d%d", &a, &b );
    printf("current values are:
 a=%d
 b=%d
", a, b);
    temp=a;
    a=b;
    b=temp;
    printf("After swapping:
 a=%d
 b=%d
", a, b);
}
Comment

C Programming to swap two variables

#include <stdio.h>

int main()
{
    int x = 20, y = 30, temp;
    temp = x;
    x = y;
    y = temp;
    printf("X = %d and Y = %d", x, y);
    
    return 0;
}
Comment

c program for swapping of two numbers

// Overcomplicating things lol. Try this
#include <stdio.h>
int main()
{
    int x, y;
    printf("Enter Value of x ");
    scanf("%d", &x);
    printf("
Enter Value of y ");
    scanf("%d", &y);
    int temp = x;
    x = y;
    y = temp;
    printf("
After Swapping: x = %d, y = %d", x, y);
    return 0;
}
Comment

variable swap in c

// swap variables in C
void swap(int *x, int *y){
	int temp = *x;
    *x = *y;
    *y = temp;
}
swap(&a, &b); // address of a and b
Comment

how to swap values in variables in c

#include <stdio.h>
#include <stdlib.h>

int main()
{
  	//initialize variables
	int num1 = 10;
	int num2 = 9;
  	int tmp;
  	
  	//create the variables needed to store the address of the variables
  	//that we want to swap values
  	int *p_num1 = &num1;
  	int *p_num2 = &num2;
  
  	//print what the values are before the swap
  	printf("num1: %i
", num1);
    printf("num2: %i
", num2);
  
  	//store one of the variables in tmp so we can access it later
  	//gives the value we stored in another variable the new value
  	//give the other variable the value of tmp
  	tmp = num1;
  	*p_num1 = num2;
  	*p_num2 = tmp;

  	//print the values after swap has occured
   	printf("num1: %i
", num1);
    printf("num2: %i
", num2);
  	
	return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: double array in c 
C :: C Passing Pointers to Functions 
C :: fopen in c example 
C :: c recursion func revers number 
C :: plt legend top right outside 
C :: c read n bytes code 
C :: Fibonacci Series Program. in c 
C :: c programming language 
C :: c convert float to string 
C :: how to add 1 to 10 in c 
C :: c language string 
C :: malloc basics 
C :: bubble sort 
C :: delay in c programming for windows 
C :: casting in c 
C :: Program to Check Whether Character is Lowercase or Not without using islower function 
C :: c program to implement mv command 
C :: do while loop in c 
C :: c extern 
C :: vifm preview images 
C :: c command line arguments parser 
C :: static variable c 
C :: how to input a string into a char array cpp 
C :: ansi c read write bmp 
C :: how to print chicken in c 
C :: retoure a la ligne C 
C :: How to declare a string? 
C :: call cuda kernel from c parameters 
C :: curl ftp upload file to directory 
C :: gtk widget change window title 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =