Powered By Blogger

Saturday 30 April 2011

Can u guess the output... U jst need a simple concept of bitwise and logical operators in C

#include<stdio.h>
int main(void)
{
    int a[5],i=0,s=0;
    printf("Enter 5 digits (choose digits between 0-9)::\n");
    for(i=0;i<5;i++)
        scanf("%d",&a[i]);


    printf("\n\n");
    for(i=0;i<4;i++)
        printf("%5d|%d=%d",a[i+1],a[i],a[i+1]|a[i]);



    printf("\n\n");
    for(i=0;i<4;i++)
        printf("%5d||%d=%d",a[i+1],a[i],a[i+1]||a[i]);
  
  

Thursday 28 April 2011

Guess why the output is different from the initialized value. Its due to a simple change done while initialization nd with a definite logic.

#include<stdio.h>

#include<conio.h>
int main(void)
{
  int i=012;
  int j=046;
  int k=056;
  printf("i=%d\n",i);
  printf("j=%d\n",j);
  printf("k=%d\n",k);

  getch();

  return 0;
}


A tricky C program to print the string "Hi i'm Subhabrata Chakraborty" without using any semicolon(;) in the function.

#include<stdio.h>
#include<conio.h>
void main(void)
{
  if(printf("Hi I'm Subhabrata Chakraborty"))
}

A tricky C program where a negetive no is shown as greater than positive one. But its not by mistake, there is a definite computing logic.

#include<stdio.h>
#include<conio.h>
int main(void)
{
  unsigned int y = 12;
  int x = -2;
 
   if(x>y)
     printf   (" x is greater");
  else
     printf (" y is greater");
   getch();
 
return 0;
}