code-rag-bench/online-tutorials huggingface dataset:
Write your own memcpy() in C

Here we will see how to implement memcpy() function in C. The memcpy() function is used to copy a block of data from one location to another. The syntax of the memcpy() is like below −
void * memcpy(void * dest, const void * srd, size_t num);
To make our own memcpy, we have to typecast the given address to char*, then copy data from source to destination byte by byte. Just go through the following code to get better idea.
#include<stdio.h>
#include<string.h>
void custom_memcpy(void *dest, void *src, size_t n) {
   int i;
   //cast src and dest to char*
   char *src_char = (char *)src;
   char *dest_char = (char *)dest;
   for (i=0; i<n; i++)
      dest_char[i] = src_char[i]; //copy contents byte by byte
}
main() {
   char src[] = "Hello World";
   char dest[100];
   custom_memcpy(dest, src, strlen(src)+1);
   printf("The copied string is %s\n", dest);
   int arr[] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
   int n = sizeof(arr)/sizeof(arr[0]);
   int dest_arr[n], i;
   custom_memcpy(dest_arr, arr, sizeof(arr));
   printf("The copied array is ");
   for (i=0; i<n; i++)
      printf("%d ", dest_arr[i]);
}
The copied string is Hello World
The copied array is 10 20 30 40 50 60 70 80 90
How to call an interface method in Java?

In order to call an interface method from a java program, the program must instantiate the interface implementation program. A method can then be called using the implementation object.
public interface InterfaceDemo{
    default public void displayNameDefault(String name){
       System.out.println("Your name is : " + name);
   }
    public void displayName(String name);
    public void displayNameAndDesignation(String name, String designation);
}
The above interface defines three methods for displaying a name and optionally a job title. One method is a default method that contains implementation logic. The remaining two methods do not include implementation logic.
public class InterfaceDemoImpl implements InterfaceDemo{
    public void displayName(String name) {
         System.out.println(name);
    }  
      public void displayNameAndDesignation(String name, String designation) {
           System.out.println("Name:" + name + "\n"+ "Designation:" + designation);
     }
}
The above java program declares that it will implement the interface by using the implements keyword. The program is now obligated to provide java code for the two non-default methods. Accordingly, implementations of the methods are provided.
public class CallInterfaceMethod {
     public static void main(String args[]){
         InterfaceDemo demo = new InterfaceDemoImpl();
         demo.displayName("Adithya");
         demo.displayNameAndDesignation("Adithya", "Java Developer");
         demo.displayNameDefault("Adithya");
      }
}
The above program instantiates the interface implementation. Next, each of the methods defined in the interface is called.
Adithya
Name:Adithya
Designation:Java Developer
Your name is : Adithya
H2 Database - Delete

The SQL DELETE query is used to delete the existing records from a table. We can use WHERE clause with DELETE query to delete selected records, otherwise all the records will be deleted.
Following is the generic query syntax of the delete command.
DELETE [ TOP term ] FROM tableName [ WHERE expression ] [ LIMIT term ]

The above syntax deletes the rows from a table. If TOP or LIMIT is specified, at most the specified number of rows are deleted (no limit if null or smaller than zero).
Consider the CUSTOMER table having the following records.
+----+----------+-----+-----------+----------+ 
| ID | NAME     | AGE | ADDRESS   | SALARY   | 
+----+----------+-----+-----------+----------+ 
|  1 | Ramesh   |  32 | Ahmedabad |  2000.00 | 
|  2 | Khilan   |  25 | Delhi     |  1500.00 | 
|  3 | kaushik  |  23 | Kota      |  2000.00 | 
|  4 | Chaitali |  25 | Mumbai    |  6500.00 | 
|  5 | Hardik   |  27 | Bhopal    |  8500.00 | 
|  6 | Komal    |  22 | MP        |  4500.00 | 
|  7 | Muffy    |  24 | Indore    | 10000.00 | 
+----+----------+-----+-----------+----------+

The following command will delete the details of the customer, whose ID is 6.
DELETE FROM CUSTOMERS WHERE ID = 6;

After execution of the above command, check the Customer table by executing the following command.
SELECT * FROM CUSTOMERS; 
The above command produces the following output −
+----+----------+-----+-----------+----------+ 
| ID | NAME     | AGE | ADDRESS   | SALARY   | 
+----+----------+-----+-----------+----------+ 
|  1 | Ramesh   |  32 | Ahmedabad |  2000.00 | 
|  2 | Khilan   |  25 | Delhi     |  1500.00 | 
|  3 | kaushik  |  23 | Kota      |  2000.00 | 
|  4 | Chaitali |  25 | Mumbai    |  6500.00 | 
|  5 | Hardik   |  27 | Bhopal    |  8500.00 | 
|  7 | Muffy    |  24 | Indore    | 10000.00 | 
+----+----------+-----+-----------+----------+ 

If we want to DELETE all the records from CUSTOMERS table, we do not use WHERE clause. The DELETE query would be as follows.
DELETE FROM CUSTOMER; 

