Wednesday, September 2, 2009

Quick Tips for Loop Statement in C programming

  1. there are three types of loop such as a) for loop b) while loop and c)do-while loop the purpose of each loop are same ( to repeat some part of the program) . but why there are three type of  loop:


a)      for loop : if the loop will continue finite number of times.
b)      While loop: if the loop will continue unknown number of times .
c)      Do..while loop: if the loop will continue at least one.

  1. zero (0) evaluate to false .

  1. if 0 is used as an expression in while loop , the condition is false and loop does not executed.
  2. If 0 is used as an expression in do while the condition is false and loop execute at least once.
  3. If 0 is used as an expression in for loop the condition is false and loop is execute at least once and it is equivalent to do .. while loop.

  1. if we drop all part of the for loop it is infinite loop , and drop all parts of while  and do …while loop is an error.
  2. break statement used only with switch statement and loop statement.
  3. Terminated with semicolon(;) in for loop is infinite loop , and in while loop it is infinite and in do...while loop it is compulsory.
  4. Dropping {} in for loop is not infinite , in while it is infinite but in do while it is necessary and infinite.
  5. the frequent variable only used with loop constant.
  6. use register keyword in frequent used of variable .
     for example : register int i;
                              for(i=0;i<=100;i++)

                                                printf(“%d”,i);
  1.  for loop is pre tested , while is pre tested where as do…while is post tested .for an example: for (;8<2;)>
  2. there are three important factors are necessary for any type of loop .

a.       start value
b.      stop value
c.       step value

  1. if we drop the step value it is an infinite loop.
  2. if the loop counter value is beyond of its range then that loop is infinite loop.
  3. function recursion is the replacement of loop.  

Switch Case using tips in c programming

  1. if the case match with an expression execution start from the case.

Example : void main()
{
  int x=2;
 switch(x)
 {
  case 1:
printf(“one”);
  break;
 case 2:
printf(“two”);
 break;
 }
}

  1. if none of the case are satisfied then the default case is satisfied

example : void main()
                        int x=102;
                        switch(x)
                        {
                                    case 10: printf(“ I am a reader”);
                                    case 11:printf(“I am writer”);
                                    default: printf(“I am programmer”);
}





3.case character must be integral constant.
4.break is used to prevent the falling of control from one case to another case


5. case can in any order.
 6.In the switch statement , the keyword ‘continue ‘ cannot be used in place of ‘break’. The compiler will generate an error message . the use of continue will not take the control to the beginning of switch as one is likely to believe.

7.duplicate case is not allowed.

8. the default case is optional . if there is no match case and there is no default case , then the compiler does not report the error.
9.case character can be constant or constant expression but not variable.

10. if 0 is given as an argument in if , while and do-while , it  evaluates to false but in switch it evaluates as an expression.

11. switch case used for menu driven program

using tips If-Else statement in C programming

  1. if the expression is evaluated with true then it is replace with 1 otherwise  replaced with 0.

Example : if( 5>3)
                 Printf(“YES”);
                        Else
                 Printf(“no”);
  1. if multiple statement are given in the if expression the order of evaluation is form left to right.

Example  int a=5;
                If (a++ ,a=a-5,a--;a)
                  Printf(“yes”);
                Else
                        Printf(“NO”);
3.Nested if can be replace with logical && operator
   Example :-
       Int a=1,b=2,c=3;
      If(a==1)
   If(b==2)
If(c==3)
 Printf(“BOSS”);

  1. ternary operator (?:) sometimes replaced the if statement .

