“échanger en utilisant la troisième variable” Réponses codées

échanger sans utiliser la troisième variable

// SWAPPING WITHOUT USING THIRD VARIABLE
#include<stdio.h>  
 int main()    
{    
int a=10, b=20;      
printf("Before swap a=%d b=%d",a,b);      
a=a+b;//a=30 (10+20)    
b=a-b;//b=10 (30-20)    
a=a-b;//a=20 (30-10)    
printf("\nAfter swap a=%d b=%d",a,b);    
return 0;  
}   
Adventurous Antelope

échanger en utilisant la troisième variable

//The code for a function to Swap two number with a temporary variable is as follows
#include<stdio.h>

void swapping(int, int);  //function declaration
int main()
{
    int a, b;

    printf("Enter values for a and b respectively: \n");
    scanf("%d %d",&a,&b);

    printf("The values of a and b BEFORE swapping are a = %d & b = %d \n", a, b);

    swapping(a, b);      //function call
    return 0;
}

void swapping(int x, int y)   //function definition
{
    int third;
    third = x;
    x    = y;
    y    = third;

    printf("The values of a and b AFTER swapping are a = %d & b = %d \n", x, y);
}
ShrutiBongale

Réponses similaires à “échanger en utilisant la troisième variable”

Questions similaires à “échanger en utilisant la troisième variable”

Plus de réponses similaires à “échanger en utilisant la troisième variable” dans C

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code