After executing the above command, no records will be available in the Customer table.

    14 Lectures 
     1 hours 

 Mahesh Kumar

    100 Lectures 
     9.5 hours 

 Hari Om Singh

    108 Lectures 
     8 hours 

 Pavan Lalwani

    10 Lectures 
     1 hours 

 Deepti Trivedi

    20 Lectures 
     2 hours 

 Deepti Trivedi

    14 Lectures 
     1 hours 

 Deepti Trivedi
 Print
 Add Notes
 Bookmark this page
C++ Program to Implement Gauss Jordan Elimination

This is a C++ Program to Implement Gauss Jordan Elimination. It is used to analyze linear system of simultaneous equations. It is mainly focused on reducing the system of equations to a diagonal matrix form by row operations such that the solution is obtained directly.
Begin
   n = size of the input matrix
   To find the elements of the diagonal matrix:
   Make nested for loops j = 0 to n and i = 0 to n
      The element in the first row and the first column is made 1
      and then the remaining elements in the first column are made 0.
      Similarly, the elements in the second row and the second
      column is made 1, and then the other elements in the second
      column are reduced to 0 and so on.
   Print all calculated solution values.
End
#include<iostream>
using namespace std;
int main() {
   int i,j,k,n; // declare variables and matrixes as
   input
   float a[10][10],b,x[10];
   printf("\nEnter the size of matrix: ");
   scanf("%d",&n);
   printf("\nEnter the elements of augmented matrix (rowwise):\ n");
   for(i=1; i<=n; i++) {
      for(j=1; j<=(n+1); j++) {
         cout << "A[" << i << ", " << j << " ]=";
         cin >> a[i][j];
      }
   }
   //to find the elements of diagonal matrix
   for(j=1; j<=n; j++) {
      for(i=1; i<=n; i++) {
         if(i!=j) {
            b=a[i][j]/a[j][j];
            for(k=1; k<=n+1; k++) { 
               a[i][k]=a[i][k]-b*a[j][k];
            }
         }
      }
   }
   cout<<"\nThe solution is:\n";
   for(i=1; i<=n; i++) {
      x[i]=a[i][n+1]/a[i][i];
      cout<<"x"<<i << "="<<x[i]<<" ";
   }
   return(0);
}
Enter the size of matrix: 3
Enter the elements of augmented matrix row-wise:
A[1, 1 ]=1
A[1, 2 ]=2
A[1, 3 ]=-4
A[1, 4 ]=2
A[2, 1 ]=7
A[2, 2 ]=6
A[2, 3 ]=-2
A[2, 4 ]=-5
A[3, 1 ]=0
A[3, 2 ]=-3
A[3, 3 ]=-5
A[3, 4 ]=-8
The solution is:
x1=-2.89831 x2=2.5678 x3=0.059322
How to attach a Scrollbar to a Text widget in Tkinter?

Tkinter Text widget is used to accept multiline user Input. It is similar to Entry Widget but the only difference is that Text widget supports multiple line texts. In order to create a Text widget, we have to instantiate a text object.
Adding multiple texts will require to add the ScrollBar. In order to add a scrollbar in the text widget, we can call the ScrolledText(root) function. This function generally creates a text field with a scrollbar.
The ScrolledText(root) function resides in Tkinter ScrolledText Module. We can import it using the following command,
from tkinter.scrolledtext import ScrolledText
In this example, we will create a Text widget and then add a scrollbar to it.
#Import the library
from tkinter import *
from tkinter.scrolledtext import ScrolledText

#Create an object of tkinter window or frame
win = Tk()

#Define the geometry of window
win.geometry("650x250")

#Create an instance of Text Widget
ScrolledText(win).pack()

win.mainloop()
Running the above code will display a window with a text widget that supports multiline user Input and a native scrollbar.
How to create a date spinner in Java?

To create a date spinner, use the SpinnerDateModel class. Within that set the date format −
Date today = new Date();
JSpinner spinner2 = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH));
JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner2, "dd/MM/yy");
spinner2.setEditor(editor);
Above, we have set the Date format to be −
dd/MM/yy
The following is an example to create a date spinner in Java −
package my;
import java.awt.GridBagLayout;
import java.util.Calendar;
import java.util.Date;
import javax.swing.*;
public class SwingDemo {
   public static void main(String[] args) {
      JFrame frame = new JFrame("Spinner Demo");
      JPanel panel = new JPanel();
      JLabel label = new JLabel("Exam No.");
      JLabel label2 = new JLabel(" Appeared On");
      panel.setLayout(new GridBagLayout());
      int min = 0;
      int max = 10;
      int step = 1;
      int i = 5;
      SpinnerModel value = new SpinnerNumberModel(i, min, max, step);
      JSpinner spinner = new JSpinner(value);
      spinner.setBounds(50, 80, 70, 100);
      Date today = new Date();
      JSpinner spinner2 = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH));
      JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner2, "dd/MM/yy");
      spinner2.setEditor(editor);
      panel.add(label);
      panel.add(spinner);
      panel.add(label2);
      panel.add(spinner2);
      frame.add(panel);
      frame.setSize(550,300);
      frame.setVisible(true);
   }
}
Console.SetWindowSize() Method in C# - GeeksforGeeks

