0% found this document useful (0 votes)
4 views

Mid 2

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

Mid 2

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

1.

C Program to print the average of 1 to n numbers using functions without return type
2. Write a program in C to find the square of any number using the function
For example:

Tes Input Result


t

1 20 The square of 20 is :
400.00

2 5 The square of 5 is :
25.00

3. Write a C program through a pointer to compare three numbers and display a small
number
For example:

Tes Input Result


t

1 2 5 9 2

2 26 98 12 12

4. Write a c program to call a function without arguments and with return values from
other user-defined functions, to calculate whether the number is prime or not
For example:

Tes Input Result


t

1 3 prime

2 9 not
prime

5. C program to find the factorial of a given number using pointers.


6. Write a C program "to store 5 numbers in dynamically created memory and a
function that returns average of the numbers stored in that memory".
Note : 1. Use call by reference parameter passing method.
2. Function should return a float value.
3. Display only two digits after decimal point
7. Write a function (i.e C program) that returns all perfect square numbers in between
m, n (both inclusive) Guaranteed constants : n>m , m>0 , n>0
Note : 1. Use call by reference parameter passing technique
2 . Function should return an integer pointer
Example:
a) m=1 , n=10 then count =3 (perfect square numbers : 1 ,4, 9)
b) m=26, n=35 then count-0 (No perfect square number in between 26, 35)
8. Using recursion ,write c program to check whether the given number n is
palindrome or not. ( n >0)
Note : 1.Parameter passing method is Call-by-value
2.Function should return Boolean data type
3.Display TRUE if number n is palindrome, FALSE , if not palindrome.
9. Write a C program to add two numbers using pointers.
For example:

Tes Input Result


t

1 5 8 sum=1
3

2 3 4 sum=7

10. Write a program to print even and odd numbers in a given range using functions.
For example:

Tes Input Result


t

1 2 10 Even numbers are:2 4 6 8 10


Odd numbers are:3 5 7 9
2 4 16 Even numbers are:4 6 8 10 12 14
16
Odd numbers are:5 7 9 11 13 15

11. Write a C program to swap two numbers using functions(Call By Reference)?


For example:

Tes Input Result


t

1 13 15 15 13

12. Write a program to find the factorial of a number using functions?


For example:

Tes Input Result


t

1 4 factorial of
number=24

2 6 factorial of
number=720

13. Find the LCM of two numbers using recursion.


For example:

Tes Input Result


t

1 4 6 LCM of 4 and 6
is:12

2 1 7 LCM of 1 and 7
is:7

14. check given number is prime number or not using with argument without return type?
For example:
Tes Input Result
t

1 5 prime number

2 10 Not prime
number

15. Write a program to get the power of a number using functions.


For example:

Tes Input Result


t

1 3 3 27

2 5 2 25

16. Write a recursive function to find sum of 1 to N numbers.


For example:

Tes Input Result


t

1 5 sum of
numbers=15

2 0 Invalid Number

17. Find the power of any number using recursion.


For example:

Tes Input Result


t

1 2 4 16
2 3 3 27

18. Write a program to find the product of two numbers using recursion.
For example:

Tes Input Result


t

1 5 4 The product of numbers 5 and 4


is:20

2 8 5 The product of numbers 8 and 5


is:40

19. Write a program to find the GCD of two numbers using Recursions.
For example:

Tes Input Result


t

1 36 60 12

2 12 18 6

20. Write a program in C to find the maximum number between two numbers using a
pointer.
21. Write a C program to solve the following equation.
f(n)=f(n-2)+f(n-1), for all n>=2,
f(n)=1 for all n<2
Note : Use recursion with call by value passing method and function should return an
integer value.
22. Using recursion write a C program to display values of n, m when the m crosses n
or n crosses m. Here m, n are two integers . One number will cross other after
successively incrementing or decrementing.
Example : m=1 , n=5 , cross each other when n=2 , m=4
m=-6 , n=-10 , cross each other when n=-7, m=-9
m=5 , n=1 , cross each other when n=4 , m=2
23. Write a function that returns value of m*2n
m>0 and n>0
Note: 1 .Use call by reference parameter passing method
2 . Function should return integer value
3. Use bitwise operators to compute m*2n
4 . Do not use any predefined functions to compute m*2n

