code-rag-bench/online-tutorials huggingface dataset:
Count of different ways to express N as the sum of 1, 3 and 4 in C++

Given a positive number N as input. The goal is to find the number of ways in which we can express N as a sum of 1s, 3s and 4s only. For example, if N is 4 then it can be represented as 1+1+1+1, 3+1, 1+3, 4 so the number of ways will be 4.
For Example
Input -  N=5
Output - Count of different ways to express N as the sum of 1, 3 and 4 are: 6
Explanation -  5 can be represented as:
1+1+1+1+1
1+3+1
3+1+1
1+1+3
4+1
1+4
Input - N=6
Output - Count of different ways to express N as the sum of 1, 3 and 4 are: 9
Explanation - 9 can be represented as:
1+1+1+1+1+1
3+1+1+1
1+3+1+1
1+1+3+1
1+1+1+3
3+3
4+1+1
1+4+1
1+1+4
In this approach we will use a dynamic programming approach to count the number of ways we can represent N as sum of 1, 3 and 4. Take array arr[i] where i represents the number and arr[i] as ways to represent it as sum.
 The base cases will be 
arr[0]=0 ( No way )
arr[1]=1 ( only one way , 1 )
arr[2]=1 ( only one way, 1+1 )
arr[3]=2 ( 1+1+1, 3 )
Now other numbers 4, 5 ... i etc. will have ways as  arr[i-1]+arr[i-3]+arr[i-4].
Take a positive number N as input. 
Function Expres_sum(int N) takes N and returns the count of different ways to express N as the sum of 1, 3 and 4.
Take array arr[N+1] to store the count of ways.
Initialize base cases   arr[0] = 1, arr[1] = 1, arr[2] = 1 and arr[3] = 2.
Traverse for rest of the values from i=4 to i<=N.
Takeaways arr[i] as sum of arr[i - 1] + arr[i - 3] + arr[i - 4].
At the end of the for loop return arr[N] as result.
Live Demo
#include <bits/stdc++.h>
using namespace std;
int Expres_sum(int N) {
   int arr[N + 1];
   arr[0] = 1;
   arr[1] = 1;
   arr[2] = 1;
   arr[3] = 2;
   for (int i = 4; i <= N; i++) {
      arr[i] = arr[i - 1] + arr[i - 3] + arr[i - 4];
   }
   return arr[N];
}
int main() {
   int N = 5;
   cout << "Count of different ways to express N as the sum of 1, 3 and 4 are: " << Expres_sum(N);
   return 0;
}
If we run the above code it will generate the following output −
Count of different ways to express N as the sum of 1, 3 and 4 are: 6
How to convert the image into a base64 string using JavaScript?

To convert the image into a base64 string using JavaScript, use the FileReader API. You can try to run the following code to get base64string for an image −
<!DOCTYPE html>
<html>
   <body>
      <script>
         function toDataURL(url, callback) {
            var httpRequest = new XMLHttpRequest();
            httpRequest.onload = function() {
               var fileReader = new FileReader();
                  fileReader.onloadend = function() {
                     callback(fileReader.result);
                  }
                  fileReader.readAsDataURL(httpRequest.response);
            };
            httpRequest.open('GET', url);
            httpRequest.responseType = 'blob';
            httpRequest.send();
         }
         toDataURL('https://www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg', function(dataUrl) {
         document.write('Result in string:', dataUrl)
      })
      </script>
   </body>
</html>
How to center a window on the screen in Tkinter?

In order to place a tkinter window at the center of the screen, we can use the PlaceWindow method in which we can pass the toplevel window as an argument and add it into the center.
We can also set the window to its center programmatically by defining its geometry.
#Import the tkinter library
from tkinter import *

#Create an instance of tkinter frame
win = Tk()

#Set the geometry
win.geometry("600x250")

win.eval('tk::PlaceWindow . center')

win.mainloop()
Running the above code will create a centered window.
Angular Google Charts - Donut Chart

Following is an example of a Donut Chart.
We have already seen the configurations used to draw a chart in Google Charts Configuration Syntax chapter. Now, let us see an example of a Donut Chart.
We've used pieHole configuration to show a Pie Chart as Donut Chart.
options = {    
   pieHole:0.4
};
app.component.ts
import { Component } from '@angular/core';
@Component({
   selector: 'app-root',
   templateUrl: './app.component.html',
   styleUrls: ['./app.component.css']
})
export class AppComponent {
   title = 'Browser market shares at a specific website, 2014';
   type = 'PieChart';
   data = [
      ['Firefox', 45.0],
      ['IE', 26.8],
      ['Chrome', 12.8],
      ['Safari', 8.5],
      ['Opera', 6.2],
      ['Others', 0.7] 
   ];
   columnNames = ['Browser', 'Percentage'];
   options = {    
      pieHole:0.4
   };
   width = 550;
   height = 400;
}
Verify the result.

    16 Lectures 
     1.5 hours 

 Anadi Sharma

    28 Lectures 
     2.5 hours 

 Anadi Sharma

    11 Lectures 
     7.5 hours 

 SHIVPRASAD KOIRALA

    16 Lectures 
     2.5 hours 

 Frahaan Hussain

    69 Lectures 
     5 hours 

 Senol Atac

    53 Lectures 
     3.5 hours 

 Senol Atac
 Print
 Add Notes
 Bookmark this page
How to convert columns of an R data frame into a single vector?

Sometimes all the columns in a data frame have similar data characteristics representing a particular variable. For example, having a data frame containing five columns each with heights of people. To convert this type of data frame into a vector we can use as.vector function along with the as.matrix function. The as.matrix will read the data frame columns so that the array of values can be created.
 Live Demo