20 Feb, 2019
Console.SetWindowSize(Int32, Int32) Method is used to change the height and width of the console window to the specified values.
Syntax: public static void SetWindowSize (int width, int height);
Parameters:width: The width of the console window measured in columns.height: The height of the console window measured in rows.
Exceptions:
ArgumentOutOfRangeException:If the width or height is less than or equal to zerowidth plus WindowLeft or height plus WindowTop is greater than or equal to MaxValuewidth or height is greater than the largest possible window width or height for the current screen resolution and console font.
If the width or height is less than or equal to zero
width plus WindowLeft or height plus WindowTop is greater than or equal to MaxValue
width or height is greater than the largest possible window width or height for the current screen resolution and console font.
IOException: If an I/O error occured.
Example 1: Getting the current dimensions of the window.
// C# program to get the current// window width and Heightusing System;  namespace GFG {  class Program {      static void Main(string[] args)    {        Console.WriteLine(Console.WindowWidth);        Console.WriteLine(Console.WindowHeight);    }}}
Output:
Example 2: Setting the value of SetWindowSize
// C# program to illustrate the// Console.SetWindowSize Propertyusing System;  namespace GFG {  class Program {      static void Main(string[] args)    {        // Passed 40, 40 to SetWindowSize to         // change window size to 40 by 40        Console.SetWindowSize(40, 40);.          // Printing the current dimensions        Console.WriteLine(Console.WindowWidth);        Console.WriteLine(Console.WindowHeight);    }}}
Output:
Note: See the Horizontal Scroll Bar at the bottom of the Window in both the images.
Reference:
https://docs.microsoft.com/en-us/dotnet/api/system.console.setwindowsize?view=netframework-4.7.2
CSharp-Console-Class
CSharp-method
Picked
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C# | Delegates
C# | Method Overriding
C# | Abstract Classes
Extension Method in C#
C# | Replace() Method
Difference between Ref and Out keywords in C#
C# | Class and Object
C# | String.IndexOf( ) Method | Set - 1
C# | Constructors
Introduction to .NET Framework
How to get all combinations of some arrays in JavaScript?

You can use your own function to get all combinations.
Following is the code −
function combination(values) {
   function * combinationRepeat(size, v) {
      if (size)
         for (var chr of values)
      yield * combinationRepeat(size - 1, v + chr);
      else yield v;
   }
   return [...combinationRepeat(values.length, "")];
}
var output = combination([4,5]);
console.log(output);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo306.js.
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo306.js
[ '44', '45', '54', '55' ]
seq command in Linux with Examples

06 Jul, 2021
seq command in Linux is used to generate numbers from FIRST to LAST in steps of INCREMENT. It is a very useful command where we had to generate list of numbers in while, for, until loop. 
Syntax:  
seq [OPTION]... LAST
  or
seq [OPTION]... FIRST LAST
  or
seq [OPTION]... FIRST INCREMENT LAST
Options:  
seq LAST: When only one argument is given then it produces numbers from 1 to LAST in step increment of 1. If the LAST is less than 1, then is produces no output. 
seq FIRST LAST: When two arguments are given then it produces numbers from FIRST till LAST is step increment of 1. If LAST is less than FIRST, then it produces no output.  
seq FIRST INCREMENT LAST: When three arguments are given then it produces numbers from FIRST till LAST in step of INCREMENT. If LAST is less than FIRST, then it produces no output.  
seq -f “FORMAT” FIRST INCREMENT LAST: This command is used to generate sequence in a formatted manner. FIRST and INCREMENT are optional. 
seq -s “STRING” FIRST INCREMENT LAST: This command is uses to STRING to separate numbers. By default this value is equal to “\n”. FIRST and INCREMENT are optional. 
seq -w FIRST INCREMENT LAST: This command is used to equalize width by padding with leading zeroes. FIRST and INCREMENT are optional. 
seq –help: It displays help information. 
seq –version: It displays version information. 
 
 
sagar0719kumar
sumitgumber28
linux-command
Linux-misc-commands
Linux-Unix
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to underline a text content using HTML ?

09 Feb, 2021
In this article, we will create an underline text by using the <u> tag in the document. It stands for underline and it is used to underline the text enclosed within the <u> tag. This tag is generally used to underline misspelled words. This tag requires a starting as well as ending tag. Syntax:  
<u> Contents... </u>
Example 1: This example uses <u> tag to create an underline text.
html
<!DOCTYPE html><html> <head>    <title>        How to underline a text        content using HTML?    </title>     <style>        body {            text-align: center;        }         .gfg {            font-size: 40px;            font-weight: bold;            color: green;        }         .geeks {            font-size: 25px;            font-weight: bold;        }         p {            font-size: 20px;        }    </style></head> <body>    <div class="gfg">        GeeksforGeeks    </div>     <div class="geeks">        HTML5: How to underline a text        in an HTML document          <p>            GeeksforGeeks: A <u>computer            science</u> portal for geeks        </p> </body> </html>
Output:
Example 2: This example is an alternate way of <u> tag to underline the text. In this example, we will use CSS text-decoration property to underline the text content.
html
<!DOCTYPE html><html> <head>    <title>        How to underline a text        content using HTML?    </title>     <style>        body {            text-align: center;        }         .gfg {            font-size: 40px;            font-weight: bold;            color: green;        }         .geeks {            font-size: 25px;            font-weight: bold;        }         p {            font-size: 20px;        }         span {            text-decoration: underline;        }    </style></head> <body>    <div class="gfg">        GeeksforGeeks    </div>     <div class="geeks">        HTML5: How to underline a        text in an HTML document          <p>            GeeksforGeeks: A <span>            computer science</span>            portal for geeks        </p> </body> </html>
Output:
Supported browsers:
Google Chrome
Internet Explorer
Firefox
Opera
Safari
AshokJaiswal
CSS-Misc
HTML-Misc
CSS
HTML
Web Technologies
Web technologies Questions
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Powershell - For Loop

