Wednesday, December 18, 2019

Python program to check if year is a leap year or not

# Python program to check if year is a leap year or not
#to check the year
#year = 2020

#To get year (integer input) from the user
year = int(input("Enter a year: "))

if (year % 4) == 0:
   if (year % 100) == 0:
       if (year % 400) == 0:
           print("{0} is a leap year".format(year))
       else:
           print("{0} is not a leap year".format(year))
   else:
       print("{0} is a leap year".format(year))
else:
   print("{0} is not a leap year".format(year))



Output:

Enter a year: 2020
2020
2020 is a leap year

Tuesday, December 17, 2019

The Countries of the World and their Capitals(general knowledge question)

List of countries of the World and their Capitals:

Confirmation Box - onClick in javascript program



Confirmation Box - onClick in javascript program:

<input id="confirm" type="button" value="Click me" onclick="confirm('Are you sure?');">



JavaScript program to print this page using onClick

Print this page on click in JavaScript program:

<input id="print" type="button" value="Print this Page" onclick="window.print();">



Javascript program to display alert box on click


Alert box on click in javascript program:

<input type="button" value="Click me" onclick="alert('Thanks for visiting my blog.....!');">


The multi threading concept in C++ with an example

The multi threading concept in C++ with an example:

#include
#include
using namespace std;
// function to be used in callable
void func_dummy(int N)
 {

  for (int i = 0; i < N; i++) {
  cout << "Thread 1 :: callable => function pointer\n";
   }

 }
 
// A callable object

class thread_obj {

 public:

   void operator()(int n) {

       for (int i = 0; i < n; i++)

           cout << "Thread 2 :: callable => function object\n";

   }

};

int main()
{
// Define a Lambda Expression
auto f = [](int n) {
   for (int i = 0; i < n; i++)
   cout << "Thread 3 :: callable => lambda expression\n";
   };
//launch thread using function pointer as callable
thread th1(func_dummy, 2);
// launch thread using function object as callable
thread th2(thread_obj(), 2);
//launch thread using lambda expression as callable
thread th3(f, 2);
// Wait for thread t1 to finish
 th1.join();
// Wait for thread t2 to finish
th2.join();
// Wait for thread t3 to finish
th3.join();
return 0;
}

Output:

Thread 1 :: callable => function pointer
Thread 1 :: callable => function pointer
Thread 3 :: callable => lambda expression
Thread 3 :: callable => lambda expression
Thread 2 :: callable => function object
Thread 2 :: callable => function object

Programming language : Ruby

Programming language : Ruby


Ruby is an interpreted, high-level, general-purpose programming language.

It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.
A dynamic, open source programming language with a focus on simplicity and productivity.
It has an elegant syntax that is natural to read and easy to write.


Platform support
Matsumoto originally did Ruby development on the 4.3BSD-based Sony NEWS-OS 3.x, but later migrated his work to SunOS 4.x, and finally to Linux.
Ruby versions and implementations are available on many operating systems, such as Linux, BSD, Solaris, AIX, macOS, Windows, Windows Phone,[104] Windows CE, Symbian OS, BeOS, and IBM i.

Features of Ruby:

1.Thoroughly object-oriented with inheritance, mixins and metaclasses
2.Dynamic typing and duck typing
3.Everything is an expression (even statements) and everything is executed imperatively (even declarations)
4.Succinct and flexible syntaxthat minimizes syntactic noise and serves as a foundation for domain-specific languages
5.Dynamic reflection and alteration of objects to facilitate metaprogramming
6.Lexical closures, iterators and generators, with a block syntax
7.Literal notation for arrays, hashes, regular expressions and symbols
8.Embedding code in strings (interpolation)
9.Default arguments
10.Four levels of variable scope (global, class, instance, and local) denoted by sigils or the lack thereof
11.Garbage collection
12.First-class continuations
13.Strict boolean coercion rules (everything is true except false and nil)
14.Exception handling
15.Operator overloading
16.Built-in support for rational numbers, complex numbers and arbitrary-precision arithmetic
17.Custom dispatch behavior (through method_missing and const_missing)
18.Native threads and cooperative fibers (fibers are a 1.9/YARV feature)
19.Support for Unicode and multiple character encodings.
20.Native plug-in API in C
21.Interactive Ruby Shell (a REPL)
22.Centralized package management through RubyGems
23.Implemented on all major platforms
24.Large standard library, including modules for YAML, JSON, XML, CGI, OpenSSL, HTTP, FTP, RSS, curses, zlib and Tk

Repositories and libraries:
RubyGems is Ruby's package manager. A Ruby package is called a "gem" and can easily be installed via the command line. Most gems are libraries, though a few exist that are applications, such as IDEs.
There are over 10,000 Ruby gems hosted on RubyGems.org.
Many new and existing Ruby libraries are hosted on GitHub, a service that offers version control repository hosting for Git.
The Ruby Application Archive, which hosted applications, documentation, and libraries for Ruby programming, was maintained until 2013, when its function was transferred to RubyGems.

Date and time java script program

<!DOCTYPE html>
<title>Time and Date</title>


<time id="msg"></time>

<script>
  document.getElementById("msg").innerHTML = new Date().toLocaleString();
</script>

JavaScript program to create a JavaScript object to show the current time

<!DOCTYPE html>
<title>Current time</title>

<time id="time"></time>
<script language="javascript">
  /*Create a JavaScript object for the current time,then extract the desired parts, then join them again in the desired format.*/

  var currentTime = new Date(),
      hours = currentTime.getHours(),
      minutes = currentTime.getMinutes();
 
 
  if (minutes < 10) {
    minutes  = "0" + minutes;
  }

 
var suffix = "AM";
if (hours >= 12) {
    suffix = "PM";
    hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}


  time = hours + ":" + minutes + " " + suffix;
     
  // Output
  document.getElementById("time").innerHTML = time;
</script>

JavaScript program for multiplication table

<html>
<head>
  <title>Multiplication Table</title>
  <script type="text/javascript">
    var rows = prompt("How many rows for your multiplication table?");
    var cols = prompt("How many columns for your multiplication table?");
    if(rows == "" || rows == null)
    rows = 10;
    if(cols== "" || cols== null)
    cols = 10;
    createTable(rows, cols);
    function createTable(rows, cols)
    {
      var j=1;
      var output = "<table border='1' width='500' cellspacing='0'cellpadding='5'>";
      for(i=1;i<=rows;i++)
      {
    output = output + "<tr>";
        while(j<=cols)
        {
    output = output + "<td>" + i*j + "</td>";
      j = j+1;
    }
    output = output + "</tr>";
    j = 1;
    }
    output = output + "</table>";
    document.write(output);
    }
  </script>
</head>
<body>
</body>
</html>

Featured posts

Mongolia

 Mongolia! Mongolia is a vast and sparsely populated country in East Asia, known for its stunning natural beauty, rich history, and unique c...

Popular posts