model lab 2-set 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

1.

Write a C program to demonstrate the following


Pointer to Array:
​ Declare an integer variable n and a pointer ptr3 to an integer array. Allow the user to
input the size of the array and then input n integers to store in the array. Use the pointer
ptr3 to access and print the elements of the array.
Test case 1
Test case 1

size:·5

Elements:·1 2 3 4 5

Accessing·array·elements·using·pointer:1·2·3·4·5·⏎

Enter·two·integers:·16 9

Using·pointer·to·add:·25⏎

Using·pointer·to·subtract:·7⏎

Print whether a given number is prime or not using functions

Create a structure named Book to store book details like title, author, and price. Write a C
program to input details for three books, find the most expensive and the lowest priced books,
and display their information.

2. Get a number from the user and print factorial of a given number using recursive
functions
Write a C program to reverse a string without using library functions and using pointers.
Sample Input and Output:
Enter a string : Hindustan

Create a structure named "Employee" to store employee details such as employee ID, name,
and salary. Write a program to input data for three employees, find the highest salary employee,
and display their information.
3. Write a C program that uses typedef and takes input from the user to calculate the area
of a rectangle.
Write a program given an array, write a program to reverse it using pointers .
Write a program to find the GCD and LCM of two numbers using functions.
Input and Output Format:
Input consists of two integers corresponding to two values.
Output consists of two integers corresponding to GCD and LCM of the two numbers.

4. .C Program to Add Two Distances (in inch-feet system) using Structures


Write a C program that uses preprocessor directives to define macros for calculating the sum
and product of two numbers entered by the user.

n1:·3

n2:·8

Sum:·11.00⏎

Product:·24.00

​ Write a recursive C program which computes the nth Fibonacci number for an
appropriate value of n.

5. Write a C program to demonstrate the following


​ Declare an integer variable x and two pointers ptr1 and ptr2. Use ptr1 and ptr2 to display
the value of x with single and double indirection, and allow the user to update the value
of x through double indirection.
​ Write a C program that uses bit fields and takes input from the user to store, calculate
their total and average. Display student's scores, total and average.
Write a C program to compute internal marks of a student for five different subjects using
structures and functions.

6. Write a C program to perform arithmetic operations on two numbers using pointers.


Write a menu driven program to find the area of the following shapes. Use the structures and
use PI value as 3.14
​ Write a program given an array A[] consisting 0s, 1s and 2s, write a function that sorts
A[]. The functions should put all 0s first, then all 1s and all 2s in last.
7. Write a C program that uses preprocessor directives to define macros for calculating the
sum and product of two numbers entered by the user.
Write a C program to find the maximum of 3 numbers using functions and pointers.
​ Write a program to find the addition of two matrices using functions.

8. Write a C program to demonstrate the usage of pointers.


​ Declare an integer variable "number" and an integer pointer"pointer". Allow the user to
input an integer, store it in "number", and then use the pointer "pointer" to access and
modify the value of "number".
C to pass a structure to a function and display its members.
Print the sum of n numbers using functions

9. Write a C program to demonstrate the usage of unions which manages two integer
values, x and y
Find the time taken to bake a cake for a cooking competition.Given the starting time and ending
time.
Print no.of.digits in a given number using recursive function

10. Write a C program that uses pre-processor directives to define and use constants, and it
takes input from the user to calculate the area of a circle.
Write a program to get the details of n students and to display their details, sorted in ascending
order based on marks
Print the maximum of n numbers using functions

You might also like