Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
22 views

C Programrs

The document contains 14 multiple choice questions related to C programming concepts like if-else statements, operators, functions, loops, arrays etc. It also contains 10 programming problems asking to write C code to solve problems related to numerical methods like Newton Raphson method, Trapezoidal rule, Simpson's rule, interpolation, Regula Falsi method etc. The last question asks about the difference between do-loop and do-while loop in C.

Uploaded by

DIP
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

C Programrs

The document contains 14 multiple choice questions related to C programming concepts like if-else statements, operators, functions, loops, arrays etc. It also contains 10 programming problems asking to write C code to solve problems related to numerical methods like Newton Raphson method, Trapezoidal rule, Simpson's rule, interpolation, Regula Falsi method etc. The last question asks about the difference between do-loop and do-while loop in C.

Uploaded by

DIP
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1. (i) What is the correct syntax of if statement in C program?

a) if(condition){ } b) if(condition) :
c) If { [condition] } d) None of these

(ii) Choose a correct C Statement.


a) a++ is (a=a+1) POST INCREMENT Operator
b) a-- is (a=a-1) POST DECREMENT Operator
--a is (a=a-1) PRE-DECREMENT Operator
c) ++a is (a=a+1) PRE INCRMENT-Operator
d) All the above.

(iii) What is the output of C Program?


int main()
{
int a=32;
do
{
printf("%d ", a);
a++;
}while(a <= 30);
return 0;
} 1, 6
a) 30 b) 32 c) 33 d) No Output

(iv) The sqrt() function is used to calculate which value?


a) Square b) Square of reverse bits
c) Square root d) None of these

(v) What will be the output of the following C program?


#include <stdio.h>
int func(int x){
return (--x);
}
int main(){
int a = func(13);
printf("%d", a);
return 0;
} 1, 6
a) 12 b) 13 c) 14 d) Error

(vi) What will be the output of the following C code?


#include <stdio.h>
int main()
{
int x =-100;
-100;
printf("%d",x);
return 0;
}
a) -100 b) 0 c) 100 d) Error

(vii) What is the purpose of ‘return’ statement in a function in C?


a) To define a function b) To declare the function’s return type
c) To exit the program d) To return a value from the function

(viii) When the condition of if statement is false, the flow of code will ___.
a) go into the if block b) Exit the program
c) Continue the code after skipping the if block d) None of these

(ix) Which of the following is not a standard C library function for mathematical
operations?
a) rand b) pow c) sqrt d)abs

(x) What will be the output of the following C code?


#include <stdio.h>
void main()
{
int k = 0;
for (k = 0; k < 3; k++)
printf("Hello");
}
a) Run time error b) Hello is printed thrice
c) Hello is printed twice d) Hello is printed infinitely

(xi) Recursive function may call


a) another function b) itself
c) both a and b d) none of these

(xii) The operator ++ is a


a) unary operator b) binary operator
c) ternary operator d) null operator

(xiii) The minimum number of function in any C program is


a) 1 b) 2 c) 3 d) 4

(xiv) What is the output of the following program code ?


Void main()
{
int i=0;
clrscr();
void main ();
printf(“number:%d”, i);
i++;
getch();
}
a) Number :0
b) Number:1
c) Continue printing like (b) i,e. 0
Number :…upto number:< a large number>
d) none of these

2. Write a program in ‘C’ to find a root of the equation 𝑥 3 − 5𝑥 + 1 = 0 by Newton Raphson method.
1
3. Write a program in ‘C’ to evaluate ∫0 𝑥 𝑑𝑥 taking n=5 by using Trapezoidal rule.
4. Write a program in C to find the square of any number using the function.
6 1
5. Write a program in C to evaluate ∫0 (1+𝑥)2 𝑑𝑥 using Simpson’s one-third rule taking six equal sub-
intervals.
6. Write a program in C to print the first 10 natural numbers using i) for loop ii) do while loop
7. Write a C program to compute the value of y at x=2.8 from the following table using Newton’s
Backward interpolation formula.
x 0.0 1.0 2.0 3.0
y 1 2 11 34
8. Write a C program to compute the value of y at x = 0.33 from the following table
x 0.32 0.34 0.36 0.38 0.40
y 1.769 1.780 1.791 1.802 1.813
8 4 2 4 9
9. Write a C program to find the real root between 2 and 3 of the equation 𝑥 3 − 2𝑥 − 5 = 0 using
Regula Falsi method.
𝑑𝑦
10. Write a C program to compute y(0.8) for 𝑑𝑥 = 𝑥𝑦, 𝑦(0) = 2 taking h= 0.2.(Using RK-method of
order 4).
11. What is the difference between do-loop and do-while loop in C?

Write a C program to compute the sum of the first 10 natural numbers.


#include <stdio.h>
int main()
{
int j, sum = 0;
printf("The first 10 natural number is :\n");
for (j = 1; j <= 10; j++)
{
sum = sum + j;
printf("%d ",j);
}
printf("\nThe Sum is : %d\n", sum);
}
Write a program in C to print the first 10 natural numbers using for loop.
#include <stdio.h>
int main()
{
int i;
printf("The first 10 natural numbers are:\n");
for (i=1;i<=10;i++)
{
printf("%d ",i);
}
printf("\n");
return 0;
}

Write a program in C to print the first 10 natural numbers using do while loop

#include <stdio.h>
int main()
{
int n=1;
do
{
printf("%d ", n);
n++;
} while(n <= 10);
return 0;

Write a program in C to find the square of any number using the function.
#include <stdio.h>
float f(float x)
{
return (x* x);
}
int main()
{
float a,n;
printf("Input any number for square : ");
scanf("%f", &a);
n = f(a);
printf("The square of %f is : %f\n", a, n);
return 0;
}

You might also like