Tutorialspoint

Programming Examples

Compile and Execute C Online

c

#include <stdio.h>
#include<stdlib.h>
#define MAX 255
int main()
{
    char arr[MAX]={'\0'};
    //char *ar;
    char split[MAX][MAX];
    int i=0,j=0;
    //ar=arr;
    //gets(arr);
    fgets(arr,MAX,stdin);
    
    for(int k=0;arr[k]!='\0';k++){
        
        
        
        if(arr[k]==' ' || arr[k]=='\n'){
            split[i][j]='\0';
            i++;
            j=0;
            continue;
        }
        
        split[i][j]=arr[k];
        j++;
    }
    
    
    for(int m=i;m>=0;m--){
        for(int n=0;split[m][n]!='\0';n++){
            printf("%c",split[m][n]);
        }
        printf("\b ");
    }
    
    
    
    
    

    return 0;
}

15220013-Edit Dosen

<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Bootstrap -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
      <h1>EDIT DOSEN</h1>
  <form>
      <div class="form-group row">
    <label for="" class="col-sm-2 col-form-label">NIDN</label>
      <input type="" class="form-control" id="" placeholder="">
    </div>
     <div class="form-group row">
    <label for="" class="col-sm-2 col-form-label">NAMA</label>
      <input type="" class="form-control" id="" placeholder="">
    </div>
  </form>
  
    <button type="button" class="btn btn-primary btn-sm">Update</button>
    <button type="button" class="btn btn-secondary btn-sm">Batal</button>

    
 </body>
</html>

15220013-Daftar Dosen

<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Bootstrap -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <h1>DAFTAR DOSEN</h1>
    <button type="button" class="btn btn-primary">Tambah</button>
   <table class="table">
  <thead class="thead-inverse">
    <tr>
      <th>NO</th>
      <th>NIDN</th>
      <th>NAMA</th>
      <th>TINDAKAN</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>05892897</td>
      <td>Lindung Siswanto</td>
      <td><button type="button" class="btn btn-success">Edit</button>
      <button type="button" class="btn btn-danger">Hapus</button></td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>08673490</td>
      <td>Sri Hasta</td>
      <td><button type="button" class="btn btn-success">Edit</button>
      <button type="button" class="btn btn-danger">Hapus</button></td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td>05796135</td>
      <td>Ali Purwito</td>
      <td><button type="button" class="btn btn-success">Edit</button>
      <button type="button" class="btn btn-danger">Hapus</button></td>
    </tr>
  </tbody>
</table>
  </body>
</html>

Execute Ruby Online

# @param {String} s
# @param {String} t
# @return {Boolean}
def is_anagram(s, t)
    hash = Hash.new(0)
    hash1 = Hash.new(0)
    s.each_char do |v|
        hash.store(v, hash[v]+1)
    end
    t.each_char do |v|
        hash1.store(v, hash1[v]+1)
    end
    p hash == hash1
end

is_anagram("rat","cat")

hello

BEGIN TRANSACTION;

/* Create a table called NAMES */
CREATE TABLE NAMES(Id integer PRIMARY KEY, Name text);

/* Create few records in this table */
INSERT INTO NAMES VALUES(1,'Tom');
INSERT INTO NAMES VALUES(2,'Lucy');
INSERT INTO NAMES VALUES(3,'Frank');
INSERT INTO NAMES VALUES(4,'Jane');
INSERT INTO NAMES VALUES(5,'Robert');
COMMIT;

/* Display all the records from the table */
SELECT * FROM NAMES;

rgwrgf

Program HelloWorld(output);
var
jmeno: string;

begin
write('Zadej jmeno:');
read(jmeno);
writeln;
  writeln('Nazdar',jmeno);
end.

des1

import javax.swing.*;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Random ;
class DES {
byte[] skey = new byte[1000];
String skeyString;
static byte[] raw;
String inputMessage,encryptedData,decryptedMessage;

public DES() {
try {
generateSymmetricKey();

inputMessage=JOptionPane.showInputDialog(null,"Enter message to encrypt");
byte[] ibyte = inputMessage.getBytes();
byte[] ebyte=encrypt(raw, ibyte);
String encryptedData = new String(ebyte);
System.out.println("Encrypted message "+encryptedData);
JOptionPane.showMessageDialog(null,"Encrypted Data "+"\n"+encryptedData);

byte[] dbyte= decrypt(raw,ebyte);
String decryptedMessage = new String(dbyte);
System.out.println("Decrypted message "+decryptedMessage);

JOptionPane.showMessageDialog(null,"Decrypted Data "+"\n"+decryptedMessage);
}
catch(Exception e) {
System.out.println(e);
}

}
void generateSymmetricKey() {
try {
Random r = new Random();
int num = r.nextInt(10000);
String knum = String.valueOf(num);
byte[] knumb = knum.getBytes();
skey=getRawKey(knumb);
skeyString = new String(skey);
System.out.println("DES Symmetric key = "+skeyString);
}
catch(Exception e) {
System.out.println(e);
}
}
private static byte[] getRawKey(byte[] seed) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("DES");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(seed);
kgen.init(56, sr);
SecretKey skey = kgen.generateKey();
raw = skey.getEncoded();
return raw;
}
private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "DES");
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
}

private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "DES");
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decrypted = cipher.doFinal(encrypted);
return decrypted;
}
public static void main(String args[]) {
DES des = new DES();
}
}

Compile and Execute Verilog Online

/* 
 * Do not change Module name 
*/
module main;
  initial 
    begin
      $display("Hello, World");
      $finish ;
    end
endmodule

Compile and Execute Java Online

package code;
public class Trial{
	public static void main(String[] args)
	{
		new Trial().one(1,1);
	}
	 void one(int a,int b,int... c)
	 {
		 System.out.println("one");
	 }
}

Monty_Hall_problem

# Monty Hall simulator
# https://stackoverflow.com/questions/1247863/is-this-a-good-or-bad-simulation-for-monty-hall-how-come
import random

iterations = 100000

doors = ["goat"] * 2 + ["car"]
change_wins = 0
change_loses = 0

for i in xrange(iterations):
    # shuffle the doors
    random.shuffle(doors)
    # you pick door n:
    first_choice = random.randrange(3)
    # Monty picks door: a random door !=firt_choice, !="car"
    sequence = range(3)
    # Monty random sort the doors
    random.shuffle(sequence)
    for host_try_door in sequence:
        if host_try_door == first_choice or doors[host_try_door ] == "car":
            #this random door cannot be opened, try next
            continue
    # now if you change, you lose iff doors[n]=="car"
    if doors[first_choice] == "car":
        change_loses += 1
    else:
        change_wins += 1

print( "Changing has %s wins and %s losses" % (change_wins, change_loses))
perc = (100.0 * change_wins) / (change_wins + change_loses)
print ("by changing you win %.1f%% of the time" % perc)

Advertisements
Loading...

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