The following scripts demonstrates the for loop.
> $array = @("item1", "item2", "item3")
 
> for($i = 0; $i -lt $array.length; $i++){ $array[$i] }
How to remove unused dependencies from composer?

27 Jan, 2021
Removing unused Dependencies from Composer is very easy. Following are the two approaches:
1. Using Composer Remove:This is the simplest command to remove unused Dependencies from Composer. 
Syntax:
composer remove dependency_name
Firstly decide which dependency you want to remove from the composer. Here we will be removing stripe/stripe-php dependency as shown below in the composer and the stripe folder is also present in the directory.
Dependencies in the composer.
Stripe folder is present before deleting.
Now just go to the directory in which your composer.json file is there and then type the below command:
composer remove stripe/stripe-php
composer remove stripe/stripe-php Command
Output: This command removed the stripe/stripe-php dependency from the composer as shown below:
Stripe folder removed after the command.
Thus, the composer remove is a very easy command and will remove the unused dependencies from the composer.
2. Using Composer Update:It’s another way of removing unused Dependencies from Composer. 
Syntax:
composer update 
Running composer update Command. 
The above command will update the complete directory and will add all the dependencies and folders shown below:
All the Folders Added and Updated.
Now just open the composer.json file and delete the dependency which you want to remove.
composer.json File Contents
Now just delete the phpunit/phpunit:4.6.1 dependency and the updated composer.json is shown below:
composer.json File after Deletion
Now we just need to run the composer update command once more and it will remove all the phpunit dependencies which we don’t want as shown below:
Running composer update once again.
Dependencies Removed 
“composer update” will do the task, but it will also update the other packages.
Now if you just want to remove a specific package without updating others then just specify that package name.
composer update packageauthor/package_name
It will remove the “package_name” package.
Picked
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to set column in center using Bootstrap 5?

05 Nov, 2021
The goal here is to center a column in bootstrap. Bootstrap is a free and open-source CSS framework directed at responsive, mobile-first front-end web development. There are two approaches to centering a column <div> in Bootstrap.
Approach 1 (offsets):  
The first approach uses bootstrap offset class. The key is to set an offset equal to half of the remaining size of the row. So for example, a column of size 2 would be centered by adding an offset of 5, that’s (12-2)/2. The below example implements this.
 
html
<!DOCTYPE html><html>    <link rel="stylesheet"          href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"           integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"           crossorigin="anonymous" />    <body>        <div class="container">            <div class="row">                <div style="height: 200px;"                      class="col-md-6 offset-md-3                            text-center bg-success">.                  col-md-6 .offset-md-3</div>            </div>        </div>    </body></html>
Output
Approach 2(Margin auto):  
Setting left and right margins to auto will center the div with respect to its parent element. The left and right margin can be set with .ml-auto and .mr-auto class respectively. The below example implements this.
 
html
<!DOCTYPE html><html>    <link rel="stylesheet"           href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"          integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"           crossorigin="anonymous" />    <body>        <div class="container">            <div class="row">                <div style="height: 200px;"                      class="mr-auto ml-auto                             text-center bg-success">                  .ml-auto .mr-auto</div>            </div>        </div>    </body></html>
Output
ysachin2314
chhabradhanvi
Bootstrap-Misc
Bootstrap
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Show Images on Click using HTML ?
How to Use Bootstrap with React?
How to set Bootstrap Timepicker using datetimepicker library ?
How to Add Image into Dropdown List for each items ?
How to change the background color of the active nav-item?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Installation of Node.js on Linux
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?
Node in Apache Cassandra

15 Jul, 2020
In this article, we are going to discuss what is a node in Cassandra, information of node, how we can access the information about the node, and by using Nodetool utility we will also discuss some nodetool commands. let’s discuss one by one.
Node :
A node in Cassandra contains the actual data and it’s information such that location, data center information, etc.
A node contains the data such that keyspaces, tables, the schema of data, etc.
you can perform operations such that read, write, delete data, etc. on a node.
A node plays an important role in Cassandra clusters.
In Cassandra ring where every node is connected peer to peer and every node is similar to every other node in the cluster.
Let’s consider an example where you have three replicas of data and each replica on different nodes. now, if you want to read data then anyone node can respond that’s why the concept of distributed data across the cluster is so effective and high availability mechanism in Cassandra.
Nodetool :
It is the node management utility tool by which you can get the node health information, node information, cluster information, etc.
with the help of nodetool commands, you can access all the required information of the nodes.
Nodetool commands such that help, info, the status will give you the general information about the node.
It’s by default located in the bin/ folder where Cassandra is installed.
Some basics Nodetool commands :
Example –
nodetool status