24. c program to find perfect numbers between 10 and to a given number using a
function with arguments and with return type
For example:

Tes Input Result


t

1 500 28 496

2 9000 28 496
8128

25. Write a C program to print strong numbers between two given numbers using
recursion. (Note: And pass values to the function to its address to perform the
operation)
For example:

Tes Input Result


t

1 20 650 145

2 220 40585
65412

26. C program to print prime numbers between intervals using recursion


For example:

Tes Input Result


t
1 20 60 23 29 31 37 41 43 47 53 59

2 52 53 59 61 67 71 73 79 83 89 97 101 103 107 109


125 113

27. Write a program in C to check whether a number is a prime number or not using the
function.
For example:

Tes Input Result


t

1 5 The number 5 is a prime number

2 10 The number 10 is not a prime


number

28. C program to find the area of a circle and the area of a triangle using two functions
with arguments and call these two functions from the third function and pass values
to those two functions through this third function. And call the third function from
the main function (Note: take the first two parameters to calculate the area of a
triangle and the third parameter to calculate the area of the circle)
For example:

Tes Input Result


t

1 5 13 20 area of the triangle:


32.50000
area of a circle: 1256.64

2 15 23 area of the triangle:


62 172.500000
area of a circle: 12076.27

29. Write a C program "to store 5 numbers in dynamically created memory and a
function that returns biggest of the numbers stored in that memory".
Note : 1. Use call by reference parameter passing method.
2. Function should return a integer value.
30. Write a function ( c program ) to count all perfect numbers in between m,n.
(n>m , m>1 , n>1)
In number theory, a perfect number is a positive integer that is equal to the sum of its
positive divisors, excluding the number itself. The smallest perfect number is 6, which is
the sum of 1, 2, and 3.
Note 1. Use call by reference parameter passing method
2. Your function should return a pointer.
31. Using recursion write a c program to computer mm
(m>0)
Note : 1.Use call by value method to pass parameters and
2.function should return an integer
3.Do not use any predefined functions
32. Write a program to generate the Fibonacci series using recursion.
For example:

Tes Input Result


t

1 12 144

2 8 21

33. Write a program to generate the Fibonacci series using any function category.
For example:

Tes Input Result


t

1 7 0 1 1 2 3 5
8

4 0 1 1
2

34. check given number is armstrong number or not using without argument without
return type
For example:
Tes Input Result
t

1 153 Armstrong Number

2 150 Not Armstrong


Number

35. Write a C program to print all strong numbers between given intervals using
functions.
For example:

Tes Input Result


t

1 1 1000 1 2
145

2 67 145
1000

36. Write a c program to find the GCD of two numbers using with arguments and with
return type.
For example:

Tes Input Result


t

1 24 30 6

2 6 18 6

37. Write a C program to find power of any number using recursion

For example:
Tes Input Result
t

1 2 3 8

2 3 4 81

38. Write a program in C to find the sum of digits of a number using recursion.
For example:

Tes Input Result


t

1 enter any number to find sum of digits: The Sum of digits of 25 =


25 7

2 enter any number to find sum of digits: The Sum of digits of 105
105 = 6

39. program to solve quadratic equation.


Function returns 0 if roots are equal
Function returns 1 if roots are unequal
Function returns -1 if roots are imaginary
40. Read the following instructions carefully and write C program using functions
concept that will do the intended task.
1. Store five positive integers in dynamically created memory
2. Compute the sum of first two adjacent even numbers.( sum will be 0 if
no even integer in the given input)
Note: 1.Use call by reference parameter passing method
2. Your function should return a pointer (i.e sum ).
3. Display the sum in main function.
Example :
Input: 21 ,4 ,6,110 , 891 then sum=10
Input : 1 ,5, 7, 981,77 then sum=0
Input: 2 ,4 ,6,110 , 890 then sum=6

You might also like