example : if (a>65)
  printf(“hi”;
else
 printf(“bye”);

using ternary operator:
a>65?printf(“hi”);printf(“bye”);
  1. hanging if is not allowed , and it always cause an error misplaced else

       example:
   if(6>2)
printf(“yes”);
printf(“no”);
else

printf(“bye”);

  1. ‘else ‘ is optional part of the if statement

  1. else(:) is compulsory in conditional operator .

example :
 64>3 ? printf(“yes”) : printf(“”);

  1. nested if is differ from multiple if

example :
nested if

int a=1,b=2,c=3;
if(a==1)
if(b==2)
if(c==3)
printf(“BOSS”);

multiple if
int avg=75;
if(( avg>=60)
printf(“first”);
if (avg>=40 && avg<60)

   printf(“second”);
if(avg>=30 && avg<40)


  1. There are other conditional statement like #if , #else , #elseif etc used with preprocessor directive
  2. alwaysuse the “else  if” instead of multiple if.

Int avg=75;
If(avg>=60)
 Printf(“first”);
If(avg>=40 && avg<60)

 Printf(“second”);
If (avg>= 30 && avg<40)>


Use else if

Int avg=75;
If(avg>=60)
 Printf(“first”);
Else If(avg>=40 )
 Printf(“second”);
Else (avg>= 30 )
…………..


            

c programming operator using tips

1.      Precedence decides which operator should be perform first

         Example:-
          P = 6 / 2 + 4 * 3

            (Operator /  and  * enjoy same priority  so it is evaluated from  Left to Right)

          P = 6 / 2  + 4 * 3   [ Operation  of   / ]

          P = 3 +  4 * 3        [ Operation of *]
     
          P = 3 + 12            [ Operation of +]
  
          P =  15
      2. Associative determine the order of evaluation

3. Left to Right  & Right to left are two associative rules used when two or more than two same  operators enjoy the same Priority.
4. There is no operators in C to find out the value of “ A  raised to  power B”.
5. comma ( ,) operator is the lowest priority form the group of 45 operator.
6. parenthesis ( ), [], . and -> having highest priority from group of 45 operators .
7. Sizeof( ) is an operator and a keyword which look like function.
8. Modules ( %) is an operator that works with only integral type.
 Example:-
      Float x ;
     X = 10.0 % 3 ;
     Printf(“ %f ”, x);  //( wrong approach )
 Int x ;
X = 10 / 3 ;
Printf ( “%d”, x) ;  // right approach

9. C does not allow “culprits”  such as ** ,//
  example :
int a=4;
a**;
printf(“%d”, a);

10. unary operator (++,--) Can apply to variable not to constants.
11.unary operator plus (+) is dummy operator.
    Int a=6;
   +a;
printf (“%d”,a);

12. some time ternary operator (?:) replace the conditional if statement.

Like  example:-
Int a=6;
If(a>5)
 Printf(“hello”);
Else
Printf(“hi”);

(a>=5)?printf(“hello”):printf(“hi”);

13.comma and parenthesis are twin brothers.

Example :

While ( (P=getch() )!= EOF)
While ( p=getch() ,!=EOF )
14. Return Keyword cannot be used with ternary operator (?:)
  void main()
  {
 int p=5;
p>65540? Return1 : return 0;
}

15.the bit wise operator work with only integer and character .

16. continuous triple plus (+++) is allowed but not more or less.
  For example:
   Int a=3 b;
    B = a+++5; // means b = a ++ + 5  which is 8

17.      More then one + is allow in same statement but space matter a lot between operator .
18.      ## operator helps to concatenate between tokens

#define m (x) printf(“yes %d”, a##x)
void main()
{
int a1=32;
int a2=30;
m(1);
m(2);
}
19.      Turboc used many punctuation know as separators like (), [],.. etc.
20.      caste operator is an operator which is a signal (force) to compiler to convert one caste to other caste .

         example :-  float x; x =  (float) 5/2;
 21. all operators in C can be overload in c++ but except ?: , .* :: etc



 
      

Saturday, July 11, 2009

General aptitude - Questions with Answers

One of the following is my secret word: AIM DUE MOD OAT TIE. With the list in front of you, if I were to tell you any one of my secret word, then you would be able to tell me the number of vowels in my secret word. Which is my secret word?

Ans.TIE

One of Mr. Horton, his wife, their son, and Mr. Horton's mother is a doctor and another is a lawyer.
a)If the doctor is younger than the lawyer, then the doctor and the lawyer are not blood relatives.
b)If the doctor is a woman, then the doctor and the lawyer are blood relatives.
c)If the lawyer is a man, then the doctor is a man.
Whose occupation you know?

Ans.Mr. Horton:he is the doctor.

Mr. and Mrs. Aye and Mr. and Mrs. Bee competed in a chess tournament. Of the three games played:
a)In only the first game were the two players married to each other.
b)The men won two games and the women won one game.
c)The Ayes won more games than the Bees.
d)Anyone who lost game did not play the subsequent game.
Who did not lose a game?

Ans.Mrs.Bee did not lose a game.

Three piles of chips--pile I consists one chip, pile II consists of chips, and pile III consists of three chips--are to be used in game played by Anita and Brinda. The game requires:
a)That each player in turn take only one chip or all chips from just one pile.
b)That the player who has to take the last chip loses.
c)That Anita now have her turn.
From which pile should Anita draw in order to win?

Ans.Pile II

Of Abdul, Binoy, and Chandini:
a)Each member belongs to the Tee family whose members always tell the truth or to the El family whose members always lie.
b)Abdul says ''Either I belong or Binoy belongs to a different family from the other two."

Whose family do you name of?


Ans.Binoy's family--El.

In a class composed of x girls and y boys what part of the class is composed of girls
A.y/(x + y)
B.x/xy
C.x/(x + y)
D.y/xy

Ans.C

What is the maximum number of half-pint bottles of cream that can be filled with a 4-gallon can of cream(2 pt.=1 qt. and 4 qt.=1 gal)

A.16
B.24
C.30
D.64

Ans.D

f the operation,^ is defined by the equation x ^ y = 2x + y, what is the value of a in 2 ^ a = a ^ 3

A.0
B.1
C.-1
D.4

Ans.B

A coffee shop blends 2 kinds of coffee, putting in 2 parts of a 33p. a gm. grade to 1 part of a 24p. a gm. If the mixture is changed to 1 part of the 33p. a gm. to 2 parts of the less expensive grade, how much will the shop save in blending 100 gms.

A.Rs.90
B.Rs.1.00
C.Rs.3.00
D.Rs.8.00

Ans.C

There are 200 questions on a 3 hr examination.Among these questions are 50 mathematics problems.It is suggested that twice as much time be spent on each maths problem as for each other question.How many minutes should be spent on mathematics problems

A.36
B.72
C.60
D.100

Ans.B

others Links of General Aptitude Question's

index

1.Math Trivias Questions And Answers

2.Quantitative Aptitude Questions and SOLUTION | Aptitude Interview Questions and SOLUTION

3.Best Placement Aptitude Questions Interview Questions and Answers

4.Aptitude Knowledge Interview Questions and Answers

5.Aptitude Questions WITH SOLUTIONS and Free Aptitude Tests with Interview Questions WITH SOLUTIONS

6.Infosys placement Aptitude Interview Questions and Answers

7.General Aptitude Assessment Questions and Answers

8.General Placement Aptitude Test WITH SOLUTIONS

9.Self-Referential Aptitude Test Questions and Solution

10.Quantitative Aptitude Questions with Solution | Aptitude Interview Questions with Solution

11.Placement APTITUDE PAPER WITH SOLUTIONS

12.GENERAL APTITUDE TEST BATTERY with SOLUTIONS

13.Sample Logical Aptitude Questions and Answers

14.Logical & Aptitude Placement Questions and Answers

15.Aptitude Questions | Interview Questions and Solution

16.Quantitative Aptitude Questions | Interview Questions and Answers

17.Aptitude Questions Interview | Aptitude Questions and Answers


Quantitative Aptitude Questions with SOLUTION | Aptitude Interview Questions and SOLUTION

In a group of 15,7 have studied Latin, 8 have studied Greek, and 3 have not studied either. How many of these studied both Latin and Greek

A.0
B.3
C.4
D.5

