How to write my own header file in C?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

1K+ Views

Steps to write my own header file in C −Type a code and save it as “sub.h”.Write a main program “subtraction.c” in which −include new header file.Write “sub.h” instead of All the functions in sub.h header are now ready for use.Directly call the function sub().Both “subtraction.c” and “sub.h” should be in same folder.Sub.hint sub(int m, int n) {    return(m-n); }subtraction.cExample#include #include "sub.h" void main() {    int a= 7, b= 6, res;    res = sub(a, b);    printf("Subtraction of two numbers is: %d", res); }After running ”subtraction.c” the output will be −OutputSubtraction of two numbers is: 1Read More

What is Broadcasting in Computer Network?

Moumita
Updated on 30-Jul-2019 22:30:26

12K+ Views

Broadcasting in computer network is a group communication, where a sender sends data to receivers simultaneously. This is an all − to − all communication model where each sending device transmits data to all other devices in the network domain.The ways of operation of broadcasting may be −A high level operation in a program, like broadcasting in Message Passing Interface.A low level networking operation, like broadcasting on Ethernet.Broadcasting is shown in the following figure −Advantages of BroadcastingBroadcast helps to attain economies of scale when a common data stream needs to be delivered to all, by minimizing the communication and processing ... Read More

How do I search and replace specific chars at the beginning of a string in MySQL?

Rama Giri
Updated on 30-Jul-2019 22:30:26

181 Views

For this, you can use INSERT(). Let us first create a table −mysql> create table DemoTable    -> (    -> ZipCode varchar(200)    -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('9030'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('3902'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('9083'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('9089'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement ... Read More

Activity Selection Problem (Greedy Algo-1) in C++?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

2K+ Views

There are n different activities are given with their starting time and ending time. Select maximum number of activities to solve by a single person.We will use the greedy approach to find the next activity whose finish time is minimum among rest activities, and the start time is more than or equal with the finish time of the last selected activity.The complexity of this problem is O(n log n) when the list is not sorted. When the sorted list is provided the complexity will be O(n).InputA list of different activities with starting and ending times.{(5, 9), (1, 2), (3, 4), ... Read More

What is the importance of ES6's template strings in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

87 Views

ES6's template strings is a new way to combine strings. We already have methods such as join(), concat() etc to combine strings but the template strings method is the most sophisticated because it’s more readable, no backslash to escape quotes and no more messy plus operators.Using concat() and join()ExampleIn the following example join() and concat() methods are used to combine strings. If we observe carefully the code looks very messy.Live Demo const platform = 'Tutorix'; const joinMethod = ['The', 'best', 'e-learning', 'platform', 'is', platform].join(' '); document.write(joinMethod); ... Read More

How to select objects where an array contains only a specific field in MongoDB?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

214 Views

Let us first create a collection with documents −> db.arrayContainOnlySpecificFieldDemo.insertOne( ...    { ...       "StudentName":"John", ...       "StudentAge":21, ...       "StudentTechnicalSubject":["C", "Java", "MongoDB"] ...    } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc4921dac184d684e3fa26a") } > db.arrayContainOnlySpecificFieldDemo.insertOne( { "StudentName":"Carol", "StudentAge":23, "StudentTechnicalSubject":["MongoDB"] } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc49237ac184d684e3fa26b") }Display all documents from a collection with the help of find() method. The query is as follows −> db.arrayContainOnlySpecificFieldDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cc4921dac184d684e3fa26a"),    "StudentName" : "John",    "StudentAge" : 21,   ... Read More

How to change JLabel background and foreground color in Java?

Nancy Den
Updated on 30-Jul-2019 22:30:26

2K+ Views

To change the JLabel foreground and background color, use the following methods:JLabel label; label.setForeground(new Color(120, 90, 40)); label.setBackground(new Color(100, 20, 70));The following is an example to change JLabel background and foreground color:Exampleimport java.awt.Color; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("This is demo label!", JLabel.RIGHT);       label.setVerticalAlignment(JLabel.TOP);       label.setFont(new Font("Verdana", Font.PLAIN, 15));       label.setForeground(new Color(120, 90, 40));       label.setBackground(new Color(100, 20, 70));   ... Read More

How to open last activity when tapping on Android notification?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

554 Views

This example demonstrate about How to open last activity when tapping on Android notificationStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Context ; import android.content.Intent ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; import android.view.View ; import android.widget.Button ; public class MainActivity extends AppCompatActivity {    public static ... Read More

Hidden features of C++

George John
Updated on 30-Jul-2019 22:30:26

336 Views

Here we will see some good features and tricks of C++ programming language that can help us in different area. Like if we want to participate in some competitive programming events, then these tricks will help us to reduce the time for writing codes. Let us see some of these examples one by one.Checking whether a number is odd or even without using % operator. This trick is simple. We can perform bitwise AND operation with the number and 1. If the result is non-zero then this is odd, otherwise this is even. The logic is too simple. All odd ... Read More

How can I set an EtchedBorder from BorderFactory class to a component in Java?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

136 Views

Set an EtchedBorder from BorderFactory class −EtchedBorder etchedBorder = (EtchedBorder)BorderFactory.createEtchedBorder();Now, set it for a component −JButton button = new JButton("Etched Border"); button.setBorder(etchedBorder);The following is an example to set an EtchedBorder from BorderFactory class to a component −Examplepackage my; import java.awt.BorderLayout; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.border.Border; import javax.swing.border.EtchedBorder; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED);       EtchedBorder etchedBorder = (EtchedBorder)BorderFactory.createEtchedBorder();       JButton raisedButton = new JButton("Raised Border");   ... Read More

Advertisements