Consider the below data frame −
set.seed(101)
x1<−rnorm(20)
x2<−rnorm(20)
x3<−rnorm(20,5,0.34)
df1<−data.frame(x1,x2,x3)
df1
x1 x2 x3
1 −0.3260365 −0.1637557 5.164036
2 0.5524619 0.7085221 5.257793
3 −0.6749438 −0.2679805 4.211429
4 0.2143595 −1.4639218 4.843768
5 0.3107692 0.7444358 4.624170
6 1.1739663 −1.4103902 5.136996
7 0.6187899 0.4670676 5.193438
8 −0.1127343 −0.1193201 4.759932
9 0.9170283 0.4672390 4.901369
10 −0.2232594 0.4981356 4.495481
11 0.5264481 0.8949372 4.608913
12 −0.7948444 0.2791520 4.906680
13 1.4277555 1.0078658 5.196486
14 −1.4668197 −2.0731065 4.525053
15 −0.2366834 1.1898534 5.254680
16 −0.1933380 −0.7243742 4.642597
17 −0.8497547 0.1679838 5.056229
18 0.0584655 0.9203352 5.384135
19 −0.8176704 −1.6716048 5.399066
20 −2.0503078 0.4484691 4.854527
Converting df1 to a vector −
df1_vector<−as.vector(as.matrix(df1[,c("x1","x2","x3")]))
df1_vector
[1] −0.3260365 0.5524619 −0.6749438 0.2143595 0.3107692 1.1739663
[7] 0.6187899 −0.1127343 0.9170283 −0.2232594 0.5264481 −0.7948444
[13] 1.4277555 −1.4668197 −0.2366834 −0.1933380 −0.8497547 0.0584655
[19] −0.8176704 −2.0503078 −0.1637557 0.7085221 −0.2679805 −1.4639218
[25] 0.7444358 −1.4103902 0.4670676 −0.1193201 0.4672390 0.4981356
[31] 0.8949372 0.2791520 1.0078658 −2.0731065 1.1898534 −0.7243742
[37] 0.1679838 0.9203352 −1.6716048 0.4484691 5.1640360 5.2577927
[43] 4.2114287 4.8437684 4.6241696 5.1369956 5.1934379 4.7599317
[49] 4.9013692 4.4954815 4.6089132 4.9066798 5.1964863 4.5250531
[55] 5.2546796 4.6425965 5.0562295 5.3841351 5.3990656 4.8545265
 Live Demo
y1<−sample(LETTERS[1:26],20)
y2<−sample(LETTERS[1:26],20)
y3<−sample(LETTERS[1:26],20)
y4<−sample(LETTERS[1:26],20)
df2<−data.frame(y1,y2,y3,y4)
df2
  y1 y2 y3 y4
1  G V P Y
2  A J N A
3  E L X L
4  K E B O
5  P Z O E
6  W T T Z
7  X N J U
8  L D L J
9  U U Z X
10 Y B A F
11 F M W I
12 Q P F B
13 T Y H M
14 H C K T
15 I F Y W
16 N G G H
17 R A M K
18 S K E G
19 C O U Q
20 O W D V
Converting df2 to a vector −
df2_vector<−as.vector(as.matrix(df2[,c("y1","y2","y3","y4")]))
df2_vector
[1] "G" "A" "E" "K" "P" "W" "X" "L" "U" "Y" "F" "Q" "T" "H" "I" "N" "R" "S" "C"
[20] "O" "V" "J" "L" "E" "Z" "T" "N" "D" "U" "B" "M" "P" "Y" "C" "F" "G" "A" "K"
[39] "O" "W" "P" "N" "X" "B" "O" "T" "J" "L" "Z" "A" "W" "F" "H" "K" "Y" "G" "M"
[58] "E" "U" "D" "Y" "A" "L" "O" "E" "Z" "U" "J" "X" "F" "I" "B" "M" "T" "W" "H"
[77] "K" "G" "Q" "V"
How to set all values in a single column MySQL Query?

To set all values in a single column MySQL query, you can use UPDATE command.
The syntax is as follows.
update yourTableName set yourColumnName =yourValue;
To understand the above syntax, let us create a table. The query to create a table is as follows.
mysql> create table setAllValuesDemo
   -> (
   -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> Name varchar(20),
   -> Amount int
   -> );
Query OK, 0 rows affected (0.64 sec)
Now you can insert some records in the table using insert command.
The query is as follows.
mysql> insert into setAllValuesDemo(Name,Amount) values('John',2345);
Query OK, 1 row affected (0.22 sec)
mysql> insert into setAllValuesDemo(Name,Amount) values('Carol',47586);
Query OK, 1 row affected (0.13 sec)
mysql> insert into setAllValuesDemo(Name,Amount) values('Bob',95686);
Query OK, 1 row affected (0.15 sec)
mysql> insert into setAllValuesDemo(Name,Amount) values('David',95667);
Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement.
The query is as follows.
mysql> select *from setAllValuesDemo;
The following is the output.
+----+-------+--------+
| Id | Name  | Amount |
+----+-------+--------+
| 1  | John  | 2345   |
| 2  | Carol | 47586  |
| 3  | Bob   | 95686  |
| 4  | David | 95667  |
+----+-------+--------+
4 rows in set (0.00 sec)
Here is the query to set all values in a single column MySQL query.
mysql> update setAllValuesDemo set Amount=10500;
Query OK, 4 rows affected (0.20 sec)
Rows matched: 4 Changed: 4 Warnings: 0
Now check the table records once again using select statement.
The query is as follows.
mysql> select *from setAllValuesDemo;
The following is the output.
+----+-------+--------+
| Id | Name  | Amount |
+----+-------+--------+
| 1  | John  | 10500  |
| 2  | Carol | 10500  |
| 3  | Bob   | 10500  |
| 4  | David | 10500  |
+----+-------+--------+
4 rows in set (0.00 sec)
How to add "graphics.h" C/C++ library to gcc compiler in Linux - GeeksforGeeks

