0% found this document useful (0 votes)
22 views30 pages

Model Ques Comp

The document is a comprehensive guide covering various topics related to databases, networking, programming, and software development. It includes detailed explanations of concepts such as database management systems, transmission media, scripting languages, object-oriented programming, and the software development lifecycle. Additionally, it provides practical coding examples in PHP and JavaScript, illustrating how to implement these concepts in real-world applications.

Uploaded by

jelishasubedi85
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)
22 views30 pages

Model Ques Comp

The document is a comprehensive guide covering various topics related to databases, networking, programming, and software development. It includes detailed explanations of concepts such as database management systems, transmission media, scripting languages, object-oriented programming, and the software development lifecycle. Additionally, it provides practical coding examples in PHP and JavaScript, illustrating how to implement these concepts in real-world applications.

Uploaded by

jelishasubedi85
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/ 30

Chapter 1

1.​ What are data, information and database?


2.​ What is database? What are the objectives of a database?
3.​ What is a database management system? How does database management system
works?
4.​ What is hierarchical data model?
5.​ What is data normalization? What are the most important and widely used forms
of data normalization?
6.​ Explain the types of database models.
7.​ What is a primary key? What are the features of good primary keys?
8.​ What are the advantages and disadvantages of a database? Explain briefly.
9.​ Explain the difference between centralized database and distributed database.
10.​ What is data security? What are the different data security methods?
11.​ Why in normalization needed? Explain the normalization process with example.
12.​ Describe 1NF, 2NF and 3NF normalization concept with examples.
13.​ Explain DDL and DML.
14.​ Define database administrator. What is the role of database administrator?
15.​ What is the purpose of ER diagram? List out the different symbols used in ER
diagram with their meanings and example.

Chapter 2
1.​ What is transmission media? Explain any two different types of transmission
media.
2.​ What is optical fiber? Write advantages of optical fiber cable.
3.​ Differentiate between LAN and WAN.
4.​ What is communication system? Explain basic elements of communication
system.
5.​ Explain Unshielded Twisted Pair (UTP) and Coaxial cable.
6.​ Describe star topology with suitable diagram.
7.​ Explain bus and ring topology with advantages and disadvantages.
8.​ Differentiate between guided and unguided networking media.
9.​ Differentiate between internet and intranet.
10.​ Describe different types of communication modes.
11.​ Write the difference between Client server and peer to peer Network
12.​Differentiate between IPV4 and IPV6.
13.​What are topologies? Explain different types of topology.

1
14.​What is OSI Model? Explain.
15.​Explain the different network connecting devices.
16.​Explain about 7 layers of the OSI/ISO model of networking.
17.​Explain different types of Guided media.
18.​Explain different types of Unguided media.
19.​Write short notes on:
​ ​ ​ IP Address
​ ​ ​ MAC Address
​ ​ ​ Subnet
​​ ​ ​ Internet
​​ ​ ​ Intranet
​​ ​ ​ Extranet
20. Explain different network connecting devices.

Chapter 3
1.​ What do you mean by scripting language? Describe the types of scripting
language.
2.​ Differentiate between static and dynamic web pages.
3.​ Differentiate between server side and client side scripting.
4.​ Differentiate between programming language and scripting language.
5.​ Difference between while and do while loop.
6.​ What do you mean by JavaScript? Write the advantages of using JavaScript.
7.​ Explain how to add JavaScript code to HTML.
8.​ Describe the method to use function in JavaScript with example.
9.​ Explain the data types used in JavaScript.
10.​ What is variable? How variable is declared in JavaScript?
11.​ What is operator? Explain the types of operator used in JavaScript.
12.​ Explain increment and decrement operator with example.
13.​ What is loop? Explain types of loop with example.
14.​ What is event? Describe the types of events in HTML
15.​ What is function? Write its advantages.
16.​ What are the benefits of using JavaScript in a HTML page?
17.​ Write a JavaScript and HTML code to input cost price and sales price and find
the profit or loss.
18.​ Write a JavaScript and HTML code to display the following series: 1, 2, 3, 4, 5,
6 …….. 100.
19.​ Write a JavaScript and HTML code to display the following series: 1, 4, 9, 16,
25, …… up to 10th term.

