Tutorialspoint

isaactellezaranda@gmail.com

c

#include<stdio.h>

int main()
{
    int m;
    int g;
    int h1;
    int h2;
    int vi;
    int vf;
    int s;
    float f;
    printf("Dame la masa\n");
    scanf("%d",& m);
    printf("Dame la gravedad\n");
    scanf("%d",& g);
if (g==0)
{
    printf("La gravedad es incorrecta\n");
     do{ 
    printf("Ingresa otra gravedad\n");
    scanf("%d", & g);
       }while (g>0);
}
else 
{
    printf("La gravedad es correcta\n");
}
    
    printf("Dame la altura\n");
    scanf("%d",& h1);
    printf("Dame la altura 2\n");
    scanf("%d",& h2);
    if (h2==h1)
{
    printf("Las alturas no pueden ser iguales\n");
     do{ 
    /*printf("Recuerda que la altura h1 tiene que ser mayor\n")*/
    printf("Ingresa altura 1\n");
    scanf("%d", & h1);
    printf("Ingresa altura 2\n");
    scanf("%d", & h2);
    
       }while (h1>h2);
}
else 
{
    printf("Las alturas son correctas\n");
}
    printf("Dame la velcidad inicial\n");
    scanf("%d",& vi);
    printf("Dame la velcidad final\n");
    scanf("%d",& vf);
    printf("Dame el desplazamiento\n");
    scanf("%d",& s);
f=((m*g*(h2-h1))+(1/2*m*(vi^2-vf^2)))/(s*(-1));
    printf("el valor de la fuerza de friccion es: %d\n,f");

    return 0;
}

Compile and Execute Pascal Online

Program HelloWorld(output);
begin
  writeln('Hello, world!');
end.

D108 Sample

Program D108Sample;

var
   a, b, c : integer;
   op1, op2, sp : char;

begin
  readln(a,sp,op1,sp,b,sp,op2,sp,c);
  
  writeln(a,op1,b,op2,c);
end.

Execute Python-3 Online

import random

spaces = 45 
player1 = 0
player2 = 0
player3 = 0
player4 = 0
dice = 0

while player1 < spaces or player2 < spaces:
    #Player 1's turn
    dice = random.randint(1, 6)
    print("Dice: " + str(dice))
    player1 += dice
    print("Player 1: " + str(player1))
    
    if player1 >= spaces:
        break
    #Player 2's turn
    dice = random.randint(1, 6)
    print("Dice: " + str(dice))
    player2 += dice
    print("Player 2: " + str(player2))
    
    if player2 >= spaces:
        break

    dice = random.randint(1, 6)
    print("Dice: " + str(dice))
    player3 += dice
    print("Player 3: " + str(player3))
    
    if player3 >= spaces:
        break
    
    dice = random.randint(1, 6)
    print("Dice: " + str(dice))
    player4 += dice
    print("Player 4: " + str(player4))
    
    if player4 >= spaces:
        break
    
if player1 > player2 and player1 > player3 and player1 > player4:
    print("Player 1 wins")
if player2 > player1 and player2 > player3 and player2 > player4:
    print("Player 2 wins")
if player3 > player1 and player3 > player2 and player3 > player4:
    print("Player 3 wins")
if player4 > player1 and player4 > player2 and player4 > player3:
    print("Player 4 wins")
if player1 == player2 and player1 == player3 and player1 == player4:
    print("Tie")

print("End")

Compile and Execute C Online

c

#include <stdio.h>

int main()
{
    printf("Hello, World!\n");

    return 0;
}

2 sum

def twosum(lst,target):
    if len(lst) < 2:
        return None
    d = {}
    numset = set()
    for index,val in enumerate(lst):
        if target-val in d:
            numset.add((d[target-val],index))
        else:
            d[val] = index
    return numset        
            
#print twosum([1,0,-1,2,-2],0)         

assert(twosum([1,0,-1,2,-2],0)) == set([(3, 4), (0, 2)])
assert(twosum([1],0)) == None
assert(twosum([],0)) == None

2 sum closest with multiple pairs

def targetsum(lst,target):
    lst = list(set(lst))
    n = len(lst)
    if n < 1:
       return None
    if n == 1:
        return [(0,1)]
    l = 0
    r =  n-1
    min_l = 0
    min_r = n-1
    minsum = 999999
    d = {}
    minvalue = 9999
    res =[]
    
    while l < r:
        sm = lst[l] + lst[r]
        
            
        if abs(sm) < abs(minsum):
            minsum = sm
            min_l = l
            min_r = r
        
        d[(lst[l],lst[r])] =abs(sm) 
        
        if sm < target:
            l = l+1
        
        if sm >= target:
            r = r -1
    for k,v in d.items():
        if v == abs(minvalue):
            res.append(k)
        if v < abs(minvalue):
            minvalue = v
            res = [] 
            res.append(k)
    return res
print targetsum([-1,0,1,2,2,-2],0)
    
assert(targetsum([-1,0,1,2,2,-2],0)) == [(2, -2), (1, -1)]
assert(targetsum([2,2],0)) == [(0, 1)]
assert(targetsum([],0)) == None

Compile and Execute C Online

c

#include <stdio.h>

 int main()
 {
  /* for loop execution */
  for ( int a = 10; a < 20; a = a + 1)
  {
      printf("value of a: %d\n", a);
  }
    return 0;
 }
             
     
 
 

STEVE

# Hello World program in Python
#DIVISION

import sys
import math
print("Stephen")
divide = 17
x = 75
total = (x/divide)
print("remainder is ")
print(total)

2Sum

def twosum(lst,target):
    if len(lst) < 2:
        return None
    d = {}
    numset = set()
    for index,val in enumerate(lst):
        if target-val in d:
            numset.add((d[target-val],index))
        else:
            d[val] = index
    return numset        
            
#print twosum([1,0,-1,2,-2],0)         

assert(twosum([1,0,-1,2,-2],0)) == set([(3, 4), (0, 2)])
assert(twosum([1],0)) == None
assert(twosum([],0)) == None

    

Advertisements
Loading...

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