let’s consider an example if a user wants to know the status of the node, then nodetool status commands need to be executed. In given below output is showing node is in the UN (Up and Normal) state and the address of a default node is 127.0.0.1 and also about load and rack information, etc.
 C:\Program Files\apache-cassandra-3.11.4\bin>nodetool status
Datacenter: datacenter1
========================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens       Owns    Host ID                               Rack
UN  127.0.0.1  322.11 KiB  256          ?       83ae1bed-37b7-46c0-a166-2a774e147205  rack1 
Apache
NoSQL
DBMS
DBMS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Types of Functional dependencies in DBMS
What is Temporary Table in SQL?
MySQL | Regular expressions (Regexp)
Difference between OLAP and OLTP in DBMS
Difference between Where and Having Clause in SQL
SQL | DDL, DML, TCL and DCL
Introduction of Relational Algebra in DBMS
Relational Model in DBMS
Difference between Star Schema and Snowflake Schema
KDD Process in Data Mining
GATE | GATE-CS-2014-(Set-3) | Question 65

28 Jun, 2021
Consider the transactions T1, T2, and T3 and the schedules S1 and S2 given below.
T1: r1(X); r1(Z); w1(X); w1(Z)
T2: r2(Y); r2(Z); w2(Z)
T3: r3(Y); r3(X); w3(Y)
S1: r1(X); r3(Y); r3(X); r2(Y); r2(Z);
    w3(Y); w2(Z); r1(Z); w1(X); w1(Z)
S2: r1(X); r3(Y); r2(Y); r3(X); r1(Z);
    r2(Z); w3(Y); w1(X); w2(Z); w1(Z) 
Which one of the following statements about the schedules is TRUE?(A) Only S1 is conflict-serializable.(B) Only S2 is conflict-serializable.(C) Both S1 and S2 are conflict-serializable.(D) Neither S1 nor S2 is conflict-serializable.Answer: (A)Explanation: For conflict serializability of a schedule( which gives same effect as a serial schedule ) we should check for conflict operations, which are Read-Write, Write-Read and Write-Write between each pair of transactions, and based on those conflicts we make a precedence graph, if the graph contains a cycle, it’s not a conflict serializable schedule.
To make a precedence graph: if Read(X) in Ti followed by Write(X) in Tj ( hence a conflict ), then we draw an edge from Ti to Tj ( Ti -> Tj)
If we make a precedence graph for S1 and S2 , we would get directed edges for S1 as T2->T1, T2->T3, T3->T1, and for S2 as T2->T1, T2->T3, T3->T1, T1->T2. In S1 there is no cycle, but S2 has a cycle. Hence only S1 is conflict serializable.
Note : The serial order for S1 is T2 -> T3 -> T1.Quiz of this Question
GATE-CS-2014-(Set-3)
GATE-GATE-CS-2014-(Set-3)
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | GATE-CS-2014-(Set-2) | Question 65
GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 33
GATE | GATE-CS-2014-(Set-3) | Question 20
GATE | GATE CS 2008 | Question 46
GATE | GATE-CS-2015 (Set 3) | Question 65
GATE | GATE-CS-2014-(Set-1) | Question 51
GATE | GATE-CS-2014-(Set-3) | Question 65
GATE | GATE CS 1996 | Question 63
GATE | GATE-CS-2015 (Set 2) | Question 55
GATE | GATE CS 2008 | Question 40
Python math function | modf()

11 Jan, 2018
modf() function is an inbuilt function in Python that returns the fractional and integer parts of the number in a two-item tuple. Both parts have the same sign as the number. The integer part is returned as a float.
Syntax :
modf(number) 
Parameter :
There is only one mandatory parameter which is the number. 
Returns :This method returns the fractional and integer parts of number in a two-item tuple. Both parts have the same sign as the number. The integer part is returned as a float.
Exception :
TypeError:  If anything other then a float number is passed, it returns a type error. 
Below is the Python3 implementation of modf() method :
Code #1
# Python3 program to demonstrate the function modf()  # This will import math moduleimport math     # modf() function used with a positive numberprint("math.modf(100.12) : ", math.modf(100.12))  # modf() function used with a negative numberprint("math.modf(-100.72) : ", math.modf(-100.72))   print("math.modf(2) : ", math.modf(2)) 
Output :
math.modf(100.12) :  (0.12000000000000455, 100.0)
math.modf(-100.72) :  (-0.7199999999999989, -100.0)
math.modf(2) :  (0.0, 2.0)

 
Code #2 : TypeError
# Python3 program to demonstrate the  # error in function modf()  # This will import math moduleimport math     # modf() function used with a positive numberprint("math.modf(100.12) : ", math.modf("100.12"))
Output :
Traceback (most recent call last):
  File "/home/fa6d7643de17bafe9a0e0693458e4bdb.py", line 9, in 
    print("math.modf(100.12) : ", math.modf("100.12"))
TypeError: a float is required

 Code #3 :