2
20.​ Write a JavaScript and HTML code to enter a number and display whether it is
prime or not.
21.​ Write a JavaScript and HTML code to display the multiplication table of a
given number.
22.​ Write a JavaScript and HTML code to display the following patterns:
a.
1 b. 1
1 2 1 1
1 23 1 11
1 234 1 111
1 2345 1 1111
7.​ Write a JavaScript and HTML code to input a number and display whether it is
odd or even
8.​ Write a JavaScript and HTML code display the sum of 'n' terms of odd numbers.
9.​ Write a JavaScript program to display simple interest.
10.​ Write a JavaScript program to display the area of rectangle
11.​ Write a JavaScript program to display the factorial of a numbers using function
12.​ Write a JavaScript and HTML code to display all the numbers from 1 to 10.
13.​ Write a JavaScript and HTML code to display the multiplication of a number.
14.​ Write a JavaScript and HTML code to display all even numbers up to 50
15.​ Write a JavaScript function to Fahrenheit that converts a temperature
from Celsius to Fahrenheit. [Fahrenheit= 1.8 * Celsius + 32]
16.​ Write a JavaScript function product that takes two numbers and returns their
product.
17.​ Write a HTML and JavaScript code to enter a number from a user and display
whether it is positive or negative.
18.​ What do you mean by event handling? Explain any two events with example
19.​ What is jQuery? Why it is used in the web development?
20.​ What is variable? How variables are declared in PHP? Explain with example.
21.​ Write the rules for naming variable in PHP.
22.​ Describe the data types used in PHP.
23.​ What is operator? Describe PHP operators with examples.
24.​ Describe PHP increment and decrement operator with example.
25.​ Write a PHP code to enter any two values and display their sum, difference
and product.
26.​ Write a PHP code to enter length and breadth of a rectangle and display area
and perimeter.
27.​ Create a registration form including Name, Address, Phone NO, email
address, Qualification, Gender and Country and get the values entered by user
using POST method.
28.​ What is SQL? Why it is used?
29.​ Differentiate between GET and POST method

3
30.​ Explain any five SQL queries with example.
31.​ Explain PHP mysqli_connect() function.
32.​ How do you fetch data from database in PHP.
33.​ How can you update data in database in PHP. explain programmatically.
34.​ Why database connection is required? Explain the database connection
process in PHP and MySQL.
35.​ How can you create database in PHP. Explain with example.

Chapter 4
1.​ What is function? Write the advantages of using function.
2.​ Differentiate between user defined function and library function.
3.​ Differentiate between call by value and call by reference method.
4.​ What do you mean by recursive function? Explain with example.
5.​ What do you mean by storage class? Define auto, register and static storage class.
6.​ Define function. Explain the process of declaring and calling function.
7.​ Write a program to calculate the factorial of given number using function.
8.​ Write a program to calculate the factorial of given number using recursive
function.
9.​ Write a program to enter length and breadth of a rectangle and display its area
using function.
10.​ Write a program to find the sum of 'n' integer numbers using function.
11.​ Write a program to display the sum of n even numbers using function.
12.​ Write a program to display the Fibonacci series up to 10th term using recursive
function.
13.​ Write a program to display series 2, 5, 8, 11, …….. up to nth term using
function.
14.​ Write a program to enter a number and display whether a given number is odd
or even using user defined function.
15.​ Write a program to display simple interest using user defined function.
16.​ Write a program to find whether a given number is positive or negative using
function.
17.​ Write a program to enter a radius of a circle and display its area using user
defined function.
18.​ Write a program to check a given number is even or odd using the function.
19.​ Write a program to check whether entered number is prime number or not
using function.
20.​ What is structure? Write the advantages of using structure.
21.​ What is union? What are the advantages of using union?

4
22.​ Differentiate between structure and union with example.
23.​ Explain how the value of structure can be accessed.
24.​ Differentiate between array and structure.
25.​ Write a program to enter name and marks of 20 students and display them
using structure.
26.​ Write a program to enter the marks of 5 students in Nepali, Computer and using
a structure named Marks having elements roll no., name, Nepali_marks, maths_marks
and Computer_marks and then display the percentage of each student.
27.​ Write a program to enter employee name and basic salary of 50 employees and
display the record in proper format using structure.
28.​ What is pointer? Write the advantages of pointer.
29.​ Define indirection and address of operator.
30.​ Differentiate between call by value and call by reference.
31.​ What is NULL pointer?
32.​ What is file handling concept in c? Explain.
33.​ What is the importance of file pointer in file handling? Explain with an
example.
34.​ Explain any five file handling functions in c.
35.​ Describe fscanf() and fprintf() functions with example.
36.​ Define the terms:
​FILE
​EOF
37.​ Write a program to enter name and salary of employee and write it in a file
employee.txt
38.​ Write a program to enter name, address and salary of 20 employee and store it
in a file staff.dat
39.​ Write a program to enter name, post and salary of a employee and write it in a
file employee.dat
40.​ Write a program which asks name, age, rollno of student and write it in a file
student.dat
41.​ Write a program to display name, age and address reading from a file
record.dat.
42.​ Write a program which reads name, department and age from a file named
employee.dat and display them.
43.​ Write a program which read name, RollNo and age of a student and write them
in a file xyz.dat.
44.​ Write a program which writes "Welcome to Nepal" in a file.

5
Chapter 5
1.​ What is OOP? What are its benefits over structured programming?
2.​ Differentiate between OOP and structured programming.
3.​ Explain the terms polymorphism and inheritance.
4.​ What is object-oriented programming? How is it different from the procedural
oriented programming?
5.​ Why polymorphism and inheritance are important concepts of OOP?
6.​ What are the advantages of using object oriented programming?
7.​ What is OOP? Write an application of OOP.
8.​ Write short notes on:
a.​ Class
b.​ Object
c.​ Polymorphism
d.​ Inheritance
9.​ What is object oriented programming? Explain the features of OOP in brief.

Chapter 6
1.​ Define the term 'Information System‘ and Software Project‘.
2.​ What is SDLC? Why is it important in system development?
3.​ What is the difference between system Analyst and Software Engineer?
4.​ What are the different methods of Requirements Collection in software
development?Explain.
5.​ List out the different phases of SDLC. Explain each of them.
6.​ What are the different models of system development? Explain them.
7.​ List out the different phases of SDLC. Explain each of them.
8.​ What are the different tools used in system design? Describe each of them with
suitable example.
9.​ What is feasibility study? Explain the different levels of feasibility study.
10.​ Define program logic. Explain different types of program logic tools.
11.​ What is documentation? Why is it important?
12.​ What are documentation techniques? Explain with examples.
13.​ What is feasibility study? Why feasibility study is important in system analysis
phase? Explain.
14.​ What is system analysis? What are the major objectives of system analyst?
Explain.

6
15.​ Explain about the different testing techniques during the system development.
16.​ Describe the Agile model to explain the SDLC with advantages and
disadvantages.
17.​ Explain the Prototype model for SDLC with advantages and disadvantages.
18.​ Explain the concept of system design with different tools.
19.​ Write short notes on:
a.​ Waterfall Model
b.​System Analyst
c.​ Software engineer
d.​Prototyping model
e.​ Spiral Model
f.​ Agile Model

