Question 1

Write a program to accept a string from user and using pointers

  • Print the string in reverse order.
  • Calculate the length of the string.

Input:

Enter a string:
pointers

Output:

String in reverse order: sretniop
Length of the string: 8

Question 2

Write a program to implement calculator as we had done in Assignment 2, using pointers. You need to write separate function for all the operations(+,-,*,/). In these functions you need to pass the variables as pointers and then perform the requested operation and return the result. To calculate the result you should not use a third variable.

For example: Consider the function int sum(int *a, int *b); Here, the addition of two numbers must be stored in a and returned.

Question 3

Write a program to swap two numbers using pointers. You should write a function swap() where you pass two numbers and return the result to the call and print it there.

Input:

Enter two numbers:
a= 5
b=16

Output:

Numbers after swapping
a= 16
b= 5

Question 4

Write a program in C to sort the elements of an array using pointers. The elements must be sorted in both ascending and descending order. You must write two different functions sortAscending() and sortDescending() to do the sorting.

Input:

Input array elements: 10 -1 0 4 2 100 15 20 24 -5

Output:

Array in ascending order: -5, -1, 0, 2, 4, 10, 15, 20, 24, 100
Array in descending order: 100, 24, 20, 15, 10, 4, 2, 0, -1, -5
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.