Showing posts from May, 2011

sum of digits in 100!

n! means n (n 1) ... 3 2 1
For example, 10! = 10 9 ... 3 2 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
Find the sum of the digits in the number 100!

Numbers are co-prime

Check whether two numbers are co-prime without finding their factors.

The typeof operator

The typeof operator returns the type of its argument, which can be an expression or a type. The language feature provides a way to derive the type from an expression. The alternate spelling of the keyword, __typeof__, is recommended. Given an expression e, __typeof__(e) can be used anywhere a type name is needed, for example in a declaration or in a cast.
A typeof construct itself is not an expression, but the name of a type. A typeof construct behaves like a type name defined using typedef, although the syntax resembles that of sizeof. The following examples illustrate its basic syntax. For an expression e:
int e; __typeof__(e + 1) j; /* the same as declaring int j; */ e = (__typeof__(e)) f; /* the same as casting e = (int) f; */ Using a typeof construct is equivalent to declaring a typedef name. Given
int T[2]; int i[2];you can write __typeof__(i) a; /* all three constructs have the same meaning */ __typeof__(int[2]) a; __typeof__(T) a;The behavior of the code is as if you …

type of a variable at run time

Given a variable in c,how can you know the type of the variable at run time .If you don't have to use type_of operator .

number as square of two integers

Given an integer n decide if it is possible to represent it as a sum of two squares of integers.

Rotate by n bit positions

Write a function that rotates (NOT shifts) to the right by n bit positions the bits of an unsigned char no bits are lost in this process. Your answer should print out the result in binary form  Your output should be like this: x = 10100111 (binary) x rotated by 3 = 11110100 (binary)

invert function in c

Write a function invert(x,p,n) that returns x with the n bits that begin at position p inverted (i.e., 1 changed into 0 and vice versa), leaving the others unchanged.

nth prime number

Suggest an efficient algorithm to find nth prime number,where n is run time option.