05 Aug, 2021
While trying c graphic programming on Ubuntu, I figured out that graphic.h is not a standard C library and it is not supported by gcc compiler. So I am writing this article to explain the process.If you want to use graphics.h on Ubuntu platform you need to compile and install libgraph. It is the implementation of turbo c graphics API on Linux using SDL. You can download it from here libgraphStep by Step Instructions:  
STEP 1: First install build-essential by typing  
sudo apt-get install build-essential
STEP 2: Install some additional packages by typing  
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-2.0 \
guile-2.0-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev \
libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev \
libxext-dev x11proto-xext-dev libfreetype6 libaa1 libaa1-dev \
libslang2-dev libasound2 libasound2-dev
STEP 3: Now extract the downloaded libgraph-1.0.2.tar.gz file.
STEP 4: Goto extracted folder and run following command  
./configure
make
sudo make install
sudo cp /usr/local/lib/libgraph.* /usr/lib
Now you can use graphics.h lib using following lines:  
int gd = DETECT,gm; 
initgraph (& gd,& gm,NULL);
Example code: 
C
// C code to illustrate using// graphics in linux environment#include<stdio.h>#include<stdlib.h>#include<graphics.h>int main(){    int gd = DETECT, gm;    initgraph(&gd, &gm, NULL);     circle(50, 50, 30);     delay(500000);    closegraph();    return 0;}
Output:  
Reference: ask ubuntu This article is contributed by Aakash Tiwari. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Important Notes (Added by a user) : Files from the above-given link did not work for me. There are somethings wrong with them I downloaded files from https://github.com/SagarGaniga/Graphics-Library Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. 
Ankur Parihar
amanbhawsar99
VIPULKRISHNAMATHURIA
rajeev0719singh
computer-graphics
C Language
C++
Linux-Unix
TechTips
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Left Shift and Right Shift Operators in C/C++
Core Dump (Segmentation fault) in C/C++
Function Pointer in C
rand() and srand() in C/C++
Substring in C++
Vector in C++ STL
Inheritance in C++
Initialize a vector in C++ (6 different ways)
Map in C++ Standard Template Library (STL)
C++ Classes and Objects
GATE | GATE CS 1996 | Question 14 - GeeksforGeeks

31 Oct, 2017
In the balanced binary tree in the below figure, how many nodes will become unbalanced when a node is inserted as a child of the node “g”?
         a
       /   \
      b     e
     / \   /
    c  d  f
   /
  g

(A) 1(B) 3(C) 7(D) 8Answer: (B)Explanation:Quiz of this QuestionPlease comment below if you find anything wrong in the above post
GATE CS 1996
GATE-GATE CS 1996
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
GATE | GATE-IT-2004 | Question 71
GATE | GATE CS 2011 | Question 7
GATE | GATE-CS-2015 (Set 3) | Question 65
GATE | GATE-CS-2014-(Set-3) | Question 38
GATE | GATE-CS-2016 (Set 2) | Question 48
GATE | GATE CS 2018 | Question 37
GATE | GATE-IT-2004 | Question 83
GATE | GATE-CS-2016 (Set 1) | Question 65
GATE | GATE-CS-2016 (Set 1) | Question 63
GATE | GATE-CS-2007 | Question 64
Scala String toCharArray() method with example - GeeksforGeeks

29 Oct, 2019
The toCharArray() method is utilized to convert a stated string to CharArray.
Method Definition: char[] toCharArray()
Return Type: It returns CharArray.
Example: 1#
// Scala program of toCharArray()// method  // Creating objectobject GfG{       // Main method    def main(args:Array[String])    {              // Applying toCharArray method        val result = "GeeksforGeeks".toCharArray()                  for(m1<-result)        {            // Displays output            println(m1)        }              }} 
G
e
e
k
s
f
o
r
G
e
e
k
s


Example: 2#
// Scala program of toCharArray()// method  // Creating objectobject GfG{       // Main method    def main(args:Array[String])    {              // Applying toCharArray method        val result = "Nidhi".toCharArray()                  for(m1 <- result)        {            // Displays output            println(m1)        }          }} 
N
i
d
h
i

Scala
Scala-Method
Scala-Strings
Scala
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Type Casting in Scala
Class and Object in Scala
Scala Lists
Scala Tutorial – Learn Scala with Step By Step Guide
Operators in Scala
Inheritance in Scala
Scala Constructors
Scala | Arrays
Scala String substring() method with example
Lambda Expression in Scala
How to install MySQL connector package in Python? - GeeksforGeeks

