Thursday, September 17, 2009

log

1.Which statement will you add in the following program to work it correctly?
#include
int main()
{
printf("%f\n", log(36.0));
return 0;
}

answer:#include"math.h"

2.We want to round off x, a float, to an int value, The correct way to do is
A.

y = (int)(x + 0.5)

B.

y = int(x + 0.5)
C.

y = (int)x + 0.5
D.

y = (int)((int)x + 0.5)



3.

Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?
A.

rem = (5.5 % 1.3)
B.

rem = modf(5.5, 1.3)
C.

rem = fmod(5.5, 1.3)

D.

Error: we can't divide

Difference between combinational logic circuit and sequential logic circuit?

The main difference between sequential circuits and combinational circuits is that sequential circuits compute their output based on input and state, and that the state is updated based on a clock.

Combinational logic circuits implement Boolean functions, so they are functions only of their inputs, and are not based on clocks.

combinational =========================== sequencial
1.memory unit is not required =============1 it is require to store the past history
2.it is faster =================== 2. less compare to that one
3.easy to design ====== 3. comparatively garder
4.parallel adder ============== 4. serial adder

latch and flipflops

tch is a level triggered device but flip flop is a edge triggered device.

Latch takes less gates but flipflop takes more.
Latch faster flipflop
slower.
Latch does'nt have a clock signal but flip flop depends on the
clock signal but both are having one bit memory.

latch is a device which is used as switch,f/f is a storing
element

Write a C program to determine the number of elements (or size) in a tree.

Try this C program

int tree_size(struct node* node)
{
if (node==NULL)
{
return(0);
}
else
{
return(tree_size(node->left) + tree_size(node->right) + 1);
}

Write C code to determine if two trees are identical

Here is a C program using recursion

int identical(struct node* a, struct node* b)
{
if (a==NULL && b==NULL){return(true);}
else if (a!=NULL && b!=NULL)
{
return(a->data == b->data &&
identical(a->left, b->left) &&
identical(a->right, b->right));
}
else return(false);
}

Write a C program to find the mininum value in a binary search tree.

Here is some sample C code. The idea is to keep on moving till you hit the left most node in the tree

int minValue(struct node* node)
{
struct node* current = node;

while (current->left != NULL)
{
current = current->left;
}
return(current->data);
}

On similar lines, to find the maximum value, keep on moving till you hit the right most node of the tree.

Write a C program to compute the maximum depth in a tree?

int maxDepth(struct node* node)
{
if (node==NULL)
{
return(0);
}
else
{
int leftDepth = maxDepth(node->left);
int rightDepth = maxDepth(node->right);
if (leftDepth > rightDepth) return(leftDepth+1);
else return(rightDepth+1);
}
}

Tuesday, September 15, 2009

Interview questions

aptitude

1..1 8 27 64 ....? 125

2. some diagram representation oriented q's?

3. card's question ?
like they given six cards ..we want to arrange some specified order..

4.

c question

1.mention lib function for appending one string to another string ?
strcat

2. for strlen() fuction can run under which lib funtion?

string.h

3. fseek syntax

fseek(char #buffer,offset,seek-end);

4. is there any direct function for exponential?
ya its possible by exp(x)

5. write a program for finding a strlen without using lib function?

for(i=0;str[i]<null;i++);

6. following function which one is odd?
alloc calloc malloc realloc

i think it is calloc

7. pickout file function below?

scanf printf put get
but nothing be the file opreratin...file operation handle by fscanf,fprintf, fgetc,fputc

8. main()
{
int a=0;
int b=10;
int c=3;
a=b%c;
printf("%d ", a);

}
out put:: 1

9. main()
{
int a=0;
int b=-10;
int c=-3;
a=b%c;
printf("%d ", a);

}
out put:: -1

10.#include
#include
main()
{
int a=0;
int b=-10;
int c=-3;b%c;
printf("%d",a);
getch();

}
output:
warning:1

o/p: 0


electronics question

1. in tv transmission what modultion we used?
AM AND FM

2. nyquist criteria equation?
fs>=2fm

3. opamp pin diagram?



4. bridge rectifier with l c circuit?






5. l c tank circuit frequency?

f=1/(2*3.14*(l c)^.5)



6. universal gates?

NAND AND NOR

7.xor and xnor gate diagram?





Sunday, September 13, 2009

aptitude

if the area of the square is increased as a69%..then what ll be the side of the square increased %??

ans:
100+69=x^2
side=13

if x^y=2x+y defined,,2^a=a^3 then what ll be 'a' value ??

ans:
4+a=2a+3
a=1;

Saturday, September 12, 2009

quantum paper

main()
{
int c=5,a=4;
clrscr();
printf("%d%d",main||c,main||a);
getch();
}

output: 11


(2).storage class and their types?

C has a concept of 'Storage classes' which are used to define the scope (visability) and life time of variables and/or functions.

storage classes is important part of c language.WHENEVER we define any funtion in c program then we can call that in every definend class.

there are four types of storage class. these are...

1 AUTO OR AUTOMATIC STORAGE CLASS

2 REGISTER STORAGE CLASS

3 STATIC STORAGE CLASS

4 EXTERNALSTORAGE CLASS

1) The features of "AUTOMETIC" storage class are as under some conditions:

storage : storage will be in memory.

value : garbage value.

scope : scope is local to block to the variable.

life : till, controls remain within the block.

2) The featurs of "STATIC" storage class are as under some conditions:

storage : memory.

value : zero.

scope : local to block.

life : Till control remains within the block.

3) The featurs of "REGISTER" storage class are as under some conditions:

storage : register.

value : garbage value.

scope : local to the block.

life : value persists between variable.

4) The feature of "EXTERNAL" storage class are as under some conditions:

storage : memory.

value : zero.

scope : local to block.

life : till controls remains within the block

(3).how can open the image file in c?

In C, generally we?can open files having text format...

other types of files can be opened in binary format only using

file *fp;

fp=fopen("filename","rb+");// where b stands for binary format

(4).
#include
main()
{
clrscr();
printf("%d",i);
getch();

}
int i=10;

output:

Error Undefined symbol 'i' in function main

(5).syntax for fwrite,fopen,fread,fseek


fwrite(const void *buffer, size_t size, size_t count, FILE *stream);

fread( void *buffer, size_t size, size_t num, FILE *stream );

fseek( FILE *stream, long offset, int origin );

fopen(const char *FileName, const char *Mode);

(6).how to find string length wihtout using c function?

#include<stdio.h>
#include<conio.h>
int str_len(char *)
void main()
{
char s[30];
int count;
printf("enter the string :");
gets(s);
count=str_len(s);
printf("the length is :%d",count);
getch();
}
int str_len(char *a)
{
int i=0;
while(*a!='\0')
a++;
i++;
}
return i;
}

(7).
main()
{

char s[]={'a','b','c','\0','a'};
char *p;
p=&s[3];
char *s1;
s1=s;
printf("%d",++(*p)+ ++(*str1));
getch();

}error: cant giving input through array to pointer..
pointer to array is possible in c.

(8).
#include
#include
struct set
{
int x;
char name[];
}set;

main()
{
set.x=3;
set.name[]={"hi"};
printf("%d%d",set.x,set.name);
getch();

}

output:
error ..because name declared as a char..but we use string .

(9)& (10)..
two question from header files error. like "sddio." and "cionio.h"

(11).main()
{
int i=300;
int j=400;
clrscr();
printf("%d %d");
getch();
}



OUTPUT:


300 400

Friday, September 11, 2009

robert c

1.main()
{
int const *p = 10;
printf(“%d”, ++(*p));
}
Ans: Compilation Error

