Nov 22, 2012

0 B.T: Print “HelloWord”


What is the “condition” so that the following code prints both HelloWorld !
      if  "condition"
          printf ("Hello");
      else
          printf("World");


Solution:
#include<stdio.h>
int main()
{
    if(!printf("Hello"))
        printf("Hello");
    else
        printf("World");
    getchar();
}       
Explanation: Printf returns the number of character it has printed successfully. So, following solutions will also work
if (printf(“Hello”) < 0) or
if (printf(“Hello”) < 1) etc

Please Comment on solution and try to give more solution.

0 comments:

Post a Comment

 

T.I.P - Tech Info Portal Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates