• Forums
  • View New Posts
  • View Today's Posts
  • Search
  • Members
  • Calendar
  • Help
  • Extras
Forum stats
Show team
View New Posts
View Today's Posts
Lowlands Tactical: Forum
Login to account Create an account
Login
Username/Email:
Password: Lost Password?
 

  Lowlands Tactical: Forum Publiek Speeltuin
1 2 Next »
De grote programmeer opdracht 2016!

Thread Modes
De grote programmeer opdracht 2016!
Sacha Offline
Administrator
*******
Posts: 1,305
Threads: 266
Joined: Aug 2014
Reputation: 7
#1
08-10-2016, 03:13 PM (This post was last modified: 08-10-2016, 03:14 PM by Sacha.)
Neem de taal die je kent en laat zien wat je kan en hoe dit eruit ziet:
Archu Wrote:-Create an array of ten integers
-Fill the array with ten random numbers (1-100)
-Copy the array (into another array of the same capacity)
-Change the last value in the first array to a -7
-Display the contents of both arrays

Toon hier jullie resultaten!
Website Find
Reply
Sacha Offline
Administrator
*******
Posts: 1,305
Threads: 266
Joined: Aug 2014
Reputation: 7
#2
08-10-2016, 03:15 PM (This post was last modified: 08-10-2016, 03:16 PM by Sacha.)
Code:
#!/usr/bin/env python3
import random
myArray = []
for n in range(0,10):
 myArray.append(random.randint(1,100))
urArray = myArray.copy()
myArray[-1] = -7
print("1st Array: "+str(myArray)+"\n"+"2nd Array: "+str(urArray))

Result Wrote:$ ./test.py
1st Array: [32, 67, 97, 67, 5, 23, 53, 33, 4, -7]
2nd Array: [32, 67, 97, 67, 5, 23, 53, 33, 4, 63]
Website Find
Reply
PingWing Offline
Lid
**
Posts: 54
Threads: 16
Joined: Dec 2014
Reputation: 0
#3
08-10-2016, 03:44 PM (This post was last modified: 08-10-2016, 03:45 PM by PingWing.)
Voor PHP:

PHP Code:
$arr1 = array();
for(
$i = 0; $i < 10; $i++){
   $arr1[] = rand(0, 99);
}
$arr2 = $arr1;
$arr1[9] = -7;
var_dump($arr1,$arr2); 



Code:
# Result:
array (size=10)
 0 => int 93
 1 => int 80
 2 => int 53
 3 => int 49
 4 => int 85
 5 => int 87
 6 => int 52
 7 => int 33
 8 => int 39
 9 => int -7
array (size=10)
 0 => int 93
 1 => int 80
 2 => int 53
 3 => int 49
 4 => int 85
 5 => int 87
 6 => int 52
 7 => int 33
 8 => int 39
 9 => int 14
Find
Reply
Archu Offline
Lid
**
Posts: 43
Threads: 4
Joined: Sep 2014
Reputation: 2
#4
08-10-2016, 04:00 PM
Fur Java:

Code:
public class CopyArrays {

    static ArrayList arr1 = new ArrayList();
    static ArrayList arr2;

    private static ArrayList<Integer> randomize(ArrayList<Integer> array) {

        Integer cnt1;
        Random rndm = new Random();

        for (int i = 0; i < 10; i++) {
            cnt1 = rndm.nextInt(100);
            array.add(cnt1);
        }
        return array;
    }

    public static void main(String[] args) {

        randomize(arr1);
        arr2 = (ArrayList<String>) arr1.clone();
        arr1.set(9, "-7");

        System.out.println("Array 1: " + arr1 + "\n" + "Array 2: " + arr2);
    }
}


Result:
Quote:Array 1: [77, 38, 3, 37, 58, 48, 27, 18, 16, -7]

Array 2: [77, 38, 3, 37, 58, 48, 27, 18, 16, 42]
Find
Reply
Sacha Offline
Administrator
*******
Posts: 1,305
Threads: 266
Joined: Aug 2014
Reputation: 7
#5
08-10-2016, 07:31 PM
PHP Code:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main()
{
  
int myArray[10];
  
int urArray[10];
  
int i, j;
  
time_t t;

  
/* Seed with me */
  
srand((unsigned) time(&t));

  for (
i=0;i<10;i++) {
    
myArray[ i ] = rand() % 100;
  }

  for (
i=0;i<10;i++) {
    
urArray[i] = myArray[i];
  }

  
myArray[9] = -7;

  
printf("1st Array: ");
  for (
j=0;j<10;j++) {
    
printf("%d ",myArray[j]);
  }
  
printf("\n");

  
printf("2nd Array: ");
  for (
j=0;j<10;j++) {
    
printf("%d ",urArray[j]);
  }
  
printf("\n");

} 

Code:
$ ./a.out
1st Array: 39 63 41 96 97 47 79 45 30 -7
2nd Array: 39 63 41 96 97 47 79 45 30 31
Website Find
Reply
Sacha Offline
Administrator
*******
Posts: 1,305
Threads: 266
Joined: Aug 2014
Reputation: 7
#6
08-11-2016, 11:09 AM
Een externe contributie:

PHP Code:
#!/bin/bash

declare -a myArray
for i in `seq 0 9`; do myArray[$i]=$(($(random -er 100;echo $?)+1)); done
for index in "${!myArray[@]}"; do newArray[$index]=${myArray[$index]}; done
myArray
[$index]=-7;
B=$index;
A=0;echo -n "1st Array:[";for index in "${!myArray[@]}"; do echo -n ${myArray[$index]}; if [ $A -lt $B ]; then echo -n ","; fi;A=$(($A+1)); done; echo \];
A=0;echo -n "2nd Array:[";for index in "${!newArray[@]}"; do echo -n ${newArray[$index]}; if [ $A -lt $B ]; then echo -n ","; fi;A=$(($A+1)); done; echo \]; 
Website Find
Reply
Share Thread:            


  • View a Printable Version
  • Subscribe to this thread


Users browsing this thread:
1 Guest(s)

  • Contact Us
  • Forum team
  • Forum stats
  • Return to Top
 
  • RSS Syndication
  • Lite mode
  • Lowlands Tactical
  • Help
 
Forum software by © MyBB - Theme © iAndrew 2014



Linear Mode
Threaded Mode