Académique Documents
Professionnel Documents
Culture Documents
Deepak kumar
17/cs08
2
Linux Commands
1. who: It shows the names of users that are currently
logged in.
Deepak kumar
17/cs08
3
Deepak kumar
17/cs08
4
Deepak kumar
17/cs08
5
17. clear: It clears the screen and give back ,the clean
screen for use.
Deepak kumar
17/cs08
6
Deepak kumar
17/cs08
7
Deepak kumar
17/cs08
8
Program 1
Aim : Write a program to find out the factorial of a number.
Linux code:
echo “enter the number : ”
read a
fact=1
for ((i=$a;i>0;i--))
do
fact=$((fact*i))
done
echo “Factorial of $a is $fact”
output:
Deepak kumar
17/cs08
9
Program 2
Aim : Write a program to find the greatest among three
numbers.
Linux code:
echo “Enter three numbers :”
read a b c
if [ $a –gt $b ]
then
if [ $a –gt $c ]
then
echo “ $a is greatest ”
else
echo “$c is greatest ”
fi
else
if [ $b –gt $c ]
then
echo “$b is greatest”
else
echo “$c is greatest ”
fi
fi
output :
Deepak kumar
17/cs08
10
Program 3
Aim : write a program to find a pattern in a file.
Linux code:
echo “Enter the file name:”
read file1
echo “enter the pattern to search:”
read pattern
echo “find the $pattern in file”
grep “$pattern” $file1
output:
Deepak kumar
17/cs08
11
Program 4
Aim: write a program to check whether given number is
palindrome or not .
Linux code:
num=545
s=0
rev=""
temp=$num
while[ $num -gt 0 ]
do
s=$(( $num % 10 ))
num=$(( $num / 10 ))
rev=$( echo${rev}${s} )
done
if[ $temp -eq$rev ];
then
echo"Number is palindrome"
else
echo"Number is NOT palindrome"
fi
Output :
Deepak kumar
17/cs08
12
Program 5
Aim : write a program to check whether the number is
prime or not.
Linux code:
echo "Enter a number"
read a
flag=0
i=2
while [ $i -ge $(($a/2)) ]
do
if [ $(($i % 2)) == 0 ]
then
flag=1;
break
fi
done
if [ $flag == 1 ]
then
echo "$a is not a prime"
else
echo "$a is a Prime"
fi
Output :
Deepak kumar
17/cs08
13
Program 6
Aim : write a program to concatenate two strings.
Linux code:
echo Enter first string:
read s1
echo Enter second string:
read s2
s3=$s1$s2
len=`echo $s3 | wc -c`
len=`expr $len - 1`
echo “Concatinated string is $s3 of length $len”
Output:
Deepak kumar
17/cs08
14
Program 7
Linux code:
#include<stdio.h>
Void main()
Int I,j,k;
Int space=5;
Int max=5;
For(j=1;j<=max;j++)
For(i=space;i>=0;i--)
Printf(“ ”);
For(k=1;k<=j;k++)
Printf(“*”);
Space--;
Printf(“\n”);
Output:
Deepak kumar
17/cs08
15
Program 8
Aim :write a program in c to calculate the average marks of five subjects of a student.
Linux code:
#include<stdio.h>
Void main()
Int s[10],sum=0,i,avg;
For(i=1;i<=5;i++)
Scanf(“%d”,&s[i]);
Sum+=s[i];
Avg=(sum/5);
Printf(“\nAvg:=%d”,avg);
Printf(“\nPercentage=%d”,avg*100);
Output:
Deepak kumar
17/cs08
16
Program 9
Linux code:
#include<stdio.h>
Void main()
Int z,a,b;
Scanf(“%d”,&a);
Scanf(“%d”,&b);
Printf(“\n1. To Add\n2.Divide\n3.Multiply\n4.Subtract”);
Scanf(“%d”,&z);
Switch(z)
Case 1:printf(“\nAddition=%d”,a+b);
Break;
Break;
Break;
Break;
Output:
Deepak kumar
17/cs08
17
Program 10
Linux code:
#include<stdio.h>
void main()
int a[100][10],b[10][10],c[10][10],n,i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
Deepak kumar
17/cs08
18
c[i][j]=a[i][j]+b[i][j];
printf("--------------------C-MATRIX---------------------\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
printf("\t%d\t",c[i][j]=a[i][j]+b[i][j]);
printf("\n");
Output:
Deepak kumar
17/cs08
19
Deepak kumar
17/cs08