Lab_Assignment-7(1)
Lab_Assignment-7(1)
1. Rewrite the following program by taking the input to variable i from keyboard.
#include<stdio.h>
void main()
{
int i = 5;
int *p, **q;
p = &i;
q = &p;
printf("Address of i = %u or p=%u or *q=%u\n",&i,p,*q);
printf("Address of p = %u or q=%u\n",&p,q);
printf("Address of q = %u\n",&q);
printf("Value of i = %d or *(&i) = %d or *p = %d or **q=%d\n", i,*(&i),*p,**q);
printf("Value of q = %d\n",q);
}
2. Write a program to initialize pointers to an integer variable, a float variable and a
character variable and then print the values and corresponding addresses using the
expression with respective pointers of the variables.
3. Write a program which accepts a lowercase character as input in main and passes the
address of the input character to a function which changes the value two it’s uppercase.
4. Write a program to read 20 numbers between 10 and 100, inclusive. As each number is
read, print it only if it’s not a duplicate of a number already read.
5. A small airline has just purchased a computer for its new automated reservations
system. Write a program to assign seats of a plane (capacity of 10 seats). Your program
Should display the following menu of alternatives:
Please type 1 for ‘first class’
Please type 2 for ‘economy’
If the person types 1, then your program should assign a seat in the first class section
(seats 1 to 5). If the person types 2, then your program should assign a seat in the
economy section (seats 6 to 10). Your program then prints the boarding pass indicating
the person’s seat number and class.
Use an array to represent the seating chart of the plane. Initialize all the elements of the
array to 0 to indicate that all seats are empty. As each seat is assigned, set the
corresponding element of the array to 1 to indicate that the seat is no longer available.
When the first class option is full, your program should ask the person if it’s acceptable
to be placed in the economy section (and vice versa). If yes, make the appropriate
assignment. If no, then print the message, “Next flight leaves in 3 hours”.
6. Write a program to pass two values as reference to a function which computes the
following:
Add 2 to each number, then add the resulted numbers and print the value
Multiply each number by 6 and then take the product. Finally divide the
resultant value by 3 and print.
Take mod of the larger number with the smaller one and print the result
At the end print both the values in the function main
7. Write a recursive function to print the following structure where number of rows is
the input through keyboard:
S
SS
SSS
SSSS
………… #rows times
8. Write a program to find all primes less than or equal to N. To find whether a number
p is prime or not check if p is divisible by all primes less than p.