2.main()
{
int I;
char *a = “man”;
for(i=0;i<3;i++)
printf(“%c%c%c%c\n”,i[a],a[i],*(a+i),*(i+a));
}
Ans: mmm
aaa
nnn

3.main()
{
extern int i = 10;
printf(“%d”,i);
}
Ans: Runtime error

4.main()
{
float f= 1.1;
double d = 1.1;
if ( f == d)
printf(“I LOVE U”);
else
printf(“I HATE U”);
}
Ans: I HATE U

5.How many queues are required to implement Priority queue
Ans: Two

6.A Binary tree is given and asked to write post order traversal

7.No of Nodes of Perfect Binary Tree :
Ans: 2n-1

8.Which Data Structure is efficient to implement Trees
Ans: Linked List

9. Heterogeneous Linked List is implemented using
Ans: Void pointers

10. #include
void main()
{
int i = 15;
int const & j = i;
cout << i << j << endl;
i = 9;
cout << i << j << endl
}
ANS: 15 15
9 9

11. which of the following function is used to display a character in console
ANS: put

13. To use manipulators we have to include the header file..
ANS: iomanip.h

14. Virtual memory consist of main memory and
ANS: swap files
http://www.ChetanaS.org
15. Command used to partition the disk
ANS: fdisk

Tuesday, September 8, 2009

C IDEAS

main()
{
int i=3;
int j=4;
clrscr();
printf("%d %d");
getch();
}



OUTPUT:


3 4

Friday, September 4, 2009

Bitread by Bitstream

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>


typedef unsigned char BITSTREAM;
unsigned long int readdata;
unsigned long int *ptr,*x,*y,*Z;





BITSTREAM * bs_open(unsigned char *buf,char *mode)
{
BITSTREAM * bfp;


bfp= buf;

return bfp;
}

unsigned long bs_read(int bitcnt, BITSTREAM *bfp)
{
int bitrem =0;
static unsigned long bitOffset=0;



bfp += (bitOffset/8);
bitrem= 8 - (bitOffset % 8);

char ch=*bfp;


int value1=0;
int value2=0;


/*increase offset for next call*/
bitOffset+=bitcnt;


if(bitrem != 0)
{
if(bitrem >= bitcnt)
{
value1= (unsigned char)(ch <<(8- bitrem)) >> (8- bitcnt) ;

}
else
{
int bitfrom2nd = bitOffset % 8;
value1= (unsigned char)(ch << (8- bitrem) ) >> (8- (bitrem+bitfrom2nd));

if(bitfrom2nd != 0)
{
bfp +=1;
ch=*bfp;
value2= (unsigned char)(ch >> (8- bitfrom2nd) ) ;

printf(" hello %d %d %d \n", value1,value2, bitcnt );
value1|=value2;
}
}
}
else
{
value1= ch >> (8 - bitcnt);
}

printf("Returning Value = %d \n", value1);
return value1;

}


int bs_checkread(BITSTREAM *bfp)
{


if((readdata=bs_read(4,bfp))!=0x4)
{
return 1;
}


if((readdata=bs_read(8,bfp))!=0x14)
{
return 1;
}

if((readdata=bs_read(6,bfp))!=0x9)
{
return 1;
}


if((readdata=bs_read(3,bfp))!=0)
{
return 1;
}


if((readdata=bs_read(4,bfp))!=0x6)
{
return 1;
}



if((readdata=bs_read(7,bfp))!=0x44)
{
return 1;
}


return 0;
}



int bs_close(BITSTREAM *bfp)
{
bfp=NULL;
return *bfp;
}



void main()
{
unsigned char buf[4]={'A','B','C','D'};
BITSTREAM *bfp;
bfp=bs_open(buf,"r");

printf("file \n %s \n\n" , bfp);

if(bfp == NULL )
{
printf("bs:failed to open file \n");
}

if(bs_checkread(bfp))
{
printf("bs:failed while reading input\n");

}
else
{
printf("read operation success-1level 1 success\n");
}
/*bs_close(bfp);*/

/*getch();*/
}

