Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 335 - 337 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 335

C & C Plus Plus
Edit

Describe in Detail

Essay▾

How would you use the functions sin () , pow () , sqrt () ?

Sin ()

double sin (double x) returns the sine of a radian angle x.

• Declaration:
• double sin (double x)
• Parameters:
• x-This is the floating-point value representing an angle expressed in radians.

Pow ()

Calculates power of numbers:

• Syntax:

double pow (double x, double y) ;

• Parameters or Arguments: Here x is raised to the power of y.

Sqrt ()

The C library function double sqrt (double x) returns the square root of x.

• Declaration:

double sqrt (double x)

• Parameters:

x-This is the floating-point value whose square root needs to be computed

Question 336

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Write a program which employs Recursion.

Explanation

1. #include<iostream>
2. usingnamespacestd;
3. intfact(intn)
4. {
5.     if (n == 0)
6.     return1;
7.     n=nfact(n-1);
8.     returnn;
9. }
10. intmain() {
11.     intn=5;
12.     cout ≪ "Factorial of number " ≪ n ≪ " is :" ≪ fact(n) ≪ endl;
13.     return0;
14. }

Question 337

C & C Plus Plus
Edit

Describe in Detail

Essay▾
1. main ()
2. {
3.     inti =0;
4.     for (; i ++; printf ( “%d” i) );
5.     printf ( “%d” i);
6. }

Explanation

• In a program int i = 0; Here integer variable i = 0 for (; i ++ ; printf ( “% d” i) ) ; Before entering into the for loop checking condition is “evaluated” .Here it evaluates to 0 (false) and comes out of the loop, and i is incremented (note the semicolon after the for loop)
• So, the answer is 1.

Developed by: