Like:-
1
232
45654
78910987
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script>
function f1() {
var num = (document.getElementById("txtNum").value).trim();
var regx = /^[0-9]*$/;
var chkNum = regx.test(num);
if (chkNum != true) {
alert("Enter Number only..");
}
var inc = 1, temp;
for (var i = 1; i <= num - 1; i++) {
for (var sp = 1; sp <= num - i; sp++) {
document.write(" ");
}
for (var j = 1; j <= i; j++) {
document.write(inc );
inc++;
}
temp = inc - 1;
for (var j = 1; j < i; j++) {
document.write(temp - j );
}
document.write("<br/>");
}
}
</script>
</head>
<body>
<input id="txtNum" type="text" />
<input id="Button" type="button" value="button" onclick="f1()"/>
<div id="div1">
</div>
</body>
</html>
1
232
45654
78910987
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script>
function f1() {
var num = (document.getElementById("txtNum").value).trim();
var regx = /^[0-9]*$/;
var chkNum = regx.test(num);
if (chkNum != true) {
alert("Enter Number only..");
}
var inc = 1, temp;
for (var i = 1; i <= num - 1; i++) {
for (var sp = 1; sp <= num - i; sp++) {
document.write(" ");
}
for (var j = 1; j <= i; j++) {
document.write(inc );
inc++;
}
temp = inc - 1;
for (var j = 1; j < i; j++) {
document.write(temp - j );
}
document.write("<br/>");
}
}
</script>
</head>
<body>
<input id="txtNum" type="text" />
<input id="Button" type="button" value="button" onclick="f1()"/>
<div id="div1">
</div>
</body>
</html>
No comments:
Post a Comment