BITWRITE BY BITSTREAM

c LANGUAGE STANDARD library contains function to operate on files(fopen ,fclose,fread , fwrite). However there is no function to read/write the data in bit level.The problem is to implement a part of Bitstream involving only readind of the data from a buffer in the bit-level.However the problem defintion has been simplified to aid the completion of the program within the limited amount of time.


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>


typedef unsigned char BITSTREAM;


BITSTREAM * bs_open(unsigned char *buf,char *mode)
{
BITSTREAM * bfp;
if(*mode=='r')
{

bfp= buf;
}
else
{
unsigned char buff[10];
bfp=buff;
}
return bfp;
}




BITSTREAM * bs_write(unsigned long val,int bitcnt, BITSTREAM *bfp)
{
int bitrem =0;
static unsigned long bitOffset=0;

static unsigned char buff[10];
int bitfrom2nd;
int value1=0;

int value2=0;
bitrem=8-(bitOffset % 8);

int pos=bitOffset / 8;
//bfp+=pos;
/*increase offset for next call*/

bitOffset+=bitcnt;
if(bitrem >= bitcnt)
{

if(bitrem == 8)
{
value1= 0x00;
}
else
{
value1=buff[pos];
}

value2= (unsigned char)(val<<(8- bitcnt)) >> (8- bitrem);

buff[pos]=value1 | value2;


bfp[pos]=(unsigned char) buff[pos];
}
else
{

value1= buff[pos];


value2= (unsigned char)((val << (8-bitcnt)) >> (8- bitrem) ) ;
buff[pos]= value1 | value2;
bfp[pos]=(unsigned char) buff[pos];



bitfrom2nd = 8-(bitOffset % 8);

if (bitfrom2nd != 0)
{
pos++;
//bfp++;

buff[pos]=(unsigned char)(val << bitfrom2nd);

bfp[pos]=(unsigned char) (&buff[pos]);
}
}

printf(" value1= %d value2= %d bitcount =%d ", value1,value2,bitcnt );

printf(" buff %s %d\t ",buff,bfp);

printf(" bfp %s \n",bfp);


return (bfp);
}


void main()
{
unsigned char buf[10]={'\n'};

BITSTREAM *bfp;


/*clrscr();*/
bfp=bs_open(buf,"w");

bs_write(0x4,4,bfp);
bs_write(0x14,8,bfp);
bs_write(0x9,6,bfp);
bs_write(0x0,3,bfp);
bs_write(0x6,4,bfp);
bs_write(0x44,7,bfp);
bs_write(69,8,bfp);
bs_write(0x4,4,bfp);
bs_write(0x5,4,bfp);
for(int i=0;i<6;i++)
buf[i]=bfp[i];
printf("\nmain buff %s %s\t \n",buf, &bfp);



/*getch();*/
}



output:

C:\TC\karthi>bitwrite
value1= 0 value2= 64 bitcount =4 buff @ 38076048 bfp @\
value1= 64 value2= 1 bitcount =8 buff A@ 38076048 bfp A☺
value1= 64 value2= 2 bitcount =6 buff AB@ 38076048 bfp AB☻a,U?|☻
value1= 64 value2= 0 bitcount =3 buff AB@ 38076048 bfp AB@a,U?|☻
value1= 64 value2= 3 bitcount =4 buff ABC 38076048 bfp ABC♥,U?|♥
value1= 0 value2= 68 bitcount =7 buff ABCD 38076048 bfp ABCD,U?|♥
value1= 0 value2= 69 bitcount =8 buff ABCDE 38076048 bfp ABCDEU?|♦

value1= 0 value2= 64 bitcount =4 buff ABCDE@ 38076048 bfp ABCDE@?|♣

value1= 64 value2= 5 bitcount =4 buff ABCDEE 38076048 bfp ABCDEE?|♣


main buff ABCDEE ABCDEE