Tuesday 17 December 2013

Write a program which takes a integer and prints “YES” if its binary code (Excluding most significant bit) and its reverse are same;otherwise print “NO” for example 0101101101101

#include<stdio.h> int main() { int num,NOBITS; unsigned int firstbitmask=1,lastbitmask,x,y; NOBITS=8*sizeof(int)-1; lastbitmask=firstbitmask<<NOBITS; printf("Enter a number"); scanf("%d",&num); while(lastbitmask>firstbitmask) { x=num&lastbitmask; y=num&firstbitmask; if(((x==0)&&(y==0))||(x && Y)) { lastbitmask <<=1; firstbitmask >>=1; } else break; } if(lastbitmask==firstbitmask) printf("YES"); else printf("NO"); return 0; }

Write a program which reads a set of integers into an integer array and then prints those numbers which occurs only once

#include<stdio.h> int main() { int i, n, a[10], j, c; printf("Enter a number\n"); scanf("%d",&n); printf("Enter %d number\n",n); for(i=0;i<n;i++) {scanf("%d",&a[i]);} for(i=0;i<n;i++) /*To traverse array element by element */ { c=0; /* counter is initialized to 0 */ for(j=0;j<n;j++) { /* comparing ith element with all other elements */ If(a[i]==a[j]) c++; } if(c==1) printf("%d\n",a[i]); } return 0; }