# Python3 program to demonstrate the # error in function modf()  # This will import math modulefrom math import modf  lst = [3.12, -5.14, 13.25, -5.21]tpl = (33.12, -15.25, 3.15, -31.2)    # modf() function on elements of listprint("modf() on First list element : ", modf(lst[0]))print("modf() on third list element : ", modf(lst[2]))  # modf() function on elements of tupleprint("modf() on Second tuple element : ", modf(tpl[1]))print("modf() on Fourth tuple element : ", modf(tpl[3]))
Output :
modf() on First list element :  (0.1200000000000001, 3.0)
modf() on third list element :  (0.25, 13.0)
modf() on Second tuple element :  (-0.25, -15.0)
modf() on Fourth tuple element :  (-0.1999999999999993, -31.0)

Practical Application :Given two float numbers, multiply the fractional part and return the answer.
Code #4 :
# Python3 program to demonstrate the # application of function modf()  # This will import math moduleimport math     # modf() function to multiply fractional part a = math.modf(11.2) b = math.modf(12.3)  # Multiply the fractional part as is stored  # in 0th index of both the tupleprint(a[0]*b[0])
Output :
0.05999999999999993

Python-Built-in-functions
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Iterate over a list in Python
Python Classes and Objects
Convert integer to string in Python
turtle.onclick() function in Python

26 Jul, 2020
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support.
This function is used to bind fun to a mouse-click event on this turtle or on canvas. 
Syntax :
turtle.onclick(fun, btn=1, add=None)

Parameters:
Below is the implementation of the above method with some examples :
Example 1 :
Python3
# import packageimport turtle    # method to actiondef fxn(x,y):          # some motion    turtle.right(90)    turtle.forward(100)  # turtle speed to slowestturtle.speed(1)  # motionturtle.fd(100)  # allow user to click # for some actionturtle.onclick(fxn)
Output :
Example 2 :
Python3
# import packageimport turtle    # screen objectwn = turtle.Screen()  # method to perform actiondef fxn(x, y):  turtle.goto(x, y)  turtle.write(str(x)+","+str(y))  # onclick action wn.onclick(fxn)wn.mainloop()
Output :
Python-turtle
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Iterate over a list in Python
Convert integer to string in Python
Python | os.path.basename() method

12 Oct, 2021
OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python used for common path name manipulation.os.path.basename() method in Python is used to get the base name in specified path. This method internally use os.path.split() method to split the specified path into a pair (head, tail). os.path.basename() method returns the tail part after splitting the specified path into (head, tail) pair.  
Syntax: os.path.basename(path)Parameter: path: A path-like object representing a file system path. Return Type: This method returns a string value which represents the base name the specified path.  
Code: Use of os.path.basename() method  
Python3
# Python program to explain os.path.basename() method   # importing os.path moduleimport os.path # Pathpath = '/home/User/Documents'  # Above specified path# will be splitted into# (head, tail) pair as# ('/home/User', 'Documents') # Get the base name # of the specified pathbasename = os.path.basename(path) # Print the base name print(basename)  # Pathpath = '/home/User/Documents/file.txt' # Above specified path# will be splitted into# (head, tail) pair as# ('/home/User/Documents', 'file.txt') # Get the base name # of the specified pathbasename = os.path.basename(path) # Print the basename name print(basename)  # Pathpath = 'file.txt'  # The above specified path# will be splitted into# head and tail pair# as ('', 'file.txt')# so 'file.txt' will be printed # Get the base name # of the specified pathbasename = os.path.basename(path) # Print the base name print(basename)
Documents
file.txt
file.txt
 
Reference: https://docs.python.org/3/library/os.path.html 
sooda367
Python OS-path-module
python-os-module
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Iterate over a list in Python
Python OOPs Concepts
Python Program for Heap Sort

06 Jul, 2022
Heapsort is a comparison based sorting technique based on a Binary Heap data structure. It is similar to selection sort where we first find the maximum element and place the maximum element at the end. We repeat the same process for the remaining element.
Python
# Python program for implementation of heap Sort   # To heapify subtree rooted at index i. # n is size of heap def heapify(arr, n, i):  largest = i # Initialize largest as root  l = 2 * i + 1  # left = 2*i + 1  r = 2 * i + 2  # right = 2*i + 2    # See if left child of root exists and is  # greater than root  if l < n and arr[i] < arr[l]:   largest = l    # See if right child of root exists and is  # greater than root  if r < n and arr[largest] < arr[r]:   largest = r    # Change root, if needed  if largest != i:   arr[i],arr[largest] = arr[largest],arr[i] # swap     # Heapify the root.   heapify(arr, n, largest)   # The main function to sort an array of given size def heapSort(arr):  n = len(arr)    # Build a maxheap.  # Since last parent will be at ((n//2)-1) we can start at that location.  for i in range(n // 2 - 1, -1, -1):   heapify(arr, n, i)    # One by one extract elements  for i in range(n-1, 0, -1):   arr[i], arr[0] = arr[0], arr[i] # swap   heapify(arr, i, 0)   # Driver code to test above arr = [ 12, 11, 13, 5, 6, 7] heapSort(arr) n = len(arr) print ("Sorted array is") for i in range(n):  print ("%d" %arr[i]), # This code is contributed by Mohit Kumra 
Sorted array is
5 6 7 11 12 13

