Tuesday 22 November 2011

C program to add, subtract, multiply and divide Complex Numbers, complex arithmetic

Asked in Honeywell Technical Interview:

C Program to add, subtract, multiply and divide complex numbers :- This program performs basic operations on complex numbers i.e addition, subtraction, multiplication and division. This is a menu driven program in which user will have to enter his/her choice to perform an operation. User can perform operations until desired. To easily handle a complex number a structure named complex has been used, which consists of two integers first integer is for real part of a complex number and second for imaginary part.
#include
#include
#include

struct complex
{
int real;
int img;
};

main()
{
int choice, temp1, temp2, temp3;
struct complex a, b, c;

while(1)
{
clrscr();
printf("Press 1 to add two complex numbers.\n");
printf("Press 2 to subtract two complex numbers.\n");
printf("Press 3 to multiply two complex numbers.\n");
printf("Press 4 to divide two complex numbers.\n");
printf("Press 5 to exit.\n");
printf("Enter your choice ");
scanf("%d",&choice);

if( choice == 5)
exit(0);

if(choice >= 1 && choice <= 4) { printf("Enter a and b where a + ib is the first complex number."); printf("\na = "); scanf("%d", &a.real); printf("b = "); scanf("%d", &a.img); printf("Enter c and d where c + id is the second complex number."); printf("\nc = "); scanf("%d", &b.real); printf("d = "); scanf("%d", &b.img); } if ( choice == 1 ) { c.real = a.real + b.real; c.img = a.img + b.img; if ( c.img >= 0 )
printf("Sum of two complex numbers = %d + %di",c.real,c.img);
else
printf("Sum of two complex numbers = %d %di",c.real,c.img);
}
else if ( choice == 2 )
{
c.real = a.real - b.real;
c.img = a.img - b.img;

if ( c.img >= 0 )
printf("Difference of two complex numbers = %d + %di",c.real,c.img);
else
printf("Difference of two complex numbers = %d %di",c.real,c.img);
}
else if ( choice == 3 )
{
c.real = a.real*b.real - a.img*b.img;
c.img = a.img*b.real + a.real*b.img;

if ( c.img >= 0 )
printf("Multiplication of two complex numbers = %d + %di",c.real,c.img);
else
printf("Multiplication of two complex numbers = %d %di",c.real,c.img);
}
else if ( choice == 4 )
{
if ( b.real == 0 && b.img == 0 )
printf("Division by 0 + 0i is not allowed.");
else
{
temp1 = a.real*b.real + a.img*b.img;
temp2 = a.img*b.real - a.real*b.img;
temp3 = b.real*b.real + b.img*b.img;

if ( temp1%temp3 == 0 && temp2%temp3 == 0 )
{
if ( temp2/temp3 >= 0)
printf("Division of two complex numbers = %d + %di",temp1/temp3,temp2/temp3);
else
printf("Division of two complex numbers = %d %di",temp1/temp3,temp2/temp3);
}
else if ( temp1%temp3 == 0 && temp2%temp3 != 0 )
{
if ( temp2/temp3 >= 0)
printf("Division of two complex numbers = %d + %d/%di",temp1/temp3,temp2,temp3);
else
printf("Division of two complex numbers = %d %d/%di",temp1/temp3,temp2,temp3);
}
else if ( temp1%temp3 != 0 && temp2%temp3 == 0 )
{
if ( temp2/temp3 >= 0)
printf("Division of two complex numbers = %d/%d + %di",temp1,temp3,temp2/temp3);
else
printf("Division of two complex numbers = %d %d/%di",temp1,temp3,temp2/temp3);
}
else
{
if ( temp2/temp3 >= 0)
printf("Division of two complex numbers = %d/%d + %d/%di",temp1,temp3,temp2,temp3);
else
printf("Division of two complex numbers = %d/%d %d/%di",temp1,temp3,temp2,temp3);
}

}

}
else
printf("Invalid choice.");

printf("\nPress any key to enter choice again...");
getch();
}
}

Friday 18 November 2011

Honeywell Technical Interview Questions

1. Introduce yourself briefly.


2. How much good you are in C (on the scale of 1-10)


3. They gave me the same complex number program and told me what modification I can do in it. (Again write the program) Click here to see this program


4. Write the same complex number addition program with passing values to function, passing structure to function and passing address of the structure to the function.


5. What is recursion? What will happen is we don't give termination condition? How efficient recursion is compared to iteration.


ans:


Recursion is a programming technique that allows the programmer to express operations in terms of themselves. In C++, this takes the form of a function that calls itself. A useful way to think of recursive functions is to imagine them as a process being performed where one of the instructions is to "repeat the process". This makes it sound very similar to a loop because it repeats the same code, and in some ways it is similar to looping. On the other hand, recursion makes it easier to express ideas in which the result of the recursive call is necessary to complete the task. Of course, it must be possible for the "process" to sometimes be completed without the recursive call. One simple example is the idea of building a wall that is ten feet high; if I want to build a ten foot high wall, then I will first build a 9 foot high wall, and then add an extra foot of bricks. Conceptually, this is like saying the "build wall" function takes a height and if that height is greater than one, first calls itself to build a lower wall, and then adds one a foot of bricks.