Chapter 7
1.​ What is AI? What are the applications of AI
2.​ What is cloud computing? What are its components?
3.​ What is virtual reality? What are its advantages?
4.​ What is mobile computing? Write the advantages of using mobile computing.
5.​ What is IoT? Describe its applications. What are the challenges to implement
IoT?
6.​ What is e-commerce? Describe its types.
7.​ What is e-medicine? List out its advantages and disadvantages.
8.​ What is e-governance? List out its advantages and disadvantages.
9.​ What is the role of e-commerce to enhance the digital economy.
10.​ Define cloud computing. Explain its types along with its advantages and
disadvantages.
11.​ Explain Big Data. Also explain its advantages, disadvantages and application
areas.
12.​ Define social media. What are its advantages and disadvantages of social media.

7
8
9
Some Solved Problems
1.​ Write a PHP code to enter your name and display it.

<html>
<head>
<title>Your name </title>
</head>
<body>
<b>Enter Your Name</b> <br/>
<form method="POST">
<input type="text" name="name" /><br/>
<input type="submit" value="Submit"/> </form>
<?php
$name=$_POST['name'];
echo "Your Name=​$name";
?>
</body>
</html>

Result:

10
2.​ Write a PHP code to display the factorial of a number given by user.
<html>
<head>
<title>Factorial </title>
</head>
<body>
<b>Factorial Calculation Program</b>
<br/>
<form action="factorial.php" method="POST">
Input a Number:
<input type="Number" name="number" /><br/> <input
type="submit" value="Calculate"/> </form>
</body>
</html>

factorial.php
<?php
$n=$_POST['number'];
$fact=1;
for($i=1;$i<=$n;$i++)
{
$fact=$fact*$i;
}
echo "The factorial of​ $n = $fact";
?>

Result:

11
3.​ Write a PHP code to display all even numbers up to 50

<html>
<head>
<title>even numbers </title>
</head>
<body>
<b>Displaying Even Nymbers Up to 50</b> <br/>
<hr>
<?php
$a=2;
for($i=1;$i<=25;$i++)
{
echo"$a ,";
$a=$a+2;
}
?>
</body>
</html>
Result:

4.​ Write a PHP code to display the following patterns


*
**
***
****
*****

<html>
<head>
<title>Pattern </title>
</head>

12
<body>
<b>Displaying Pattern.. </b> <br/>
<?php
for($x=1;$x<=5;$x++)
{
for ($y=1;$y<=$x;$y++)
{
echo "* ";
}
echo "<br>";
}
?>
</body>
</html>
Result:

5.​ Write a PHP code to display the multiplication table of a number


<html>
<head>
<title>Multiplication Table </title>
</head>
<body>
<b>Multimpication Table from 1 to 5 </b> <br/> <table border="1"
cellpadding="3" cellspacing="0"> <?php
for($i=1;$i<=5;$i++)
{
echo "<tr>";
for ($j=1;$j<=10;$j++)

13
{
echo "<td>$i * $j = ".$i*$j."</td>";
}
echo "</tr>";
}
?>
</table>
</body>
</html>
Result:

Multiplication Table from 1 to 5


1*10=1
1*1=1 1*2=2 1*3=3 1*4=4
1*5=5 1*6=6 1*7=7 1*8=8 1*9=9 0
2*5=1 2*7=1 2*9=1 2*10=2
2*1=2 2*2=4 2*3=6 2*4=8 0 2*6=12 4 2*8=16 8 0
3*5=1 3*7=2 3*9=2 3*10=3
3*1=3 3*2=6 3*3=9 3*4=12 5 3*6=18 1 3*8=12 7 0
4*3=1 4*5=2 4*7=2 4*9=3 4*10=4
4*1=4 4*2=8 2 4*4=16 0 4*6=24 8 4*8=32 6 0
5*3=1 5*5=2 5*7=3 5*9=4 5*10=5
5*1=5 5*2=10 5 5*4=20 5 5*6=30 5 5*8=40 5 0

6.​ Write a PHP code to display the simple interest.