Ans.B

If 13 = 13w/(1-w) ,then (2w)2 =

A.1/4
B.1/2
C.1
D.2

Ans.C

If a and b are positive integers and (a-b)/3.5 = 4/7, then

(A) b <> a
(C) b = a
(D) b >= a

Ans. A

In june a baseball team that played 60 games had won 30% of its game played. After a phenomenal winning streak this team raised its average to 50% .How many games must the team have won in a row to attain this average?

A. 12
B. 20
C. 24
D. 30

Ans. C

M men agree to purchase a gift for Rs. D. If three men drop out how much more will each have to contribute towards the purchase of the gift/

A. D/(M-3)
B. MD/3
C. M/(D-3)
D. 3D/(M2-3M)

Ans. D

A company contracts to paint 3 houses. Mr.Brown can paint a house in 6 days while Mr.Black would take 8 days and Mr.Blue 12 days. After 8 days Mr.Brown goes on vacation and Mr. Black begins to work for a period of 6 days. How many days will it take Mr.Blue to complete the contract?

A. 7
B. 8
C. 11
D. 12

Ans.C

2 hours after a freight train leaves Delhi a passenger train leaves the same station travelling in the same direction at an average speed of 16 km/hr. After travelling 4 hrs the passenger train overtakes the freight train. The average speed of the freight train was?

A. 30
B. 40
C.58
D. 60

Ans. B

If 9x-3y=12 and 3x-5y=7 then 6x-2y = ?

A.-5
B. 4
C. 2
D. 8

Ans. D

There are 5 red shoes, 4 green shoes. If one draw randomly a shoe what is the probability of getting a red shoe

Ans 5c1/ 9c1

What is the selling price of a car? If the cost of the car is Rs.60 and a profit of 10% over selling price is earned

Ans: Rs 66/-

1/3 of girls , 1/2 of boys go to canteen .What factor and total number of classmates go to canteen.

Ans: Cannot be determined.

The price of a product is reduced by 30% . By what percentage should it be increased to make it 100%

Ans: 42.857%

There is a square of side 6cm . A circle is inscribed inside the square. Find the ratio of the area of circle to square.

Ans. 11/14

There are two candles of equal lengths and of different thickness. The thicker one lasts of six hours. The thinner 2 hours less than the thicker one. Ramesh lights the two candles at the same time. When he went to bed he saw the thicker one is twice the length of the thinner one. How long ago did Ramesh light the two candles .

Ans: 3 hours.


others Links of General Aptitude Question's

index

1.Math Trivias Questions And Answers

2.Quantitative Aptitude Questions and SOLUTION | Aptitude Interview Questions and SOLUTION

3.Best Placement Aptitude Questions Interview Questions and Answers

4.Aptitude Knowledge Interview Questions and Answers

5.Aptitude Questions WITH SOLUTIONS and Free Aptitude Tests with Interview Questions WITH SOLUTIONS

6.Infosys placement Aptitude Interview Questions and Answers

7.General Aptitude Assessment Questions and Answers

8.General Placement Aptitude Test WITH SOLUTIONS

9.Self-Referential Aptitude Test Questions and Solution

10.Quantitative Aptitude Questions with Solution | Aptitude Interview Questions with Solution

11.Placement APTITUDE PAPER WITH SOLUTIONS

12.GENERAL APTITUDE TEST BATTERY with SOLUTIONS

13.Sample Logical Aptitude Questions and Answers

14.Logical & Aptitude Placement Questions and Answers

15.Aptitude Questions | Interview Questions and Solution

16.Quantitative Aptitude Questions | Interview Questions and Answers

17.Aptitude Questions Interview | Aptitude Questions and Answers


Aptitude Knowledge Interview Questions with solutions

Which of the following fractions is less than 1/3

(a) 22/62
(b) 15/46
(c) 2/3
(d) 1

Ans: (b)

There are two circles, one circle is inscribed and another circle is circumscribed over a square. What is the ratio of area of inner to outer circle?

