santhi perumal


{ City } chennai
< Country > india
* Profession * mts
User No # 19107
Total Questions Posted # 0
Total Answers Posted # 16

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 278
Users Marked my Answers as Wrong # 122
Questions / { santhi perumal }
Questions Answers Category Views Company eMail




Answers / { santhi perumal }

Question { nvidia, 40348 }

Function to find the given number is a power of 2 or not?


Answer

#include
#include

int main()
{
int i,count = 0,number;

printf("Enter the number\n");
scanf("%d",&number);

for(i=15;i>=0;i--)
{
if((1< count++;
}

if(count == 1)
printf("\nThe Given Number is Power of 2\n");
else
printf("\nThe Given Number is Not Power of 2\n");

}

Is This Answer Correct ?    7 Yes 1 No

Question { Honeywell, 6328 }

how to exchnage bits in a byte
b7<-->b0 b6<-->b1 b5<-->b2 b4<-->b3
please mail me the code if any one know to
rajeshmb4u@gmail.com


Answer

#include
#include

int main()
{
int i,number,count=0,a[100];

printf("Enter the number\n");
scanf("%d",&number);

for(i=7;i>=0;i--)
{
if((1< a[count] = 1;
else
a[count] = 0;

count++;
}

printf("Binary Value of the Given Number is:\n");
for(i=0;i<=7;i++)
{
printf("%d",a[i]);
}
printf("\nReversed Binary Value of the Given Number is:\n");
for(i=0;i<=7;i++)
{
printf("%d",a[7-i]);
}
printf("\n");
}

Is This Answer Correct ?    0 Yes 3 No


Question { Tech Mahindra, 51999 }

How to avoid structure padding in C?


Answer

Those are 3 different things.

Structure Padding

Most processors require specific memory alignment on
variables certain types. Normally the minimum alignment is
the size of the basic type in question, fo instance this is
common

char variables can be byte aligned and appear at any byte
boundary

short (2 byte) variables must be 2 byte aligned, they can
appear at any even byte boundary. This means that 0x10004567
is not a valid location for a short variable but 0x10004566 is.

long (4 byte) variables must be 4 byte aligned, they can
only appear at byte boundarys that are a multiple of 4
bytes. This means that 0x10004566 is not a valid location
for a long variable but 0x10004568 is.

Structure padding occurs because the members of the
structure must appear at the correect byte boundary, to
achieve this the compiler puts in padding bytes (or bits if
bit fields are in use) so that the structure members appear
in the correct location. Additionally the size of the
structure must be such that in an array of the structures
all the structures are correctly aligned in memory so there
may be padding bytes at the end of the structure too

struct example {
char c1;
short s1;
char c2;
long l1;
char c3;
}

In this structure, assuming the alignment scheme I have
previously stated then

c1 can appear at any byte boundary, however s1 must appear
at a 2 byte boundary so there is a padding byte between c1
and s1.

c2 can then appear in the available memory location, however
l1 must be at a 4 byte boundary so there are 3 padding bytes
between c2 and l1

c3 then appear in the available memory location, however
because the structure contains a long member the structure
must be 4 byte aligned and must be a multiple of 4 bytes in
size. Therefore there are 3 padding bytes at the end of the
structure. it would appear in memory in this order

c1
padding byte
s1 byte 1
s1 byte 2
c2
padding byte
padding byte
padding byte
l1 byte 1
l1 byte 2
l1 byte 3
l1 byte 4
c3
padding byte
padding byte
padding byte

The structure would be 16 bytes long.

re-written like this

struct example {
long l1;
short s1;
char c1;
char c2;
char c3;
}

Then l1 appears at the correct byte alignment, s1 will be
correctly aligned so no need for padding between l1 and s1.
c1, c2, c3 can appear at any location. The structure must be
a multiple of 4 bytes in size since it contains a long so 3
padding bytes appear after c3

It appears in memory in the order

l1 byte 1
l1 byte 2
l1 byte 3
l1 byte 4
s1 byte 1
s1 byte 2
c1
c2
c3
padding byte
padding byte
padding byte

and is only 12 bytes long.


I should point out that structure packing is platform and
compiler (and in some cases compiler switch) dependent.




Memory Pools are just a section of memory reserved for
allocating temporarily to other parts of the application


A memory leak occurs when you allocate some memory from the
heap(or a pool) and then delete all references to that
memory without returning it to the pool it was allocated from.

Is This Answer Correct ?    59 Yes 2 No

Question { 7465 }

difference of two no's with out using - operator


Answer

#include
#include

//To calculate a-b
void main()
{
int a,b,min,max;

printf("Enter the value of a and b \n");
scanf("%d %d",&a,&b);
min = (a max = (a>b)?a:b;
while(min--) max--;

if(a printf("-%d",max);
else
printf("%d",max);
}

Is This Answer Correct ?    1 Yes 1 No

Question { Infosys, 12608 }

how to find the binary of a number?


Answer

#include
#include

int main()
{
int i,number;
printf("Enter the Number\n");
scanf("%d",&number);

for(i=7;i>=0;i--)
{
if((1< printf("1");
else
printf("0");
}
}

Is This Answer Correct ?    9 Yes 6 No

Question { Persistent, 8889 }

pgm to reverse string using arrays i.e god is love becomes
love is god)
(assumption:only space is used for seperation of words)

no addtional memory used.i.e no temporary arrays can used.


Answer

#include
#include

int main()
{

int i,j,length;
char a[] = "god is love";

length = strlen(a);

printf("The Given String is\n%s\n",a);
printf("The Resulted String is\n");

for(i=length-1;i>=0;i--)
{
if(a[i] == ' ')
{
for(j=i+1; a[j] != ' ' && a[j] != '\0';j++)
{
printf("%c",a[j]);
}
printf("%c",a[i]);
}
}
i++;
while(a[i] !=' ')
{
printf("%c",a[i]);
i++;
}
printf("\n");

}

Is This Answer Correct ?    14 Yes 2 No

Question { TCS, 12858 }

how to add numbers without using arithmetic operators.


Answer

#include
#include

void main()
{
int a=10,b=20;
while(b--) a++;
printf("Sum is :%d",a);
}

Is This Answer Correct ?    9 Yes 11 No

Question { Religare, 47301 }

What will be the output of
x++ + ++x?


Answer

Answer is 2x+2. For Ex: if x is 2 result is 2(2)+2 = 6.

Is This Answer Correct ?    7 Yes 8 No

Question { Oracle, 74391 }

write a Program to dispaly upto 100 prime numbers(without
using Arrays,Pointer)


Answer

#include
#include

int main()
{
int i,j, flag = 0;

for(i=2;i<=100;i++)
{
for(j=2;j {
if(i != j)
{
if(i%j != 0)
continue;
else
break;
}
}
if(i == j)
printf("%d ",i);

}
}

Is This Answer Correct ?    52 Yes 38 No

Question { 10572 }

wap in c to accept a number display the total count of digit


Answer

#include
#include

int main()
{
int number,m,sum =0,count =0;

printf("Enter the number \n");
scanf("%d",&number);

while(number != 0)
{
m = number % 10;
sum = sum + m;
count++;
number = number / 10;
}

printf("\nThe number of Digits in the Given Number is
%d\n",count);
printf("The Sum of Digits in the Given Number is %d\n",sum);



}

Is This Answer Correct ?    19 Yes 5 No

Question { IBM, 9860 }

Write a program that accepts a string where multiple spaces
are given in between the words. Print the string ignoring
the multiple spaces.

Example:
Input: “ We.....Are....Student “ Note: one .=1 Space
Output: "We Are Student"


Answer

#include
#include

int main()
{
int i,j,k;
char a[100];

printf("Enter the String\n");
gets(a);

printf("The Given String is %s \n",a);

for(i=0; a[i] != '\0';i++)
{
if(a[i] == ' ')
{
for(k=i+1;a[k] != '\0';k++)
{
if(a[i+1] == ' ')
{
for(j=i+1;a[j] != '\0';j++)
{
a[j] = a[j+1];
}
a[j] ='\0';
}
}
}
}
printf("The Resulted String is %s\n ",a);

}

Is This Answer Correct ?    3 Yes 4 No

Question { 7545 }

what is the diff between the printf and sprintf functions??
and what is the syntax for this two functions ??


Answer

sprintf: This Writes formatted data to a character string in
memory instead of stdout

Syntax of sprintf is:

#include
int sprintf (char *string, const char *format
[,item [,item]...]);

Here

String refers to the pointer to a buffer in memory where the
data is to be written. Format refers to pointer to a
character string defining the format. Each item is a
variable or expression specifying the data to write.

The value returned by sprintf is greater than or equal to
zero if the operation is successful or in other words the
number of characters written, not counting the terminating
null character is returned. And return a value less than
zero if an error occurred.

printf: Prints to stdout

Syntax for printf is:

printf format [argument]...

The only difference between sprintf() and printf() is that
sprintf() writes data into a character array, while printf()
writes data to stdout, the standard output device.

Is This Answer Correct ?    0 Yes 1 No

Question { Global Edge, 20766 }

int *p=20;
if u print like dis printf("%d",p);
o\p:- 20; how is it possible?
plz give me the explanation.


Answer

We are assigning 20 to *p. Which means we are assigning the
address 20 to p. when you want to print the address of the
pointer variable we have to print just p not *p. if you want
to print the value stored in the particular address we need
to print like *p. in this case we are printing p so it will
give the address 20 to it.

Is This Answer Correct ?    31 Yes 5 No

Question { IBM, 13173 }

how to find a 5th bit is set in c program


Answer

#include
#include

int main()
{
int number;
int position;
int result;

printf("Enter the Number\n");
scanf("%d",&number);
printf("Enter the Position\n");
scanf("%d",&position);

result = (number >>(position-1));

if(result & 1)
printf("Bit is Set");
else
printf("Bit is Not Set");
}

Is This Answer Correct ?    18 Yes 7 No

Question { IBM, 21668 }

write a c program to check weather a particluar bit is set
or not?


Answer

#include
#include

int main()
{
int number;
int position;
int result;

printf("Enter the Number\n");
scanf("%d",&number);
printf("Enter the Position\n");
scanf("%d",&position);

result = (number >>(position-1));

if(result & 1)
printf("Bit is Set");
else
printf("Bit is Not Set");
}

Is This Answer Correct ?    33 Yes 12 No

 [1]   2    Next