Thursday, 24 January 2013

C program to run the body of if condition as well as body of else condition

C program to run the body of if condition as well as body of else condition

First program (using goto)


#include<stdio.h>

#include<conio.h>
void main()
{
      if(1)
        {
            printf("Hi Mayank");
            goto A;
         }
    else
       {
          A:
          printf("\nShekhar ");
          for(int i=1;i<11;i++)
          printf("%d ",i);
        }
 getch();
 }

Output :   Hi Mayank
                 Shekhar 1 2 3 4 5 6 7 8 9 10



Second program (using macro)




#include<stdio.h>

#include<conio.h>

#define else if(1)

void main()
{
      if(1)
        {
            printf("Hi Mayank");
         }
    else
       {
         
 printf("\nShekhar ");


          for(int i=1;i<11;i++)
          printf("%d ",i);
        }
 getch();
 }

Output :   Hi Mayank 
                 Shekhar 1 2 3 4 5 6 7 8 9 10



No comments:

Post a Comment