Time Complexity: O(n*log(n))
Time complexity of heapify is O(log(n)).
Time complexity of createAndBuildHeap() is O(n).
And, hence the overall time complexity of Heap Sort is O(n*log(n)).
Auxiliary Space: O(logn)
Please refer complete article on Heap Sort for more details!
jroberto
amankr0211
hardikkoriintern
Heap Sort
python sorting-exercises
Python-Data-Structures
Heap
Python Programs
Sorting
Sorting
Heap
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
What is the difference between virtual and abstract functions in C#?

Abstract methods do not provide an implementation and they force the derived classes to override the method. It is declared under abstract class. An abstract method only has the method definition
Virtual methods have an implementation, unlike the Abstract method and it can exist in the abstract and non-abstract class. It provides the derived classes with the option of overriding it.
The virtual keyword is useful in modifying a method, property, indexer, or event. When you have a function defined in a class that you want to be implemented in an inherited class(es), you use virtual functions. The virtual functions could be implemented differently in different inherited class and the call to these functions will be decided at runtime.
The following is a virtual function −
public virtual int area() { }
Here is an example showing how to work with virtual functions −
 Live Demo
using System;

namespace PolymorphismApplication {
   class Shape {
      protected int width, height;
      public Shape( int a = 0, int b = 0) {
         width = a;
         height = b;
      }
      public virtual int area() {
         Console.WriteLine("Parent class area :");
         return 0;
      }
   }
   class Rectangle: Shape {
      public Rectangle( int a = 0, int b = 0): base(a, b) {
      }
      public override int area () {
         Console.WriteLine("Rectangle class area ");
         return (width * height);
      }
   }
   class Triangle: Shape {
      public Triangle(int a = 0, int b = 0): base(a, b) {
      }
      public override int area() {
         Console.WriteLine("Triangle class area:");
         return (width * height / 2);
      }
   }
   class Caller {
      public void CallArea(Shape sh) {
         int a;
         a = sh.area();
         Console.WriteLine("Area: {0}", a);
      }
   }
   class Tester {
      static void Main(string[] args) {
         Caller c = new Caller();
         Rectangle r = new Rectangle(10, 7);
         Triangle t = new Triangle(10, 5);

         c.CallArea(r);
         c.CallArea(t);
         Console.ReadKey();
      }
   }
}
Rectangle class area
Area: 70
Triangle class area:
Area: 25
The abstract keyword in C# is used for abstract classes and abstract functions. An abstract class in C# includes abstract and non-abstract methods.
The following is an example of abstract functions in an abstract class in C# −
 Live Demo
using System;
public abstract class Vehicle {
   public abstract void display();
}
public class Bus : Vehicle {
   public override void display() {
      Console.WriteLine("Bus");
   }
}
public class Car : Vehicle {
   public override void display() {
      Console.WriteLine("Car");
   }
}
public class Motorcycle : Vehicle {
   public override void display() {
      Console.WriteLine("Motorcycle");
   }
}
public class MyClass {
   public static void Main() {
      Vehicle v;
      v = new Bus();
      v.display();
      v = new Car();
      v.display();
         v = new Motorcycle();
      v.display();
   }
}
Bus
Car
Motorcycle
Alternate element summation in list (Python)

Given a list of numbers in this article we are going to calculate the sum of alternate elements in that list.
Every second number and also use the range function along with length function to get the number of elements to be summed.
 Live Demo
listA = [13,65,78,13,12,13,65]
# printing original list
print("Given list : " , str(listA))
# With list slicing
res = [sum(listA[i:: 2])
for i in range(len(listA) // (len(listA) // 2))]
   # print result
   print("Sum of alternate elements in the list :\n ",res)
Running the above code gives us the following result −
Given list : [13, 65, 78, 13, 12, 13, 65]
Sum of alternate elements in the list :
[168, 91]
Use the percentage operator to separate the numbers at Even and Odd positions. And then add the elements to the respective position of a new empty list. Finally giving a list which shows sum of elements at odd position and sum of elements at even position.
 Live Demo
listA = [13,65,78,13,12,13,65]
# printing original list
print("Given list : " , str(listA))
res = [0, 0]
for i in range(0, len(listA)):
   if(i % 2):
      res[1] += listA[i]
   else :
      res[0] += listA[i]
# print result
print("Sum of alternate elements in the list :\n ",res)
Running the above code gives us the following result −
Given list : [13, 65, 78, 13, 12, 13, 65]
Sum of alternate elements in the list :
[168, 91]
LocalDate plusMonths() method in Java with Examples - GeeksforGeeks

30 Jul, 2019
The plusMonths() method of LocalDate class in Java is used to add the number of specified months in this LocalDate and return a copy of LocalDate.
This method adds the months field in the following steps:
Add the months to the month-of-year field.
Check if the date after adding months is valid or not.
If date is invalid then method adjust the day-of-month to the last valid day.
For example, 2018-08-31 plus one month gives date 2018-09-31 but this is invalid result, so the last valid day of the month, 2018-09-30, is returned.This instance is immutable and unaffected by this method call.
Syntax:
public LocalDate plusMonths(long monthsToAdd)

Parameters: This method accepts a single parameter monthsToAdd which represents the months to add, may be negative.
Return Value: This method returns a LocalDate based on this date with the months added, not null.
Exception: This method throws DateTimeException if the result exceeds the supported date range.
Below programs illustrate the plusMonths() method:Program 1:
// Java program to demonstrate// LocalDate.plusMonths() method  import java.time.*;  public class GFG {    public static void main(String[] args)    {          // create a LocalDate object        LocalDate date            = LocalDate.parse("2018-11-13");          // print instance        System.out.println("LocalDate before"                           + " adding months: " + date);          // add 5 months        LocalDate returnvalue            = date.plusMonths(5);          // print result        System.out.println("LocalDate after "                           + " adding months: " + returnvalue);    }}
LocalDate before adding months: 2018-11-13
LocalDate after  adding months: 2019-04-13

Program 2:
// Java program to demonstrate// LocalDate.plusMonths() method  import java.time.*;  public class GFG {    public static void main(String[] args)    {          // create a LocalDate object        LocalDate date            = LocalDate.parse("2018-12-31");          // print instance        System.out.println("LocalDate before"                           + " adding months: " + date);          // add 9 months        LocalDate returnvalue            = date.plusMonths(9);          // print result        System.out.println("LocalDate after "                           + " adding months: " + returnvalue);    }}
LocalDate before adding months: 2018-12-31
LocalDate after  adding months: 2019-09-30

References:https://docs.oracle.com/javase/10/docs/api/java/time/LocalDate.html#plusMonths(long)
Akanksha_Rai
Java-Functions
Java-LocalDate
Java-time package
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Initialize an ArrayList in Java
Overriding in Java
Multidimensional Arrays in Java
Stack Class in Java
PriorityQueue in Java
LinkedList in Java
Collections.sort() in Java with Examples
Set in Java
Hashtable in Java
Queue Interface In Java
code.compile_command() in Python - GeeksforGeeks

22 Apr, 2020
With the help of code.compile_command() method, we can compile the single or multiple lines of code to check for the syntax error if any by using code.compile_command() method.
Syntax : code.compile_command(code)Return : Return the object or compilation error if any.
Example #1 :In this example we can see that by using code.compile_command() method, we are able to compile the multiple lines of code by using this method.
# import codefrom code import compile_command  code = 'a = 5 b = 9; print(a + b)'# Using code.compile_command() methodcompile_command(code) 
Output :
a = 5 b = 9; print(a + b)^SyntaxError: invalid syntax
Example #2 :
# import codefrom code import compile_command  code = '-a=5'# Using code.compile_command() methodcompile_command(code) 
Output :
SyntaxError: can’t assign to operator
Python code-module
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Install PIP on Windows ?
How to drop one or multiple columns in Pandas Dataframe
Python OOPs Concepts
Python | Get unique values from a list
Check if element exists in list in Python
Python Classes and Objects
Python | os.path.join() method
How To Convert Python Dictionary To JSON?
Python | Pandas dataframe.groupby()
Create a directory in Python
How to convert an object array to an integer array in Java?

You can convert an object array to an integer array in one of the following ways −
By copying each element from integer array to object array −
import java.util.Arrays;
public class ObjectArrayToStringArray {
   public static void main(String args[]){
      Object[] objArray = {21, 58, 69, 33, 65};
      int length = objArray.length;
      int intArray[] = new int[length];
      for(int i=0; i<length; i++){
         intArray[i] = (int) objArray[i];
      }
      System.out.println("Contents of the integer array: "+Arrays.toString(intArray));
   }
}
Contents of the integer array: [21, 58, 69, 33, 65]
Using the arrayCopy() method of the System class −
import java.util.Arrays;
public class ObjectArrayToStringArray {
   public static void main(String args[]){
      Object[] objArray = {21, 58, 69, 33, 65};
      int length = objArray.length;
      Integer intArray[] = new Integer[length];
      System.arraycopy(objArray, 0, intArray, 0, length);
      System.out.println("Contents of the integer array: "+Arrays.toString(intArray));
   }
}
Contents of the integer array: [21, 58, 69, 33, 65]
Using the copyOf() method of the arrays class −
import java.util.Arrays;
public class ObjectArrayToStringArray {
   public static void main(String args[]){
      Object[] objArray = {21, 58, 69, 33, 65};
      int length = objArray.length;
      Integer[] intArray = Arrays.copyOf(objArray, length, Integer[].class);
      System.out.println("Contents of the integer array: "+Arrays.toString(intArray));
   }
}
Contents of the integer array: [21, 58, 69, 33, 65]
Using the toArray() method of the List class −
import java.util.Arrays;
public class ObjectArrayToStringArray {
   public static void main(String args[]){
      Object[] objArray = {21, 58, 69, 33, 65};
      Integer[] intArray = Arrays.asList(objArray).toArray(new Integer[0]);
      System.out.println("Contents of the integer array: "+Arrays.toString(intArray));
   }
}
Contents of the integer array: [21, 58, 69, 33, 65]