This is page is mainly for “My experience with programming”. Have a fun to write programs.
1)how will you print both the IF and ELSE part printf Statements in the C program?
just simple !
int main()
{
if(!printf(“Hello”)){
printf(“Hello”);
}
else{
printf(“World!\n”);
}
}
It will print HelloWolrd!
2)What is the output of the following?
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10,b=20;
if(a++ || b++)
{
printf(” a =%d , b= %d”,a,b);
}
}
Output:
a= 11 , b= 20
here b will not increase because In OR if any one condition satisfies then that will be true. So the first statement “a++” true . So it will not go to second statement “b++”. so the answer will be 11 and 20 for a, b respectively…
3)Swaping of 2 numbers a and b without using third variable
there are many methods but I know only three. lets start…
i)
a^=b^=a^b;
ii)
a=a+b;
b=a-b;
a=a-b;
iii)
a=(b=(a=b+a,a-b),a-b);
<p>Keep Rocking!!!</p>
<p>By Ramkumar.K</p>
Posted by dharani on December 6, 2009 at 9:58 am
nice posts. keep rocking
Posted by Ram Kumar.K on March 28, 2010 at 5:22 am
thanks na..
Posted by M.Manikandan on June 22, 2010 at 12:24 pm
hi … You done Good job…
keep it …
Posted by Ram Kumar.K on November 26, 2010 at 5:05 pm
Thanks MSM…. Enjoy