You are on page 1of 4

1.

Write a program that declares and initializes a double, an integer, and a


char. Then declare and initialize a pointer to each of the three variables and
display both value and address.

2. Write a program to swap value of two variables using pointer.


3. Print the output of variable z as z= 5,z=10, z=20 in oredr using the following
snippet.

#include <stdio.h>
int z=10;
int add1(int x,int y);
int add2(int k);
int main()
{
int a=2,b=3,c=0,d=0;
c=add1(a,b);
d = add2(c);
return 0;
}
int add1(int x,int y)
{
int z=0;
z=x+y;
return z;
}
int add2(int k)
{
int m=0;
m=z+k+5;
return m;
}

4. Write a program to ckeck whether a given string is palindrome or not using


pointers.

5. Write a program to sort an array in descending order using pointers.

6. Write a function named check() that has three parameters. The first
parameter should accept an integer number, and the second and third
parameters should accept a double precision number. The function body
should just display the values of data passed to the function when it’s called.

7. Write a program to accept a figure code and find the area of different
geometrical figures such as circle, square, triangle and rectangle using
switch case and functions.

8. Write a program to add, subtract, multiply and divide two integers using
user-defined type functions for each operation with return type.

9. Write a function that takes a positive integer as input and returns the
leading digit in its decimal representation.

10. Write a C function that takes a positive integer n as an argument and


returns the largest power of two lesser than or equal to n.
[Hint: Solution is to use bitwise left shift operator to find all powers of 2
starting from 1. For every power check if it is smaller than or equal to n or
not.]

11. Write a program that accepts an array of integers and displays the average.
Use a function to calculate the average.

12. Write a function to find the given year is a leap year or not.

13. Write two functions that compute f(x)=2.3*x and g(x,y)=x*y. x and y are
user defined values.

14. Write a program using functions to store some elements (1-D Array) and
accept key then split the array from that point and add the first half to the
end of second half.
(Eg: Enter the value of n: 5 enter the numbers:30 10 40 50 60. Enter the
position of the element to split the array: 2. The resultant array is: 40 50 60
30 10)

15. Write a program to find the sum of all odd numbers within the given limit
using recursion.

16. Write a program to find G.C.D of a number using recursion.


17. Write a program to calculate the power of a number using recursion.

18. Write a program to find the sum of the series 1!/1+2!/2+3!/3+4!/4+5!/5


using the function.

19. Write a program to convert decimal number to binary number using the
function.

20. Write a program to find reverse of any number using recursion.

21. Write a program to find Sum of elements positioned at even places of an array
using function.

22. Write a function float[] getIntersectingPoint(double[][] points) that returns


intersection point of two lines. Assume that (x1,y1), (x2,y2) are two points on
line 1 and (x3,y3), (x4,y4) are on line 2. The points are stored in a 4-by-2 two
dimentional array points with points[0][0], points[0][1] are x1,y1 and so on.
The function should return the intersecting point as an array or 0 if the two
lines are parallel. Write a program to promt the user to enter four points and
display the intersecting point.

23. Given a set of cities, the central city is the city that has the shortest total
distance to all other cities. Write a program that prompts the user to enter the
number of the cities and the locations of the cities (coordinates). Write
functions to find the central city and its total distance to all other cities.

For example

Enter the number of cities: 5

Enter the coordinates of the cities:

2.5 5.0 5.1 3.0 1.0 9.0 5.4 5.4 5.5 2.1

The central city is at (2.5, 5.0)

The total distance to all other cities is 60.81


24. Implement the function float[][] sortColumns(float[][] m) to sort the columns
in a two-dimensional array. Write a test program that prompts the user to
enter a 3 * 3 matrix of double values and displays a new column-sorted matrix.

For example

Enter a 3-by-3 matrix row by row:


0.15 0.875 0.375
0.55 0.005 0.225
0.30 0.12 0.4

output:

The column-sorted array is


0.15 0.0050 0.225
0.3 0.12 0.375
0.55 0.875 0.4

25. Consider an array having size 20. If the array is not full, an element can be
inserted at the beginning, ending or any user defined position. If the array is
not empty, an element can be removed from the beginning, ending or any user
defined position. Write a program to implement the concept using the
following functions:

bool isEmpty(int arr[ ]): Verifies whether an array is empty.


bool isFull(int arr [ ]): Verifies whether an array is full.
void insertBegin(int arr[ ], int val): Inserts given value at the beginning of
an array if it is not full.
void insertAt(int arr[ ], int val, int pos): Inserts given value at the given
position of an array if it is not full.
void insertEnd(int arr[ ], int val): Inserts given value at the end of an array
if it is not full.
int removeBegin(int arr[ ]): Removes value at the begining of array if it is
not empty.
int removeAt(int arr[ ], int pos): Removes value at the given position of an
array if it is not empty.
int removeEnd(int arr[ ]): Removes value at the end of an array if it is not
empty.
void display(int arr[ ]): Displays the array elements.

You might also like