Programming Talk

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>

4 responses to this post.

  1. nice posts. keep rocking

    Reply

  2. hi … You done Good job…
    keep it …

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.