Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

C - a simple function to demonstrate the example of recursion function

c

int fn(int a, int b) {
	if (b == 0) return 0;
	if (b == 1) return a;
	return a + fn(a, b-1);
}

Python example to print the type of various number variables

a = 5
print(a,"is of type",type(a))

a=2.0
print(a,"is of type",type(a))

a=1+2j
print(a,"is of type",type(a))


    
            

Execute Bash Shell Online

#!/bin/sh
read -p "enter the no. of element" n

for((i=0; i < n; i++))
{
read -p "enter elements" a[i]
}
k=0
	while((k<n))
	{
	i=$k
		for((j=$i+1;j<n;j++))
		{
		if(($a[i]>$a[j]))
		then
		i=$j
		fi
		}
	temp=$a[k]
	a[k]=$a[i]
	a[i]=$temp
	((k++))
	}

for((l=0;l<n;l++))
do
echo $a[l]
done
exit 0

Java example for elevator working operations

import java.awt.geom.*;

public class elevator
{

    static int floor = 0, choice1, person = 0;

    public static void main(String args[])
    {

        floor = ((int) (Math.random() * 10 + 1));

        System.out.println("The elevator is now on floor " +floor);
        System.out.print("Which floor are you at now (0-10) where 0 = basement: ");
        choice1  =  Keyboard.readInt();

        if(floor == choice1)
        {
            System.out.println("Enter the elevator");
        }

        else if(floor > choice1)
        {
            ElevatorDown();
        }

        else if(floor < choice1)
        {
            ElevatorUp();
        }

        System.out.println("To which floor would you want to go (0-10) where 0 = basement");
        choice1 = Keyboard.readInt();

        if(floor > choice1)
        {
            ElevatorDown();
        }

        else if(floor < choice1)
        {
            ElevatorUp();
        }

    }

    public static void ElevatorUp()
    {
        System.out.println("The elevator is on it's way up...");

        for (person = choice1; choice1>=floor; floor++)

            System.out.println(floor);

        System.out.println("The elevator has arrived");
    }

    public static void ElevatorDown()
    {
        System.out.println("The elevator is on it's way down...");
        for (person = choice1; choice1<=floor; floor--)

            System.out.println(floor);

        System.out.println("The elevator has arrived");
    }
}

Java example for oracle connection

import java.sql.*;  
class OracleCon{  
    public static void main(String args[]){  
        try{  
            //step1 load the driver class  
            Class.forName("oracle.jdbc.driver.OracleDriver");  
              
            //step2 create  the connection object  
            Connection con=DriverManager.getConnection(  
            "jdbc:oracle:thin:@localhost:1521:xe","system","oracle");  
              
            //step3 create the statement object  
            Statement stmt=con.createStatement();  
              
            //step4 execute query  
            ResultSet rs=stmt.executeQuery("select * from emp");  
            while(rs.next())  
            System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  
              
            //step5 close the connection object  
            con.close();  
              
        }catch(Exception e){ System.out.println(e);}  
      
    }  
}

Python code to demonstrate example of requests.post() with json

# Hello World program in Python
import requests

result = requests.post('https://openapi.daocloud.io/v1/apps/28832ce5-0e21-42a2-8307-796a85045c3e/actions/restart',
  headers={"Authorization": "token q4c67rdvmtmkgee4hwgr3efj2vj0ucw7v74qk6qk"})

print(result.json())

Python code to demonstrate example of requests.post() with json and reading data from the file

import requests
import json
import urllib2
import time

webhook_url = 'https://discordapp.com/api/webhooks/355866897704550412/e3dmYfVXANhJaCnZJkbewLUHLLu7zjEmo0GnskJC9fYrcMjO6VFAgNzISGOKI0sddcFq'
slack_data = {} #"username":"IFTTT YouTube Test",

while True:
    data = urllib2.urlopen("https://drive.google.com/uc?export=download&id=0B8OPOPGiSJ7fZlB5SjFFcmF0a1E")
    
    a = data.readlines()
    
    if a[0][0] == "F":
        slack_data["content"] = "```No Premade Games Scheduled```"
    else:
        b = ""
        b = b.join(a[1:])
    
        slack_data["content"] = "```" + b + "```"
    
    
    response = requests.post(
        webhook_url, data=json.dumps(slack_data),
        headers={'Content-Type': 'application/json'}
    )
    break

Python example to print Hello World with a new line character

# Hello World program in Python
    
print "Hello World!\n"

Python example to read data from the file (Example 1)

import requests
import json
import urllib2
import time

webhook_url = 'https://discordapp.com/api/webhooks/355866897704550412/e3dmYfVXANhJaCnZJkbewLUHLLu7zjEmo0GnskJC9fYrcMjO6VFAgNzISGOKI0sddcFq'
slack_data = {} #"username":"IFTTT YouTube Test",

while True:
    data = urllib2.urlopen("https://drive.google.com/uc?export=download&id=0B8OPOPGiSJ7fZlB5SjFFcmF0a1E")
    
    a = data.readlines()
    
    if a[0][0] == "F":
        slack_data["content"] = "```No Premade Games Scheduled```"
    else:
        b = ""
        b = b.join(a[1:])
    
        slack_data["content"] = "```" + b + "```"
    
    
    response = requests.post(
        webhook_url, data=json.dumps(slack_data),
        headers={'Content-Type': 'application/json'}
    )
    break

C example to print multiple table by reading data from the table

c

#include <stdio.h>
int main()
{
    int n;
    int m;
    int cntr;
    long long product;
    FILE*ark = fopen("Tablas de Multiplicar.dat","w");
    printf("¿Qué tabla de multiplicar desea conocer (Registre número)\n");
    scanf("&d", m);
    printf("¿Hasta qué número la desea calcular? (Registe número)\n");
    scanf("%d", &n);
    for (cntr = 1;  n=1; n++)
    {
        product= m*n;
        printf("%d %lld\n", cntr, product);
        fprintf(ark, "%d %lld\n", cntr, product);
    }
    return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.