6. What are the storage classes? Explain each with examples.


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


There are four type of storage classes in C. These are used
to store variables. These are Extern, Static, Register and
Auto. Auto is the default class assigned to any variable.
eg. if we define int x=10; then it means auto int x=10
register and static differ in only one grounds that
register is there in the cpu and static in the main memory.
extern is global and can be accessed by any program and
anywhere.


7. Where register variables are stored? Where registers remain in computer? How many registers are there?






register is there in the cpu and static in the main memory.


8. Write a program to implement static storage class. (Many questions on this)


9. What is Union? Write syntax of union. How memory is allocated for the members of Union. How it is different from structure? When we use union and when structure.


10. What is dynamic memory allocation?


11. Write syntax for allocating memory for Integer using malloc().


12. What is type casting?


13. What is the need of type casting in malloc().


12. What is difference between malloc() and calloc().


13. How memory is released?


14. Where malloc() save variables? (In which memory- Primary, RAM)


15. What is Preprocessor?


16. What it is called in C?


17. How it works? What is the need of macros?


18. How parameters are passed in C?

Thursday 17 November 2011

List of Engineering Entrance Exams In India

Here is a list of a few examinations I know :
  1. AICE - All India Competitive Examination for Admissions to Master's Degree Programmes
  2. AICET - All India Common Entrance Test
  3. AIEEE - All India Engineering Entrance Examination
  4. AMIE - Associate Membership of Institution of Engineers
  5. AMIETE - Associate Membership of Institute of Electronics and Telecommunication Engineers
  6. Annamalai University Engineering Entrance Exam
  7. BEE- Bureau of Energy Efficiency
  8. BITSAT - Birla Institute of Technology and Science Examination
  9. Dhirubhai Ambani Institute Of Information and Communication Technology
  10. GATE - Graduate Aptitude Test in Engineering
  11. IIT JEE - IIT Joint Entrance Examination
  12. ISAT - IIST Admission Test
  13. JNU EEE - Jawaharlal Nehru University Engineering Entrance Exam
  14. MP PET - Madhya Pradesh Pre Engineering Test
  15. NIT - National Institute of Technology
  16. RPET - Rajasthan Pre Engineering Test
  17. SRM EEE - SRM Engineering Entrance Exam [ BTech, MTech ]
  18. VITEEE Vellore Institute of Technology Engineering Entrance Exam

If any more exams are conducted in your area, post them here.

Latest CTS Placement Paper September 2011 Kolkata

At first the cognizant people came to the college,gave the pre placement talk.Then started the aptitude exam.
There was two part in the paper ----1st part is Verbal and 2nd part is Analytical.
Question was not so easy.You should practice properly specially the verbal part.
322 selected from 340 in the aptitude test .
After a long wait my name was called for the interview.I was lil' bit tensed because that was the 1st interview in my life.Hopefully my HR was a very good person after entering in the interview room-
HR:Sit down
me:thank you sir.
HR:He asked for the CV and look it properly.asked some common question from CV about hobby,achievements
me: answered properly
HR:Then he asked except this(which was written in my hobby) what can u do?
me: bla bla
HR:which is your preferable language
me:java
HR:what are the properties of oops
me:told
HR:gave me a situation about inheritence (cat and dog has some properties,implement this in inheritence) and then he asked me to write the code
me:properly done
HR:what is polymorphism?then overloading,overriding,run time polymorphism
me:told
HR:then he asked do u know non linear datastructure?
me:told about tree,different types of trees
HR:asked about level,height,node,edge,b tree,b+ tree
me:told
HR:told me to do a quick sort of some no.s
me:I just told the algorithm,i didn't do the sorting.
HR:what is the best and worst case of bubble sort
me:told ,he looked satisfied
HR:Tell me something about your project
me:told
HR:so at the back end u r going to use dbms?
me:yes
HR:what is candidate key,unique key?
me:told
HR:give me a table asked me to write a query (it was pretty tough)
me:I wrote a code and show him
HR:This is not my question told the question properly
me:again write the code and show him ,he looked satisfied
HR:then he asked me why cognizant?
me: told
HR:r u rellocating?
me:yes
HR:souvik,do u have any query about cognizant?
me:asked 4 questions(prepare some questions)
HR:gave the answers.
Don't be nervous.Whatever comes in your mind just tell,don't miss a single question.Almost every HR is a nice person.
Always use cognizant,don't use CTS.
I'm selected for cognizant.
I'm going to join in the next year.

Search here for "Freshers Jobs"