اكتب برنامج C يقوم بتبديل رقمين دون استخدام متغير ثالث

  • برمجة
  • برمجة سي c

اكتب برنامج C يقوم بتبديل رقمين دون استخدام متغير ثالث

مثال عن الخرج المتوقع :

Input value for x & y:
Before swapping the value of x & y: 5 7
After swapping the value of x & y: 7 5

الأجوبة

/*Write a C program that swaps two numbers without using third variable*/

#include<stdio.h>
int main()
{
int x, y;
printf("Input value for x & y: \n");
scanf("%d%d",&x,&y);
printf("Before swapping the value of x & y: %d %d",x,y);
x=x+y;
y=x-y;
x=x-y;
printf("\nAfter swapping the value of x & y: %d %d",x,y);
return 0;
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...