26 Mar, 2020
Prerequisite: Python Language Introduction MySQL is a Relational Database Management System (RDBMS) whereas the structured Query Language (SQL) is the language used for handling the RDBMS using commands i.e Creating, Inserting, Updating and Deleting the data from the databases.A connector is employed when we have to use MySQL with other programming languages. The work of mysql-connector is to provide access to MySQL Driver to the required language. Thus, it generates a connection between the programming language and the MySQL Server.
To install Python-mysql-connector module, one must have Python and PIP, preinstalled on their system. To check if your system already contains Python, go through the following instructions:
Open the Command line(search for cmd in the Run dialog( + R).Now run the following command:
python --version
If Python is already installed, it will generate a message with the Python version available.
If Python is not present, go through How to install Python on Windows and Linux? and follow the instructions provided. PIP is a package management system used to install and manage software packages/libraries written in Python. These files are stored in a large “on-line repository” termed as Python Package Index (PyPI).To check if PIP is already installed on your system, just go to the command line and execute the following command:
pip -V
If PIP is not present, go through How to install PIP on Windows and Linux?
mysql-connector method can be installed on Windows with the use of following command:
pip install mysql-connector-python
mysql-connector method can be installed on Linux with the use of following command:
pip3 install mysql-connector
Python-mySQL
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Iterate over a list in Python
Python String | replace()
*args and **kwargs in Python
Reading and Writing to text files in Python
Create a Pandas DataFrame from Lists
Function Returning Multiple Values in Go Language - GeeksforGeeks

01 Aug, 2019
In Go language, you are allowed to return multiple values from a function, using the return statement. Or in other words, in function, a single return statement can return multiple values. The type of the return values is similar to the type of the parameter defined in the parameter list.
Syntax:
func function_name(parameter_list)(return_type_list){
     // code...
}

Here,
function_name: It is the name of the function.
parameter-list: It contains the name and the type of the function parameters.
return_type_list: It is optional and it contains the types of the values that function returns. If you are using return_type in your function, then it is necessary to use a return statement in your function.
Example:
// Go program to illustrate how a// function return multiple valuespackage main  import "fmt"  // myfunc return 3 values of int typefunc myfunc(p, q int)(int, int, int ){    return p - q, p * q, p + q }  // Main Methodfunc main() {          // The return values are assigned into     // three different variables   var myvar1, myvar2, myvar3 = myfunc(4, 2)        // Display the values   fmt.Printf("Result is: %d", myvar1 )   fmt.Printf("\nResult is: %d", myvar2)   fmt.Printf("\nResult is: %d", myvar3)}
Output:
Result is: 2
Result is: 8
Result is: 6

In Go language, you are allowed to provide names to the return values. And you can also use those variable names in your code. It is not necessary to write these names with a return statement because the Go compiler will automatically understand that these variables have to dispatch back. And this type of return is known as the bare return. The bare return reduces the duplication in your program.
Syntax:
func function_name(para1, para2 int)(name1 int, name2 int){
    // code...
}

or

func function_name(para1, para2 int)(name1, name2 int){
   // code...
}

Here, name1 and name2 is the name of the return value and para1 and para2 are the parameters of the function.
Example:
// Go program to illustrate how to// give names to the return valuespackage main  import "fmt"  // myfunc return 2 values of int type// here, the return value name // is rectangle and squarefunc myfunc(p, q int)( rectangle int, square int ){    rectangle = p*q    square = p*p    return  }  func main() {          // The return values are assigned into     // two different variables   var area1, area2 = myfunc(2, 4)        // Display the values   fmt.Printf("Area of the rectangle is: %d", area1 )   fmt.Printf("\nArea of the square is: %d", area2)     }
Output:
Area of the rectangle is: 8
Area of the square is: 4

Go-Functions
Golang
Go Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
6 Best Books to Learn Go Programming Language
strings.Replace() Function in Golang With Examples
Arrays in Go
How to Split a String in Golang?
fmt.Sprintf() Function in Golang With Examples
Golang Maps
Slices in Golang
Inheritance in GoLang
Different Ways to Find the Type of Variable in Golang
Interfaces in Golang
PyQt5 ComboBox – User entered items not stored in drop down menu - GeeksforGeeks

08 Oct, 2021
In this article we will see how user entered item don’t get added in the combo box i.e when user insert item in the editable combo box it do not get inserted at the any position of the drop down list, by default when user insert any item it get inserted at the bottom.If we use normal i.e non editable combo box user is not able to add any item to the combo box, but editable combo box allow user to edit the item or search the item from the item list. Sometimes there is a need where combo box should be editable and also it do not insert any item for example in a combo box of selecting country, editable combo box will help of search country and it will not allow user to add another item. 
In order to make combo box such that item inserted by user don’t get added in the drop down list we have to do the following –1. Create a combo box 2. Make the combo box editable using setEditable method 3. Set insertion policy of combo box to do not insert 4. Create label 5. Retrieve the insertion policy and show it with the help of label 
Below is the implementation –  
Python3
# importing librariesfrom PyQt5.QtWidgets import *from PyQt5 import QtCore, QtGuifrom PyQt5.QtGui import *from PyQt5.QtCore import *import sys  class Window(QMainWindow):     def __init__(self):        super().__init__()         # setting title        self.setWindowTitle("Python ")         # setting geometry        self.setGeometry(100, 100, 600, 400)         # calling method        self.UiComponents()         # showing all the widgets        self.show()     # method for widgets    def UiComponents(self):         # creating a combo box widget        self.combo_box = QComboBox(self)         # setting geometry of combo box        self.combo_box.setGeometry(200, 150, 120, 30)         # geek list        geek_list = ["Geek", "Geeky Geek"]         # adding list of items to combo box        self.combo_box.addItems(geek_list)         # creating editable combo box        self.combo_box.setEditable(True)         # setting insertion policy        # stopping insertion        self.combo_box.setInsertPolicy(QComboBox.NoInsert)         # getting current insertion policy        policy = self.combo_box.insertPolicy()         # creating label to  print the policy        label = QLabel("Insertion policy = " + str(policy), self)         # setting geometry of the label        label.setGeometry(200, 100, 200, 30)  # create pyqt5 appApp = QApplication(sys.argv) # create the instance of our Windowwindow = Window() # start the appsys.exit(App.exec())
Output :  
Media error: Format(s) not supported or source(s) not found
 
varshagumber28
Python PyQt5-ComboBox
Python-gui
Python-PyQt
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Python String | replace()
*args and **kwargs in Python
Reading and Writing to text files in Python
Create a Pandas DataFrame from Lists
Convert integer to string in Python
Check if element exists in list in Python
Four File Handling Hacks which every C/C++ Programmer should know - GeeksforGeeks

29 May, 2017
We will discuss about four file hacks listed as below-
Rename – Rename a file using C/C++Remove – Remove a file using C/C++File Size – Get the file size using C/C++Check existence – Check whether a file exists or not in C/C++
Rename – Rename a file using C/C++
Remove – Remove a file using C/C++
File Size – Get the file size using C/C++
Check existence – Check whether a file exists or not in C/C++
// A C++ Program to demonstrate the// four file hacks every C/C++ must know  // Note that we are assuming that the files// are present in the same file as the program// before doing the below four hacks#include<stdio.h>#include<stdlib.h>#include<stdbool.h>  // A Function to get the file sizeunsigned long long int fileSize(const char *filename){    // Open the file    FILE *fh = fopen(filename, "rb");    fseek(fh, 0, SEEK_END);    unsigned long long int size = ftell(fh);    fclose(fh);      return (size);}  // A Function to check if the file exists or notbool fileExists(const char * fname){    FILE *file;    if (file = fopen(fname, "r"))    {        fclose(file);        return (true);    }    return (false);}  // Driver Program to test above functionsint main(){    printf("%llu Bytes\n", fileSize("Passwords.txt"));    printf("%llu Bytes\n", fileSize("Notes.docx"));      if (fileExists("OldData.txt") == true )        printf("The File exists\n");    else        printf("The File doen't exist\n");      rename("Videos", "English_Videos");    rename("Songs", "English_Songs");      remove("OldData.txt");    remove("Notes.docx");      if (fileExists("OldData.txt") == true )        printf("The File exists\n");    else        printf("The File doesn't exist\n");      return 0;}
Output:
Screenshot before executing the program :
Screenshot after executing the program :
This article is contributed by Rachit Belwariar. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
cpp-file-handling
C Language
C++
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc()
std::sort() in C++ STL
Bitwise Operators in C/C++
Left Shift and Right Shift Operators in C/C++
Function Pointer in C
Vector in C++ STL
Initialize a vector in C++ (6 different ways)
std::sort() in C++ STL
Virtual Function in C++
Bitwise Operators in C/C++
GATE-CS-2017 (Set 2) - GeeksforGeeks

11 Oct, 2021

Choice A : 12 [Wrong] 
There is no integer x that satisfies below equation
12 * 3  + x * 11 = 100
x = 64/11 [Which is not an integer]

Choice B : 15 [Right] 
15 * 3  + x * 11 = 100
x = 55/11  = 5

Choice C : 18 [Wrong] 
There is no integer x that satisfies below equation
18 * 3  + x * 11 = 100
x = 46/11 [Which is not an integer]

Choice C : 19 [Wrong] 
There is no integer x that satisfies below equation
19 * 3  + x * 11 = 100
x = 43/11 [Which is not an integer] 
V

W
X

Z

V

W
X

Z

V

W

Y
Ways to collect both Red = 3C2
Ways to collect both Green = 3C2
Ways to collect both Blue = 5C2

Total Ways = 11C2

P(Socks of Same Colour) = (3C2 + 5C2+ 3C2 ) /  11C2

= 16/55 
Yield - produce or provide
Resistance - the refusal to accept or comply with something.
Rest are all synonyms.
Hence, (D) is correct.
It becomes positive to negative in range [-5, 0] when ex + 0.5x2 becomes less than 2.It becomes positive to negative in range [0, 5] when ex + 0.5x2 becomes more than 2.
It becomes positive to negative in range [-5, 0] when ex + 0.5x2 becomes less than 2.
It becomes positive to negative in range [0, 5] when ex + 0.5x2 becomes more than 2.
Box 3 labeled as Apples and Oranges - Original Content can be Apple or Orangle (This box will have only one fruit, so whichever we pick would  be the correct label). Let's say the picked item was Apple, therefore the box labeled Orange will have Apples and Oranges.)
Box 2 - Oranges - This box will definitely not have orange (as its mislabeled) and it can not contain only apple (As it is in box 3) - So this will have Original Content- both oranges and Apples
Box 1 - Apples - This is the leftover box and it can now have Original Content - Orange
X = 4777....(till 30 digits)

or X = 4.7777⋯ ∗ 1029

X29 = (4.777⋯∗1029 )3 
  = (4.777...)3 ∗ 10 87

So, (X3 )3  requires 3 + 87 = 90 digits. 
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Must Do Coding Questions for Product Based Companies
C Program For Finding Length Of A Linked List
How to calculate MOVING AVERAGE in a Pandas DataFrame?
How to Convert Categorical Variable to Numeric in Pandas?
How to Replace Values in Column Based on Condition in Pandas?
How to Fix: SyntaxError: positional argument follows keyword argument in Python
How to Fix: KeyError in Pandas
C Program to read contents of Whole File
How to Append Pandas DataFrame to Existing CSV File?
How to Replace Values in a List in Python?
How to count null values in MySQL?

To count null values in MySQL, you can use CASE statement. Let us first see an example and create a table −
mysql> create table DemoTable
(
   Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   FirstName varchar(20)
);
Query OK, 0 rows affected (0.77 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(FirstName) values('John');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable(FirstName) values(null);
Query OK, 1 row affected (0.25 sec)
mysql> insert into DemoTable(FirstName) values('');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable(FirstName) values('Larry');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable(FirstName) values('');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable(FirstName) values(null);
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable(FirstName) values(null);
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable(FirstName) values('Bob');
Query OK, 1 row affected (0.15 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+-----------+
| Id | FirstName |
+----+-----------+
| 1  | John      |
| 2  | NULL      |
| 3  |           |
| 4  | Larry     |
| 5  |           |
| 6  | NULL      |
| 7  | NULL      |
| 8  | Bob       |
+----+-----------+
8 rows in set (0.00 sec)
Here is the query to count Null values in MySQL −
mysql> select sum(case when FirstName IS NULL then 1 else 0 end) as NUMBER_OF_NULL_VALUE from DemoTable;
This will produce the following output −
+----------------------+
| NUMBER_OF_NULL_VALUE |
+----------------------+
| 3                    |
+----------------------+
1 row in set (0.00 sec)
Java Concurrency - Futures and Callables

java.util.concurrent.Callable object can return the computed result done by a thread in contrast to runnable interface which can only run the thread. The Callable object returns Future object which provides methods to monitor the progress of a task being executed by a thread. Future object can be used to check the status of a Callable and then retrieve the result from the Callable once the thread is done. It also provides timeout functionality.
//submit the callable using ThreadExecutor
//and get the result as a Future object
Future<Long> result10 = executor.submit(new FactorialService(10));
 
//get the result using get method of the Future object
//get method waits till the thread execution and then return the result of the execution.
Long factorial10 = result10.get();

The following TestThread program shows usage of Futures and Callables in thread based environment.
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class TestThread {

   public static void main(final String[] arguments) throws InterruptedException,
      ExecutionException {

      ExecutorService executor = Executors.newSingleThreadExecutor();

      System.out.println("Factorial Service called for 10!");
      Future<Long> result10 = executor.submit(new FactorialService(10));

      System.out.println("Factorial Service called for 20!");
      Future<Long> result20 = executor.submit(new FactorialService(20));

      Long factorial10 = result10.get();
      System.out.println("10! = " + factorial10);

      Long factorial20 = result20.get();
      System.out.println("20! = " + factorial20);

      executor.shutdown();
   }  

   static class FactorialService implements Callable<Long> {
      private int number;

      public FactorialService(int number) {
         this.number = number;
      }

      @Override
      public Long call() throws Exception {
         return factorial();
      }

      private Long factorial() throws InterruptedException {
         long result = 1; 
         
         while (number != 0) { 
            result = number * result; 
            number--; 
            Thread.sleep(100); 
         }
         return result;	
      }
   }
}
This will produce the following result.
Factorial Service called for 10!
Factorial Service called for 20!
10! = 3628800
20! = 2432902008176640000


    16 Lectures 
     2 hours 

 Malhar Lathkar

    19 Lectures 
     5 hours 

 Malhar Lathkar

    25 Lectures 
     2.5 hours 

 Anadi Sharma

    126 Lectures 
     7 hours 

  Tushar Kale

    119 Lectures 
     17.5 hours 

 Monica Mittal

    76 Lectures 
     7 hours 

 Arnab Chakraborty
 Print
 Add Notes
 Bookmark this page
C++ Map Library - operator== Functionb

The C++ function std::map::operator== tests whether two maps are equal or not.
Following is the declaration for std::map::operator== function form std::map header.
template <class Key, class T, class Compare, class Alloc>
bool operator== ( const map<Key,T,Compare,Alloc>& m1,
                  const map<Key,T,Compare,Alloc>& m2);

m1 − First map object.
m1 − First map object.
m2 − Second map object.
m2 − Second map object.
Returns true if both map are equal otherwise false.
This function doesn't throw exception.
Linear i.e. O(n)
The following example shows the usage of std::map::operator== function.
#include <iostream>
#include <map>

using namespace std;

int main(void) {
   map<char, int> m1;
   map<char, int> m2;

   if (m1 == m2)
      cout << "Both maps are equal." << endl;

   m1.emplace('a', 1);

   if (!(m1 == m2))
      cout << "Both maps are not equal." << endl;

   return 0;
}
Let us compile and run the above program, this will produce the following result −
Both maps are equal.
Both maps are not equal.

 Print
 Add Notes
 Bookmark this page
Insert with a Select query in MySQL

For Insert with SELECT query, the syntax is as follows −
insert into yourTableName(yourColumnName1,yourColumnName2,yourColumnName3,...N) select yourValue1,yourValue2,yourValue3,......N;
Let us first create a table −
mysql> create table DemoTable1603
   -> (
   -> StudentId int,
   -> StudentName varchar(20),
   -> StudentMarks int
   -> );
Query OK, 0 rows affected (0.50 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1603(StudentId,StudentName,StudentMarks) select 101,'John',45;
Query OK, 1 row affected (0.17 sec)
Records: 1  Duplicates: 0  Warnings: 0
mysql> insert into DemoTable1603(StudentId,StudentName,StudentMarks) select 102,'Adam',76;
Query OK, 1 row affected (0.11 sec)
Records: 1  Duplicates: 0  Warnings: 0
mysql> insert into DemoTable1603(StudentId,StudentName,StudentMarks) select 103,'Bob',67;
Query OK, 1 row affected (0.31 sec)
Records: 1  Duplicates: 0  Warnings: 0
Display all records from the table using select statement −
mysql> select * from DemoTable1603;
This will produce the following output −
+-----------+-------------+--------------+
| StudentId | StudentName | StudentMarks |
+-----------+-------------+--------------+
|       101 | John        |           45 |
|       102 | Adam        |           76 |
|       103 | Bob         |           67 |
+-----------+-------------+--------------+
3 rows in set (0.00 sec)
SQL Tryit Editor v1.6

SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City
FROM Customers A, Customers B
WHERE A.CustomerID <> B.CustomerID
AND A.City = B.City 
ORDER BY A.City;
​
Edit the SQL Statement, and click "Run SQL" to see the result.
This SQL-Statement is not supported in the WebSQL Database.
The example still works, because it uses a modified version of SQL.
Your browser does not support WebSQL.
Your are now using a light-version of the Try-SQL Editor, with a read-only Database.
If you switch to a browser with WebSQL support, you can try any SQL statement, and play with the Database as much as you like. The Database can also be restored at any time.
Our Try-SQL Editor uses WebSQL to demonstrate SQL.
A Database-object is created in your browser, for testing purposes.
You can try any SQL statement, and play with the Database as much as you like. The Database can be restored at any time, simply by clicking the "Restore Database" button.
WebSQL stores a Database locally, on the user's computer. Each user gets their own Database object.
WebSQL is supported in Chrome, Safari, Opera, and Edge(79).
If you use another browser you will still be able to use our Try SQL Editor, but a different version, using a server-based ASP application, with a read-only Access Database, where users are not allowed to make any changes to the data.
C Program to find minimum occurrence of character in a string

An array of characters is called a string.
Following is the declaration for declaring an array is as follows −
char stringname [size];
For example − char string[50]; string of length 50 characters
Using single character constant −
char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}
Using string constants −
char string[10] = "Hello":;
Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.
The logic to find minimum occurrence of a character in a given string is as follows −
for(i=0; i<CHARS; i++){
   if(frequency[i]!=0){
      if(frequency[minimum] == 0 || frequency[i]< fequency[minimum]) minimum = i;
}
Following is the C program to find minimum occurring character in a string.
#include<stdio.h>
#define SIZE 100 // Maximum string size
#define CHARS 255 // Maximum characters allowed
int main(){
   char string[SIZE];
   int frequency[CHARS];
   int i = 0, minimum;
   int value;
   printf("Enter the string:\n ");
   gets(string);
   for(i=0; i<CHARS; i++){
      frequency[i] = 0; // initialize freq of all char to zero
   }
   i=0;
   while(string[i] != '\0'){ // finding freq of each char
      value = (int)string[i];
      frequency[value] += 1;
      i++;
   }
   minimum = 0;
   for(i=0; i<CHARS; i++){// finding min freq
      if(frequency[i]!=0){
         if(frequency[minimum] == 0 || frequency[i]<fequency[minimum])
            minimum = i;
   }
   printf("Minimum occurrence character is '%c' = %d times.", minimum,    frequency[minimum]);
   return 0;
}
When the above program is executed, it produces the following result −
Enter the string:
tutorialspoint
Minimum occurrence character is 'a' = 1 times.
PHP | imagetypes() Function - GeeksforGeeks

26 Jul, 2019
The imagetypes() function is an inbuilt function in PHP which is used to return the image types supported by the PHP inbuilt installed library.
Syntax:
int imagetypes( void )
Parameters: This function does not accept any parameter.
Return Value: This function returns the bit-field corresponding to the image formats supported by the version of GD linked into PHP. This function returns the following bits: IMG_BMP, IMG_GIF, IMG_JPG, IMG_PNG, IMG_WBMP, IMG_XPM, IMG_WEBP.
Below programs illustrate the imagetypes() function in PHP:
Program 1:
<?phpif (imagetypes() & IMG_PNG) {    echo "PNG Support is enabled";}else {    echo "Not supported image type.";}?>
Output:
PNG Support is enabled
Program 2:
<?phpif (imagetypes() & IMG_JPEG) {    echo "JPEG Support is enabled";}else {    echo "Not supported image type.";}?>
Output:
JPEG Support is enabled
Related Articles:
PHP | imagegif() Function
PHP | imagecolorexact() Function
Reference: http://php.net/manual/en/function.imagetypes.php
Akanksha_Rai
Image-Processing
PHP-function
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to fetch data from localserver database and display on HTML table using PHP ?
Different ways for passing data to view in Laravel
Create a drop-down list that options fetched from a MySQL database in PHP
How to create admin login page using PHP?
How to generate PDF file using PHP ?
Roadmap to Become a Web Developer in 2022
Installation of Node.js on Linux
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to Import .dta Files into R? - GeeksforGeeks

19 Dec, 2021
In this article, we will discuss how to import .dta files in the R Programming Language.
There are many types of files that contain datasets, for example, CSV, Excel file, etc. These are used extensively with the R Language to import or export data sets into files. One such format is DAT which is saved with extension .dat. These data files are used by supported applications as database files and are used by the IWIS Chain Engineering software for its database file format. 
To import .dat files in the R Language, we use the read_dta() function from the haven package library to read .dat files into a data frame. The read_dat() function takes the file name as an argument and returns the .dat file as a data frame. To use the read.dat() function at first we need to install the haven package.
To install the haven package library, we use:
install.packages("haven")
Then we import the haven package into the R console and use the read_dat() function to read .dat file into a data frame.
Syntax: dataframe <- read.dat( “file.dat” )
where, file.dat: determines the file name along with relative path from the working directory.
Example 1: We are importing a .dat file from the working directory in the R Language. The .dat file can be downloaded from here.
R
# load library havenlibrary(haven)  # import .dat filedata <- read_dta("Sample.dta")  # print head and summary of data frameprint("Top 6 Entries of data frame:")head(data)print("summary:")summary(data)
Output:
Top 6 Entries of data frame:
# A tibble: 6 x 1
     y
 <dbl>
1  15.0
2  17.3
3  16.4
4  19.3
5  17.7
6  17.5
summary:
      y        
Min.   :13.53  
1st Qu.:15.95  
Median :17.09  
Mean   :17.16  
3rd Qu.:18.50  
Max.   :20.40  
Example 2: We are importing a .dat file from outside of the working directory using its absolute address in the R Language. The .dat file can be downloaded from here.
R
# load library havenlibrary(haven)  # import .dat filedata <- read_dta("C:/Users/Priyank Mishra/Sample.dta")  # print head and summary of data frameprint("Top 6 entries of data frame:")head(data)print("summary:")summary(data)
Output:
Top 6 entries of data frame:
# A tibble: 6 x 1
    y
<dbl>
1  15.0
2  17.3
3  16.4
4  19.3
5  17.7
6  17.5
summary:
     y        
Min.   :13.53  
1st Qu.:15.95  
Median :17.09  
Mean   :17.16  
3rd Qu.:18.50  
Max.   :20.40 
Picked
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Change Color of Bars in Barchart using ggplot2 in R
How to Change Axis Scales in R Plots?
Group by function in R using Dplyr
How to Split Column Into Multiple Columns in R DataFrame?
How to import an Excel File into R ?
How to filter R DataFrame by values in a column?
How to filter R dataframe by multiple conditions?
How to change the order of bars in bar chart in R ?
R - if statement
Replace Specific Characters in String in R
MomentJS - Unix Timestamp(milliseconds)

This method gives the number of milliseconds since the Unix epoch.
moment().valueOf();
+moment();

var a = moment().valueOf();
var a = +moment();
 Print
 Add Notes
 Bookmark this page
How to rename a column in an existing MySQL table?

To rename a column in an existing MySQL table we can use ALTER TABLE command with CHANGE keyword as follows −
mysql> Alter table Student CHANGE Email Emailid Varchar(30);
Query OK, 5 rows affected (0.38 sec)
Records: 5 Duplicates: 0 Warnings: 0
With the help of query above, MySQL has changed the name of column ‘Email’ to ‘Emailid’.
We can specify the same data type & size or different data type & size with new column name as follows −
mysql> Alter table Student CHANGE Emailid Mailid char(35);
Query OK, 5 rows affected (0.29 sec)
Records: 5 Duplicates: 0 Warnings: 0
With the help of query above, MySQL has changed the name of the column from ‘Emailid’ to ‘Mailid’ along with its data type from varchar(30) to char(35).
Java Program to Calculate Simple Interest

09 Oct, 2021
Simple interest is a quick method of calculating the interest charge on a loan. Simple interest is determined by multiplying the daily interest rate by the principal by the number of days that elapse between payments. 
Simple interest formula is given by:
Simple Interest = (P x T x R)/100 
Where, 
P is the principal amount 
T is the time and 
R is the rate
Examples: –
Example 1:

Input :  P = 10000
         R = 5
         T = 5
Output : 2500

Explanation - We need to find simple interest on 
Rs. 10, 000 at the rate of 5% for 5 
units of time.

Example 2:

Input :  P = 3000
         R = 7
         T = 1
Output : 210
Example 1:
Java
// Java program to compute// simple interest for given principal// amount, time and rate of interest.import java.io.*;  class GFG {    public static void main(String args[])    {        // We can change values here for        // different inputs        float P = 1, R = 1, T = 1;          /* Calculate simple interest */        float SI = (P * T * R) / 100;        System.out.println("Simple interest = " + SI);    }}  // This code is contributed by Anant Agarwal.
Simple interest = 0.01
Example 2:
Java
// Java program to compute// simple interest for given principal// amount, time and rate of interest.import java.io.*;  class GFG {    public static void main(String args[])    {        // We can change values here for        // different inputs        float P = 10000, R = 5, T = 5;          // Calculate simple interest        float SI = (P * T * R) / 100;        System.out.println("Simple interest = " + SI);    }}
Simple interest = 2500.0
Please refer complete article on the Program to find simple interest for more details!
nishkarshgandhi
Java
Java Programs
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Object Oriented Programming (OOPs) Concept in Java
How to iterate any Map in Java
Interfaces in Java
HashMap in Java with Examples
ArrayList in Java
Initializing a List in Java
Java Programming Examples
Convert a String to Character Array in Java
Convert Double to Integer in Java
Implementing a Linked List in Java using Class
Is String a primitive data type or an object in Java?

String is not a primitive data type. Java.lang package provides the String class therefore, it is an object type. You can create a string variable directly like any other variables as −
String s = "myString";
(or)
By instantiating the string class using the new keyword as −
String s = new String("myString");
 Live Demo
import java.util.Scanner;

public class StringExample {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sting value:");

String str = sc.nextLine();
System.out.println(str.getClass());
}
}
Enter a sting value:
hello
class java.lang.String
Calculate tangent of a value in R Programming - tan() Function - GeeksforGeeks

01 Jun, 2020
tan() function in R Language is used to calculate the tangent of the numeric value passed to it as argument.
Syntax: tan(x)
Parameter:x: Numeric value
Example 1:
# R code to calculate tangent of a value  # Assigning values to variablesx1 <- -90x2 <- -30  # Using tan() Functiontan(x1)tan(x2)
Output:
[1] 1.9952
[1] 6.405331
Example 2:
# R code to calculate tangent of a value  # Assigning values to variablesx1 <- pix2 <- pi / 3  # Using tan() Functiontan(x1)tan(x2)
Output:
[1] -1.224647e-16
[1] 1.732051
R Math-Function
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Change Color of Bars in Barchart using ggplot2 in R
Group by function in R using Dplyr
How to Change Axis Scales in R Plots?
How to Split Column Into Multiple Columns in R DataFrame?
Replace Specific Characters in String in R
How to filter R DataFrame by values in a column?
R - if statement
How to filter R dataframe by multiple conditions?
Plot mean and standard deviation using ggplot2 in R
Time Series Analysis in R