Professional Documents
Culture Documents
Practical File
Practical File
Practical File
Chittorgarh (Raj)
Submitted by
Ravi Soni
Shell Program
1. Write a shell program to find the average of students marks using for loop and while loop.
2. Write a shell program to convert temperature in centigrade to Fahrenheit.
3. Write a shell script that accepts a file name starting and line number as arguments and
display all line.
4. Write a shell script to print months in a year using switch case.
5. Write a shell script to compute all arithmetic operations on which are given by user.
6. Write a shell script to find the area of the triangle.
7. Write a shell script that accept two integers as its argument and computes the value of first
number raised to the power of the second number.
/* Program to sort an array using Bubble Sort, Insertion Sort & Selection Sort */
Output:
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
void main()
{
char sentence[100];
int count, ch, i;
clrscr();
printf("Enter a sentence\n");
for(i=0; (sentence[i] = getchar())!='\n'; i++)
{ ; }
count = i;
printf("\nInput sentence is : %s ",sentence);
printf("\nResultant sentence is : ");
for(i=0; i < count; i++)
{
ch = islower(sentence[i]) ? toupper(sentence[i]) :
tolower(sentence[i]); putchar(ch);
}
getch();
}
Output:
#include<conio.h>
#include<math.h>
void main()
int a,b,c,s;
clrscr();
cin>>a>>b>>c;
s=(a+b+c)/2;
s=sqrt(s*(s-a)*(s-b)*(s-c));
getch();
Output:
#include<conio.h>
void main()
int i,j,k,n;
clrscr();
n=4;
for(i=0;i<5;i++)
for(k=n;k>=0;k--)
printf(" ");
for(j=i+1;j>0;j--)
printf(" *");
printf("\n");
n--;
n=0;
for(i=4;i>0;i--)
for(k=n+2;k>0;k--)
for(j=i;j>0;j--)
printf(" *");
printf("\n");
n++;
getch();
Output:
Shell Script
#!/bin/csh
--------------------------------------------------------------
Write a shell script that accepts two integers as its arguments and computes the value of first
number raised to the power of the second number.
Shell Script
#!/bin/csh
set c = 1
set result = 1
@ result *= $argv[1]
@ c = $c + 1
end
--------------------------------------------------------------
Shell Script
# formula Tf=(9/5)*Tc+32
# formula Tc=(5/9)*(Tf-32)
tc=$(echo "scale=2;(5/9)*($tf-32)"|bc)
echo "$tf = $tc"
else
echo "Please select 1 or 2 only"
exit 1
fi
--------------------------------------------------------------
Shell Script
for i in $*
do
temp_total=`expr $temp_total + $i`
done
avg=`expr $temp_total / $number_of_args`
echo "Average of all marks is $avg"
--------------------------------------------------------------
Shell Script
--------------------------------------------------------------
Shell Script
if [ $# -lt 3 ]
then
echo "$0 num1 opr num2"
echo "opr can be +, -, / , x"
exit 1
fi
case "$op" in
+) echo $(( $a + $b ));;
-) echo $(( $a - $b ));;
/) echo $(( $a / $b ));;
x) echo $(( $a * $b ));;
*) echo "Error ";;
esac
--------------------------------------------------------------
Write a shell script that accepts two integers as its arguments and computes the value of first
number raised to the power of the second number.
Shell Script
#!/bin/csh
set c = 1
set result = 1
@ result *= $argv[1]
end