0% found this document useful (0 votes)
2 views4 pages

FC Assignment: Question 1:write A Shell Script To Find The Sum of Numbers From 1 To 10

The document contains multiple exercises involving shell scripting and web development. It includes a shell script to calculate the sum of numbers from 1 to 10, another for calculating the factorial of a number, and a calculator built using HTML, CSS, and JavaScript. Each section provides code snippets and descriptions for the respective programs.

Uploaded by

Xorus Dremus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

FC Assignment: Question 1:write A Shell Script To Find The Sum of Numbers From 1 To 10

The document contains multiple exercises involving shell scripting and web development. It includes a shell script to calculate the sum of numbers from 1 to 10, another for calculating the factorial of a number, and a calculator built using HTML, CSS, and JavaScript. Each section provides code snippets and descriptions for the respective programs.

Uploaded by

Xorus Dremus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Fc assignment

Question 1:Write a shell script to find the sum of numbers from 1 to 10.
Code
# !/ bin / bash
sum =0
for (( i =1; i <=10; i ++) )
do
sum = $ (( sum + i ) )
done
echo " Sum of numbers from 1 to 10 is : $sum "
Program 1: Shell program to find sum of numbers from 1 to 10

Output

Exercise 2:Write a shell script to find the factorial of a number

Code

# !/ bin / bash

read -p " Enter a number to calculate factorial : " num


factorial =1

for (( i =1; i <= num ; i ++ ) )


do
factorial = $ (( factorial * i ) )
done
echo " Factorial of $num is : $factorial "
Program 2: Shell program to find factorial

Output

1
Exercise 3:Create a calculator using html css and javascript

Code calculator.html
<! DOCTYPE html >
< html lang = " en " >
< head >
< meta charset = " UTF -8 " / >
< title > Calculator HTML CSS JavaScript | CodingNepal </ title >
< link rel = " stylesheet " href = " style . css " / >
< link rel = " stylesheet " href = " ../ custom - styles . css " / >
< script src = " ../ custom - scripts . js " defer > </ script >
< style >
. download - btn - cn a {
background : none ;
color : #2 f9fff ;
border : 2 px solid #2 f9fff ;
}
. download - btn - cn a : hover {
color : # fff ;
background : #2 f9fff ;
}
</ style >
</ head >
< body >
< div class = " container " >
< input type = " text " class = " display " disabled / >
< div class = " buttons " >
< button class = " operator " data - value = " AC " > AC </ button >
< button class = " operator " data - value = " DEL " > DEL </ button >
< button class = " operator " data - value = " % " >% </ button >
< button class = " operator " data - value = " / " >/ </ button >

< button data - value = " 7 " >7 </ button >
< button data - value = " 8 " >8 </ button >
< button data - value = " 9 " >9 </ button >
< button class = " operator " data - value = " * " >* </ button >

< button data - value = " 4 " >4 </ button >
< button data - value = " 5 " >5 </ button >
< button data - value = " 6 " >6 </ button >
< button class = " operator " data - value = " -" > - </ button >

< button data - value = " 1 " >1 </ button >
< button data - value = " 2 " >2 </ button >
< button data - value = " 3 " >3 </ button >
< button class = " operator " data - value = " + " >+ </ button >

< button data - value = " 0 " >0 </ button >
< button data - value = " 00 " > 00 </ button >
< button data - value = " . " >. </ button >
< button class = " operator " data - value = " = " >= </ button >
</ div >
</ div >

< script src = " script . js " > </ script >
</ body >
</ html >
Program 3: HTML code for Calculator

2
style.css
* {
margin : 0;
padding : 0;
box - sizing : border - box ;
font - family : " Poppins " , sans - serif ;
}
body {
height : 100 vh ;
display : flex ;
align - items : center ;
justify - content : center ;
background : # e0e3eb ;
}
. container {
position : relative ;
max - width : 340 px ;
width : 100%;
border - radius : 12 px ;
padding : 10 px 20 px 20 px ;
background : # fff ;
box - shadow : 0 5 px 10 px rgba (0 , 0 , 0 , 0.05) ;
}
. display {
height : 80 px ;
width : 100%;
outline : none ;
border : none ;
text - align : right ;
margin - bottom : 10 px ;
font - size : 28 px ;
color : #000 e1a ;
background : # fff ;
pointer - events : none ;
}
. buttons {
display : grid ;
grid - gap : 10 px ;
grid - template - columns : repeat (4 , 1 fr ) ;
}
. buttons button {
padding : 10 px ;
border - radius : 6 px ;
border : none ;
font - size : 23 px ;
cursor : pointer ;
background - color : # eee ;
}
. buttons button : active {
transform : scale (0.99) ;
}
. operator {
color : #2 f9fff ;
}
Program 4: CSS stylesheet for Calculator

script.js
const display = document . querySelector ( " . display " ) ;
const buttons = document . querySelectorAll ( " button " ) ;

3
const specialChars = [ " % " , " * " , " / " , " -" , " + " , " = " ];
let output = " " ;

// Define function to calculate based on button clicked .


const calculate = ( btnValue ) = > {
display . focus () ;
if ( btnValue === " = " && output !== " " ) {
// If output has ’% ’ , replace with ’/100 ’ before evaluating .
output = eval ( output . replace ( " % " , " /100 " ) ) ;
} else if ( btnValue === " AC " ) {
output = " " ;
} else if ( btnValue === " DEL " ) {
// If DEL button is clicked , remove the last character from the
output .
output = output . toString () . slice (0 , -1) ;
} else {
// If output is empty and button is specialChars then return
if ( output === " " && specialChars . includes ( btnValue ) ) return ;
output += btnValue ;
}
display . value = output ;
};

// Add event listener to buttons , call calculate () on click .


buttons . forEach (( button ) = > {
// Button click listener calls calculate () with dataset value as
argument .
button . addEventListener ( " click " , ( e ) = > calculate ( e . target . dataset .
value ) ) ;
}) ;
Program 5: Javascript for Calculator

Output

You might also like