“Tukar dua angka di C” Kode Jawaban

Program C untuk menukar dua angka menggunakan variabel sementara

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

bertukar dua angka tanpa menggunakan variabel ketiga di 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("\nAfter swap x=%d y=%d",x,y);
}
Mridul Ghosh

C pemrograman untuk menukar dua variabel

#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;
}
Akash

Program C untuk bertukar dua angka

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

Tukar dua angka di C

#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

Jawaban yang mirip dengan “Tukar dua angka di C”

Pertanyaan yang mirip dengan “Tukar dua angka di C”

Lebih banyak jawaban terkait untuk “Tukar dua angka di C” di C

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya