Lab 3 OS
Lab 3 OS
If it is not pre installed then run “sudo apt install gcc” command in terminal to install it.
After completing above command,again run “gcc –version” to check gcc compiler is installed or
not.
Q-1) C program to swap two numbers with function and without function,without using
third variable.
Algorithm:
1.start
2.Take input a,b
3.a=a+b
4.b=a-b
5.a=a-b
6.print a,b
Code:
a)swap using function:
The swap function swaps the numbers using addition and subtraction.We need to pass the
address of variables to the function using pointer ie.call by reference.Pointer is used to allow the
function to modify the original variables directly.
Output:
Output:
Algorithm: 1.start
2.take input temperature in fahrenheit(F)
3.Use conversion formula: Celcius(C)= (F-32)*5/9
4.Print temperature in celsius
Code:
Output:
Output:
Algorithm: 1.start
2.Declare a1,a2,b1,b2, addR,addI
3. Enter the real and imaginary part of first complex number
4.Enter the real and imaginary part of second complex number
5. Add the real part of both complex number and store in addR.
6. Add the imaginary part of both complex number and store in addI.
7. Display addition of two complex number i.e addR+j addI
8.end
Code:
Output:
Algorithm: 1.start
2.take num as input (up to which u have to print prime number)
3.now take every number ‘i’ start from i=2 to i=num
4.set a variable count to 1
5. Now check for ‘i’ is prime number or not ,if not make count=0 and break
6. If count is still 1, print i
7.end
Code:
Output:
Conclusion:
We learn how to setup gcc compiler in Linux operating system , also how to run and execute C
program files using linux as operating system through ubuntu interface/terminal.