<html> <head> <script> function min_num() { var f_num = parseInt(document.getElementById('f_txt').value); var s_num = parseInt(document.getElementById('s_txt').value); document.getElementById('r_txt').value = Math.min(f_num, s_num); } function max_num() { var f_num = parseInt(document.getElementById('f_txt').value); var s_num = parseInt(document.getElementById('s_txt').value); document.getElementById('r_txt').value = Math.max(f_num, s_num); } function divisible() { var f_num = parseInt(document.getElementById('f_txt').value); var s_num = parseInt(document.getElementById('s_txt').value); if (f_num % s_num == 0) document.getElementById('r_txt').value = "Divisible"; else document.getElementById('r_txt').value = "Not Divisible"; } function power()...
<html> <head> <script> function square(num) { var result = parseInt(num * num); document.write("Square of " + num + " is " + result); } </script> </head> <body> <script> var n = parseInt(prompt("Enter an integer")); square(n); </script> </body> </html> <html> <head> <script> function square(num) { var result = parseInt(num * num); document.write("Square of " + num + " is " + result); } </script>...
<html> <body> <script> var sum = 0; for (i = 0; i <= 8; i++) { if (i % 2 == 0) sum = parseInt(sum + i); } document.write("Sum of first five even numbers is " + sum); //It will only add first five even numbers independent of range of loop /*var sum = 0, count = 0; for (i = 0; i...
<html> <body> <script> var n1, n2, n3; n1 = parseInt(prompt("Enter the first number")); n2 = parseInt(prompt("Enter the second number")); n3 = parseInt(prompt("Enter the third number")); /* Using Conditional Operator (n1 > n2 && n1 > n3) ? document.write(n1 + " is greatest number") : (n2 > n3 && n2 > n1) ? document.write(n2 + " is greatest number") : document.write(n3 + " is...
<html> <body> <script> var dt = new Date(); var day = dt.getDate(); var month = dt.getMonth() + 1; //January is 0 var year = dt.getFullYear(); var hour = dt.getHours(); var minute = dt.getMinutes(); var second = dt.getSeconds(); if (month < 10) month = "0" + month; var new_date = day + "/" + month + "/" + year + " " + hour...
<html> <body> <script> var sum = 0, i = 1; while(i<=20) { sum = parseInt(sum + i); i++; } document.write("Sum of numbers between 1- 20 is " + sum); </script> </body> </html> <html> <body> <script> var sum = 0, i = 1; while(i<=20) { sum = parseInt(sum + i); i++; } document.write("Sum of numbers between 1- 20 is " + sum); </script> </body>...
<html> <head> <script> function armstrong(num) { var temp = parseInt(num); var sum = 0; var remainder; while (temp > 0) { remainder = parseInt(temp % 10); sum = parseInt(sum + remainder * remainder * remainder); temp = parseInt(temp / 10); } if (num == sum) document.write(num + "<br />"); } </script> </head> <body> <script> for (i = 1; i < 500; i++) {...
<html> <head> <script> function FindSmall(n1, n2, n3) { if (n1 < n2) smaller = n1; else smaller = n2; if(smaller < n3) smallest = smaller; else smallest = n3; document.write(smallest + " is smallest number"); } </script> </head> <body> <script> var num1, num2, num3; num1 = parseInt(prompt("Enter the first number")); num2 = parseInt(prompt("Enter the second number")); num3 = parseInt(prompt("Enter the third number")); FindSmall(num1,...
<html> <body> <script> var num = parseInt(prompt("Enter an integer")); if (num % 2 == 0) document.write(num + " is even number"); else document.write(num + " is odd number"); </script> </body> </html> <html> <body> <script> var num = parseInt(prompt("Enter an integer")); if (num % 2 == 0) document.write(num + " is even number"); else document.write(num + " is odd number"); </script> </body> </html> ...
<html> <body> <script> var num = parseInt(prompt("Enter a positive integer")); var flag = 0; for (i = 2; i <= num/2; i++) { if (num % i == 0) { flag = 1; break; } } if (num == 1) document.write(num + " is neither prime nor composite"); else if (flag == 0) document.write(num + " is prime number"); else document.write(num + "...
<html> <body> <script> function violet() { document.body.style.background = "violet" setTimeout("indigo()", 5000); } function indigo() { document.body.style.background = "indigo" setTimeout("blue()", 5000); } function blue() { document.body.style.background = "blue" setTimeout("green()", 5000); } function green() { document.body.style.background = "green" setTimeout("yellow()", 5000); } function yellow() { document.body.style.background = "yellow" setTimeout("orange()", 5000); } function orange() { document.body.style.background = "orange" setTimeout("red()", 5000); } function red() { document.body.style.background = "red"...
<html> <body> <script> var i; var friends = new Array; friends[0] = "Armash"; friends[1] = "Shuraim"; friends[2] = "Yuzzy"; friends[3] = "Zaki"; friends[4] = "Hasnain"; friends[5] = "Shahbaz"; for(i=0; i<6; i++) { if(i%2 == 0) document.write(friends[i] + "<br>"); } </script> </body> </html> <html> <body> <script> var i; var friends = new Array; friends[0] = "Armash"; friends[1] = "Shuraim"; friends[2] = "Yuzzy"; friends[3] =...
<html> <body> <script> var str, rev = "", length, i; str = prompt("Enter a String"); length = str.length; for(i = length-1; i >= 0; i--) { rev += str.charAt(i); } document.write(rev); </script> </body> </html> ...
/* Summary: Print rectangle pattern of stars. */ #include<stdio.h> int main() { int row, col, n, m; printf("Enter the number of rows: "); scanf("%d", &n); printf("Enter the number of columns: "); scanf("%d", &m); for(row=1; row<=n; row++) { for(col=1; col<=m; col++) printf("* "); printf("\n"); } return 0; } ...
/* Summary: Print filled square pattern of stars. */ #include<stdio.h> int main() { int row, col, n; printf("Enter the number of rows: "); scanf("%d", &n); for(row=1; row<=n; row++) { for(col=1; col<=n; col++) printf("* "); printf("\n"); } return 0; } ...
/* Summary: Print hollow rhombus pattern of stars. */ #include <stdio.h> int main() { int row, col, space, n; printf("Enter the number of rows: "); scanf("%d", &n); for(row=1;row<=n;row++) { for(col=1;col<=(n+1)-row;col++) printf("*"); for(space=1;space<row;space++) printf(" "); for(col=1;col<=(n+1)-row;col++) printf("*"); printf("\n"); } for(row=2;row<=n;row++) { for(col=1;col<=row;col++) printf("*"); for(space=1;space<=n-row;space++) printf(" "); for(col=1;col<=row;col++) printf("*"); printf("\n"); } return 0; } ...
/* Summary: Print filled rhombus pattern of stars. */ #include <stdio.h> int main() { int row, space, col, n; printf("Enter the number of rows: "); scanf("%d", &n); for(row=1;row<=n;row++) { for(space=row;space<n;space++) printf(" "); for(col=1;col<(row*2);col++) printf("*"); printf("\n"); } for(row=n-1;row>=1;row--) { for(space=n;space>row;space--) printf(" "); for(col=1;col<(row*2);col++) printf("*"); printf("\n"); } return 0; } ...
/* Summary: Print rhombus pattern of stars. */ #include<stdio.h> int main() { int row, col, n; printf("Enter the number of rows: "); scanf("%d", &n); for(row=1; row<=n; row++) { for(col=n; col>row; col--) printf(" "); printf("*"); for(col=1; col<(row-1)*2; col++) printf(" "); if(row==1) printf("\n"); else printf("*\n"); } for(row=n-1; row>=1; row--) { for(col=n; col>row; col--) printf(" "); printf("*"); for(col=1; col<(row-1)*2; col++) printf(" "); if(row==1) printf("\n"); else printf("*\n");...
/* Summary: Print rectangle pattern of stars. */ #include<stdio.h> int main() { int row, col, n, m; printf("Enter the number of rows: "); scanf("%d", &n); printf("Enter the number of columns: "); scanf("%d", &m); for(row=1; row<=n; row++) { for(col=1; col<=m; col++) { if(row==1 || row==n || col==1 || col==m) printf("* "); else printf(" "); } printf("\n"); } return 0; } ...