C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf
35 comments:
#define SWAP(x,y) x^=y^=x^=y
would serve
hi TRINATH SOMAROUTHU
Thank you for posting another solution
#define swap(x,y) x^=y^=x^=y
void main()
{
int a=10,b=20;
swap(a,b);
clrscr();
printf("%d %d" ,a,b);
getch();
}
output: 20 10
void main()
{
int a,b,c;
clrscr();
printf("\n Enter two no ");
scanf("%d%d",&a,&b);
printf("\n Before Swaping value of a and b %d %d",a,b);
c=a;
a=b;
b=c;
printf("\n After Swaping value of a and b %d %d",a,b);
getch();
}
THANKS ,THANKS A LOT
good job..
please solve the problem
int a=~-3;
actually i do,not understand about ~ operator that how exactly it works .please solve step by step
process 4 is not working
error is 'wrong type argument to bit-complement' in float value
can anybody explain in detail how a=a+b-(b=a); will work out for swapping
its using third var...
Here is couple of more way to swap two numbers without using temp variable in Java
learn c programming and c graphics from programmingcampus
where you can get best online tutorials which make simple and easy to your learning.
a=a+b
a=a-b
b=a-b
thank u very much. this is the best solution without using third variable. simple and short
u r most welcome
a=a+b-(b=a)
now since value of a will be assigned to b
so equation will be
a=a+b-(a)
a=b
read the question first. we don't have to use third variable.
HI can u please help me to solve the following
Swap the values in 2 variBles using a third variAble?? Plzzzzz rply its urgent
Process 1 & 5 are approx same.
First take 2's complement of -3 which will be as:
3
= 0000 0011 // binary value of 3
= 1111 1100 // take 1's complement i.e invert 0's & 1's
2's complement = 1111 1101 // add 1
We have got result for -3. Now operation for ~ (1's complement is pending). We know in 1's complement 0's will replaced by 1's & 1's will be replaced by 0's as we did above in second step.
Therefore 1's complement of 1111 1101 will be =
0000 0010
Result = 2
Hi trinath your this program do my help & made my image in class is a intelligenc boy so thenku very much
I have got another simple solution for this.
A=A*B
B=A/B
A=A/B
Swaping done.
@Ashok Natarajan this is also correct when given both values some numbers.. if your give A=0,B=4 that time floating exception will happen..
the right order is a=a+b,b=a-b,a=a-b
Swapping of two numbers can be done in 5 methods u can see in following url...
www.programmerschat.blogspot.in
yupp...its correct order..(y)
one more way
#include
#include
int main( )
{
static int a=2,b=5;
a=a*b;
b=a/b;
a=a/b;
printf(" a =%d\t b=%d",a,b);
}
void main()
{
int a,b;
clrscr();
printf("\n Enter two no :");
scanf("%d%d",&a,&b);
printf("\n Before Swaping value of a and b %d %d",a,b);
b=a+b-(a=b);
printf("\n After Swaping value of a and b %d %d",a,b);
getch();
}
process 4 is not working. I things it's
b= b - ~a - 1;
a= a + ~b +1;
what u say?
if do not use third variable then
How to swap 2 variable using only assignment operator and no other operator in C
plz help me
1 + X +( X2 / !2 )+ ( X3 / !3 ) + ( X4 / !4 )
plz help me
swap two numbers without using third variable
Nice article . There is good coding example collection visit
Top coding program example
Good questions on c programming language. Will share it on our programming site.
Post a Comment