Ans: 1 : 2

Three types of tea the a,b,c costs Rs. 95/kg,100/kg and70/kg respectively.
How many kgs of each should be blended to produce 100 kg of mixture worth Rs.90/kg, given that the quntities of band c are equal


a)70,15,15
b)50,25,25
c)60,20,20
d)40,30,30

Ans. (b)

in a class, except 18 all are above 50 years.
15 are below 50 years of age. How many people are there


(a) 30
(b) 33
(c) 36
(d) none of these.

Ans. (d)

If a boat is moving in upstream with velocity of 14 km/hr and goes downstream with a velocity of 40 km/hr, then what is the speed of the stream ?

(a) 13 km/hr
(b) 26 km/hr
(c) 34 km/hr
(d) none of these

Ans. A

Find the value of ( 0.75 * 0.75 * 0.75 - 0.001 ) / ( 0.75 * 0.75 - 0.075 + 0.01)

(a) 0.845
(b) 1.908
(c) 2.312
(d) 0.001

Ans. A

A can have a piece of work done in 8 days, B can work three times faster than the A, C can work five times faster than A. How many days will they take to do the work together ?

(a) 3 days
(b) 8/9 days
(c) 4 days
(d) can't say

Ans. B

A car travels a certain distance taking 7 hrs in forward journey, during the return journey increased speed 12km/hr takes the times 5 hrs. What is the distance travelled

(a) 210 kms
(b) 30 kms
(c) 20 kms
(c) none of these

Ans. B

Find (7x + 4y ) / (x-2y) if x/2y = 3/2 ?

(a) 6
(b) 8
(c) 7
(d) data insufficient

Ans. C

If on an item a company gives 25% discount, they earn 25% profit. If they now give 10% discount then what is the profit percentage.

(a) 40%
(b) 55%
(c) 35%
(d) 30%

Ans. D

A certain number of men can finish a piece of work in 10 days. If however there were 10 men less it will take 10 days more for the work to be finished. How many men were there originally?

(a) 110 men
(b) 130 men
(c) 100 men
(d) none of these

Ans. A

In simple interest what sum amounts of Rs.1120/- in 4 years and Rs.1200/- in 5 years ?

(a) Rs. 500
(b) Rs. 600
(c) Rs. 800
(d) Rs. 900

Ans. C

If a sum of money compound annually amounts of thrice itself in 3 years. In how many years will it become 9 times itself.

(a) 6
(b) 8
(c) 10
(d) 12

Ans A

Two trains move in the same direction at 50 kmph and 32 kmph respectively. A man in the slower train observes the 15 seconds elapse before the faster train completely passes by him. What is the length of faster train ?

(a) 100m
(b) 75m
(c) 120m
(d) 50m

Ans B

others Links of General Aptitude Question's

index

1.Math Trivias Questions And Answers

2.Quantitative Aptitude Questions and SOLUTION | Aptitude Interview Questions and SOLUTION

3.Best Placement Aptitude Questions Interview Questions and Answers

4.Aptitude Knowledge Interview Questions and Answers

5.Aptitude Questions WITH SOLUTIONS and Free Aptitude Tests with Interview Questions WITH SOLUTIONS

6.Infosys placement Aptitude Interview Questions and Answers

7.General Aptitude Assessment Questions and Answers

8.General Placement Aptitude Test WITH SOLUTIONS

9.Self-Referential Aptitude Test Questions and Solution

10.Quantitative Aptitude Questions with Solution | Aptitude Interview Questions with Solution

11.Placement APTITUDE PAPER WITH SOLUTIONS

12.GENERAL APTITUDE TEST BATTERY with SOLUTIONS

13.Sample Logical Aptitude Questions and Answers

14.Logical & Aptitude Placement Questions and Answers

15.Aptitude Questions | Interview Questions and Solution

16.Quantitative Aptitude Questions | Interview Questions and Answers

17.Aptitude Questions Interview | Aptitude Questions and Answers


Blog List