Professional Documents
Culture Documents
Bahria University,
Karachi Campus
LAB NO.2
TASK NO OBJECTIVE
1 Practice all the Linux commands discussed in this lab while taking
assistance using the man command. Write the complete syntax used for
utilizing the cp, mv and rm commands in Linux shell.
2 Write the C programs provided in this lab and generate their outputs
over Linux environment (provide snapshot).
3 Write a C program on the Linux environment that takes your marks as
an input and display your grades accordingly to that followed at Bahria
University. Limit your program to a maximum of five subjects. Use the
suitable logical operator(s), i.e. and (&&), or (||), not (!), if required.
4 Write a shell script to display your address over multiple lines.
5 Write a shell script that would traverse among any three directories that
are placed under the /home directory. While moving from one directory
to another, the script should display the name of the current working
directory and list the content within that directory, including the hidden
files.
Submitted On:
18/03/2021
(Date: DD/MM/YY
LAB 2
OS LAB 2 BSE 4A
M.SAQIB AZIZ (65146) 02-131192-031
Question # 01:
Practice all the Linux commands discussed in this lab while taking assistance using the
man command. Write the complete syntax used for utilizing the cp, mv and rm
commands in Linux shell.
OS LAB 2 BSE 4A
M.SAQIB AZIZ (65146) 02-131192-031
OS LAB 2 BSE 4A
M.SAQIB AZIZ (65146) 02-131192-031
Question # 02:
Write the C programs provided in this lab and generate their outputs over Linux
environment (provide snapshot).
INPUT:
1)
#include <stdio.h>
int main()
{
int x, n = 10, z;
x = n++;
z = ++n;
printf("The value of x = %d\n", x);
printf("The value of z = %d\n", z);
return 0;
}
2)
#include <stdio.h>
#define LIMIT 50
int main()
{
int age;
printf("Hello, please enter your age!\n");
OS LAB 2 BSE 4A
M.SAQIB AZIZ (65146) 02-131192-031
scanf("%d", &age);
if(age < LIMIT)
{
printf("Your age is %d.\n", age);
printf("Still young!!\n");
}
else if(age == LIMIT)
{
printf("Your age is %d.\n", age);
printf("Almost there.\n");
}
else
{
printf("Your age is %d.\n", age);
printf("You are a senior!\n");
}
return 0;
}
OUTPUT:
1)
2)
OS LAB 2 BSE 4A
M.SAQIB AZIZ (65146) 02-131192-031
Question # 03:
Write a C program on the Linux environment that takes your marks as an input and
display your grades accordingly to that followed at Bahria University. Limit your
program to a maximum of five subjects. Use the suitable logical operator(s), i.e. and
(&&), or (||), not (!), if required.
INPUT:
#include <stdio.h>
int main()
{
int num;
int num2;
printf("\nEnter your marks of English\n ");
scanf("%d",&num);
printf("\nEnter your marks of Computer Programming\n ");
scanf("%d",&num2);
OS LAB 2 BSE 4A
M.SAQIB AZIZ (65146) 02-131192-031
OS LAB 2 BSE 4A
M.SAQIB AZIZ (65146) 02-131192-031
else if ( num2 >=80 && num2<=84){ // Note the space between else & if
printf(" \nYou got A- grade in Computer Programming\n");
}
else if ( num2 >=75 && num2 <=79){
printf(" \nYou got B+ grade in Computer Programming\n");
}
else if ( num2 >=70 && num2<=74){
printf(" \nYou got B- grade in Computer Programming\n");
}
else if ( num2 >=65 && num2<=69){
printf(" \nYou got B grade in Computer Programming\n");
}
else if ( num2 >=60 && num2<=64){
printf(" \nYou got C+ grade in Computer Programming\n");
}
else if ( num2 >=55 && num2<=59){
printf(" \nYou got C grade in Computer Programming\n");
}
else if ( num2 >=50 && num2<=54){
printf(" \nYou got D grade in Computer Programming\n");
}
else if ( num2 <50){
printf(" \nYou Failed in Computer Programming\n");
}
return 0;
}
OS LAB 2 BSE 4A
M.SAQIB AZIZ (65146) 02-131192-031
OUTPUT:
Question # 04:
Write a shell script to display your address over multiple lines.
Question # 05:
Write a shell script that would traverse among any three directories that are placed
under the /home directory. While moving from one directory to another, the script
should display the name of the current working directory and list the content within
that directory, including the hidden files.
OS LAB 2 BSE 4A
M.SAQIB AZIZ (65146) 02-131192-031
OS LAB 2 BSE 4A