<html>
<head>
<title>Simple interest </title>
</head>
<body>
<b>Simple Interest Calculator</b> <br/>
<table border="1">
<tr><td>
<form name="SI" method="POST">
Input Princiaple:
<input type="Number" name="p" /><br/>
Input Rate:
<input type="Number" name="r" /><br/>
Input Time:
<input type="Number" name="t" /><br/> <input
type="submit" value="Calculate SI"/> </form>
<?php
$p=$_POST['p'];

14
$t=$_POST['t'];
$r=$_POST['r'];

$si=($p*$t*$r)/100;

echo "Simple Interest=​ $si";


?>
</td></tr>
</table>
</body>
</html>

Result:

15
16
Solved Problems

1.​ Program to write “Welcome to class 12” in a file.


#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp;

fp=fopen("class.txt","w");
fprintf(fp,"Welcome to Class 12");
printf("Data is written in a file");
fclose(fp);
getch();
}

17
#include<stdio.h>
#include<conio.h>
struct book
{
char book[25];
char writer[25];
int ISBN;
float price;
}b[100];
int main()
{
int n,i;
FILE *fp;
fp=fopen("book.txt","w");
printf("Enter how many books:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter Name of book: ");
scanf("%s",b[i].book);
printf("Enter ISBN Number: ");
scanf("%d",&b[i].ISBN);
printf("Enter Writer Name: ");
scanf("%s",b[i].writer);
printf("Enter Price of a book: ");
scanf("%f",&b[i].price);
fprintf(fp,"%d\t%s\t%s\t%f \n
",b[i].ISBN,b[i].book,b[i].writer,b[i].price);
}
printf("Information successfully stored\n"); fclose(fp);
//reading the content from a file
fp=fopen("book.txt","r");
printf("ISBN No \t Name of Book \t Writer \t Price \n");

while(fscanf(fp,"%d %s %s
%f",&b[i].ISBN,b[i].book,b[i].writer,&b[i].price)!=EOF)
{
printf("%d \t\t %s\t\t %s\t\t %f
\n",b[i].ISBN,b[i].book,b[i].writer,b[i].price);
}
fclose(fp);
getch();
}

18
Output:

#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp;
char bookName[25];
fp=fopen("book.txt", "a");
if(fp==NULL)
{
printf("File doesnot exist !");
}
else
{
printf("Enter a book name to append:");
scanf("%s",bookName);
fprintf(fp,"%s\n",bookName);
}
printf("Successfully appended");
fclose(fp);
getch();
}
Output:

/* Program to count number of characters, words and lines from a text file */
#include <stdio.h>
#include<conio.h>
#include <stdlib.h>
int main()
{
FILE * file;
​ char ch;
int characters,words,lines;
file = fopen("myfile.txt", "r"); //file myfile.txt must exist

if (file == NULL)
19
{
printf("\n Unable to open file ! \n"); printf("Please check if file
exists or not \n"); exit(EXIT_FAILURE);
}
/* count characters, words and lines */ characters =
words = lines = 0; while ((ch = fgetc(file)) != EOF)
{
characters++;
/* Check new line */
if (ch == '\n' || ch == '\0')
lines++;
/* Check words */
if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\0')
words++;
}
/* Increment words and lines for last word */
if (characters > 0)
{
words++;
lines++;
}
/* Display records​ */
printf("Total characters = %d\n", characters);
printf("Total words = %d\n", words);
printf("Total lines = %d\n", lines);
fclose(file);
return 0;
}
Output:

20
#include <stdio.h>
#include<conio.h>
int main()
{
char name[50];
int marks, i, num;
FILE *fptr;
fptr = fopen("student.txt", "w");
if(fptr==NULL)
{
printf("Error!");
}
printf("Enter number of students: ");
scanf("%d", &num);
for(i = 0; i < num; ++i)
{
printf("Student %d \n Enter name: ", i+1);
scanf("%s", name);
printf("Enter marks: ");
scanf("%d", &marks);
fprintf(fptr,"\n Name: %s \n Marks=%d \n", name, marks);
}
printf("Students Name and marks successfully written to a file..");
printf("\n Press any key to exit..");
fclose(fptr);
getch();
}
Output:

21
/* Program to rename a file using rename() function */
#include <stdio.h>
#include<conio.h>
int main()
{
char oldName[100], newName[100];
printf("Enter old file Name: ");
scanf("%s", oldName);
printf("Enter new file Name: ");
scanf("%s", newName);
//​ rename old file with new name if
(rename(oldName, newName) == 0)
{
printf("File renamed successfully.\n");
}
else
{
printf("Unable to rename files. Please check files exist
\n");
}
getch();
}

/* program to store odd and even numbers in a seperate files */


#include <stdio.h>
#include<conio.h>
int main()
{
int num[10],i;
FILE *fodd;
FILE *feven;

fodd=fopen("odd.txt","w");
feven=fopen("even.txt","w");
if(fodd==NULL||feven==NULL)
{

22
printf("Unable to open file !\n"); printf("Please check whether file
exists \n ");

}
for(i=0;i<10;i++)
{
printf("Enter a number %d:",i+1);
scanf("%d",&num[i]);
if(num[i]%2==0)
fprintf(fodd,"%d \t ",num[i]);
else
fprintf(feven,"%d \t ",num[i]);
}
printf("The numbers are successfully stored.");

getch();
}
Output:

/* program to append text in a file​ */


#include <stdio.h>
#include<conio.h>
int main()
{
char text[100];
FILE *fp;
fp=fopen("myfile.txt","a");
if(fp==NULL)
{
printf("Error!");

23
}
printf("Enter a text to append: ");
scanf("%[^\n]",text);
fprintf(fp," %s ",text);
printf("Text successfully appended..");
fclose(fp);
getch();
}

24
Solved Problems
1.​ Javascript program to print “Hello World”
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<!-- Script tag can also be placed here -->
</head>
<body>
​ <!-- Script tag inside the body -->
​ <script>
​ // write the javascript code inside it
​ document.write('Hello World');
​ </script>

</body>
</html>

2.​ Javascript program to add two numbers


<!Doctype html>
<html>
<head>
<script>
function add()
{
var num1, num2, sum;
num1 = parseInt(document.getElementById("firstnumber").value);
num2 = parseInt(document.getElementById("secondnumber").value);
sum = num1 + num2;
document.getElementById("answer").value = sum;
}
</script>
</head>
<body>
<p>First Number: <input id="firstnumber"></p>
<p>Second Number: <input id="secondnumber"></p>
<button onclick="add()">Add Them</button>
<p>Sum = <input id="answer"></p>
</body>
</html>

3.​ Javascript program to find area of triangle


<!Doctype html>
<html>
<head>
<script>
function area()
{
var num1, num2, area;
num1 = parseInt(document.getElementById("firstnumber").value);
num2 = parseInt(document.getElementById("secondnumber").value);
25
area = 1/2 * (num1 * num2);
document.getElementById("answer").value = area;
}
</script>
</head>
<body>
<p>First Number: <input id="firstnumber"></p>
<p>Second Number: <input id="secondnumber"></p>
<button onclick="area()">Find area</button>
<p>Area = <input id="answer"></p>
</body>
</html>

4.​ Javascript program to convert celsius to fahrenheit

<!doctype html>
<html>
<head>
<script>
function Celsius()
{
var celsius;
celsius = parseInt(document.getElementById("firstnumber").value);

fahrenheit = celsius * 1.8 + 32


document.getElementById("answer").value = fahrenheit;
}
</script>
</head>
<body>
<p>Enter celsius: <input id="firstnumber"></p>
<button onclick="Celsius()">Find fahrenheit</button>
<p>Area = <input id="answer"></p>
</body>
</html>

5.​ Javascript program to check if a number is positive, negative or equal to zero.


<!doctype html>
<html>
<head>
<script>
function positive_negative()
{

var num1;

num1 = parseInt(document.getElementById("firstnumber").value);
if(num1>0){
document.write("Positive");
26
}
else if( num1<0){
document.write("Negative");
}
else {
document.write("Equal to zero");
}
}
</script>
</head>
<body>
<p>Enter number: <input id="firstnumber"></p>
<button onclick="positive_negative()">Check</button>
</body>
</html>

6.​ Javascript program to check if a number is even or odd


<!doctype html>
<html>
<head>
<script>
function even_odd()
{

var num1;

num1 = parseInt(document.getElementById("firstnumber").value);
if(num1%2==0){
document.write("Even");
}
else {
document.write("Odd");
}
}
</script>
</head>
<body>
<p>Enter number: <input id="firstnumber"></p>
<button onclick="even_odd()">Check</button>
</body>
</html>

7.​ Javascript program to find the largest number among three numbers

27
<!doctype html>
<html>
<head>
<script>
function greater()
{

var num1,num2,num3;

num1 = parseInt(document.getElementById("firstnumber").value);
num2 = parseInt(document.getElementById("secondnumber").value);
num3 = parseInt(document.getElementById("thirdnumber").value);
if((num1>num2)&&(num1>num3)){
document.write("Num1 is greater");
}
else if((num2>num1)&&(num2>num3)) {
document.write("Num2 is greater");
}
else {
document.write("Num3 is greater");
}
}
</script>
</head>
<body>
<p>Enter First number: <input id="firstnumber"></p>
<p>Enter Second number: <input id="secondnumber"></p>
<p>Enter Third number: <input id="thirdnumber"></p>
<button onclick="greater()">Check</button>
</body>
</html>

8.​ Javascript program to find the factorial of a number


<!doctype html>
<html>
<head>
<script>
function factorial()
{

var num1,fact=1,i;

num1 = parseInt(document.getElementById("firstnumber").value);
//num2 = parseInt(document.getElementById("secondnumber").value);
//num3 = parseInt(document.getElementById("thirdnumber").value);
for(i=1;i<=num1;i++){
fact=fact*i;
}
document.write("Factorial= ",fact)
}
</script>
</head>
28
<body>
<p>Enter First number: <input id="firstnumber"></p>
<button onclick="factorial()">Check</button>
</body>
</html>

9.​ Javascript program to find sum of n natural numbers


<!doctype html>
<html>
<head>
<script>
function sum_of_natural_numbers()
{

var num1,sum=0,i;

num1 = parseInt(document.getElementById("firstnumber").value);
for(i=1;i<=num1;i++){
sum=sum+i;
}
document.write("Sum= ",sum)
}
</script>
</head>
<body>
<p>Enter First number: <input id="firstnumber"></p>
<button onclick="sum_of_natural_numbers()">Check</button>
</body>
</html>

10.​Javascript program to make a simple calculator


<!doctype html>
<html>
<head>
<script>
function calculate()
{

var num1,sum=0,i;

num1 = parseInt(document.getElementById("firstnumber").value);
num2 = parseInt(document.getElementById("secondnumber").value);
operator = document.getElementById("operator").value;
if (operator == '+') {
result = num1 + num2;
}
else if (operator == '-') {
result = num1 - num2;
}
else if (operator == '*') {
result = num1 * num2;
}
29
else {
result = num1 / num2;
}
// display the result
document.write("Result of "+num1+operator+num2+"="+result);
}
</script>
</head>
<body>
<p>Enter First number: <input id="firstnumber"></p>
<p>Enter Second number: <input id="secondnumber"></p>
<p>Enter Operator(+,-,*,/): <input id="operator"></p>
<button onclick="calculate()">Check</button>
<!--<p>Area = <input id="answer"></p>-->
</body>
</html>

30

You might also like