How to swap two variables, without using third variable ?
Answers were Sorted based on User's Feedback
Answer / deep
let a=5 , b=10
a=a-b
means a=5-10=-5
b=b+a
b=10+(-5)
b=5
a=b-a
a=5-(-5)
a=10
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / d maniteja
let
a=x, b=y our aim is to get output as a=y&b=x;
program:
void main()
{
int a=x,b=y;
a=(a+b)+(a-b);
b=(a+b)-(a-b);
a=a/2;
b=b/2;
printf(("%d %d",a,b);
}
| Is This Answer Correct ? | 0 Yes | 1 No |
without using third variable swap two nos
a=(a+b)-(b-a);
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / gobinath
swap(int *a,int *b)
{
*a=*a-*b;
*b=*a+*b;
*a=*b-*a;
}
| Is This Answer Correct ? | 0 Yes | 1 No |
main() { char string[]="Hello World"; display(string); } void display(char *string) { printf("%s",string); }
main() { int a[10]; printf("%d",*a+1-*a+3); }
Find your day from your DOB?
15 Answers Accenture, Microsoft,
Under linux environment can u please provide a c code for computing sum of series 1-2+3-4+5......n terms and -1+2-3+4-5...n terms..
main(int argc, char **argv) { printf("enter the character"); getchar(); sum(argv[1],argv[2]); } sum(num1,num2) int num1,num2; { return num1+num2; }
Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable, but aac or bcd are unacceptable.
What is "far" and "near" pointers in "c"...?
how can i cast a char type array to an int type array
#include<stdio.h> main() { int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d..%d",*p,*q); }
Write a program to print a square of size 5 by using the character S.
main() { int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i); } a. Runtime error. b. 100 c. Some Integer not 100 d. None of the above
Design an implement of the inputs functions for event mode