Navigation

    ask avan logo
    • Register
    • Login
    • Search
    • Categories
    • Unsolved
    • Solved
    1. Home
    2. Solved
    Log in to post
    • All categories

    • Charles Craft50

      SOLVED Create a console application in C# that accepts three (3) programmer-defined values and save them to an array.
      C# • • Charles Craft50  

      2
      2
      Posts
      113
      Views

      avan

      I think they just want you to initialize an array add three values to it. Here is how you can initialize an array and add values to it.

      Method 1:

      int[] arr = new int[5] arr[0] = 1; arr[1] = 2; arr[2] = 3;

      Method 2:

      int[] arr =new int[5] { 1, 2, 3 };

      https://www.completecsharptutorial.com/basic/storing-values.php

      Here 1,2,3 are programmer-defined the values

      I am not a C# sharp developer so I don't know how to create a console application. I found the following article that might need help get started in case you are confused about that part:

      https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code

      The only part I can't figure out if the one-line instructions above is asking for the values to be inputted through the command prompt. In that case you can use args in the main method to retrieve the command line arguments. The following article should have more info and even some examples.

      https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/main-and-command-args/command-line-arguments

      I hope this helps in some way.

    • Rachel O

      SOLVED Argument for getc to check for EOF is not working.
      C • • Rachel O  

      4
      4
      Posts
      61
      Views

      avan

      Hey @Rachel-O

      I finally figured it out. Sorry, it took me a while. I am not a C developer. But anyways, I have the answer in video format. Check it out. I also included the code down below in case you don't want to watch the video version and just want the answer.

      Let me know if you have any questions or if I can be of further help.

      #include <stdio.h> #include <stdlib.h> #include <string.h> // Include boolean #include <stdbool.h> int main(int argc, char *argv[]) { // Global variables FILE *input, *output; char c; int sentenceCounter=1,wordCounter=0; // Will be set to true whenever we encounter a period bool newSentence = true; // Make sure input and output files are specified if (argc < 3) { fprintf (output, "\nCorrect usage is: ./mimir.out <name of input file> <name of output file>\n\n"); exit(EXIT_FAILURE); } // Make sure we can open input file if((input = fopen(argv[1], "r")) == NULL) { fprintf (output, "\nUnable to open input file \"%s\".\n\n", argv[1]); exit(EXIT_FAILURE); } // Let's start the process else { // Open output stream output=fopen(argv[2],"w"); // START READING INPUT FILE HERE c = getc(input); // As long as we have not reached the end of the input file while (c != EOF) { // New line marker? if(newSentence){ fprintf (output, "Sentence # %d\n",sentenceCounter++); fprintf (output, "--------------------------------------------------------------------------------\n"); newSentence = false; } // Process a single word while (c != ' ' && c != '\n' && c != ',' && c != '.'){ fprintf(output,"%c", c); c = getc(input); } // We have reached a new line, comma, space or period. So a new word. wordCounter++; // Period encountered. Set new sentence marker if(c == '.'){ newSentence = true; fprintf(output,"\n\n"); } // Have we reached 10 words yet? If so hit a new line. No comma needed. if(wordCounter == 10){ fprintf(output,"\n"); } // Otherwise comma is needed. else if(c == ' ' || c == ',' || c == '\n'){ fprintf(output,", "); } // Reset word counter? if(newSentence || wordCounter == 10){ wordCounter = 0; } // Consume empty space, period, comma and new line while (c == ' ' || c == '.' || c == ',' || c == '\n'){ c = getc(input); } } // End while c != EOF } fclose(input); return 0; }
    • Shavy Gaming

      SOLVED Write algorithms to add and delete elements from either end of the deque.
      C • • Shavy Gaming  

      2
      2
      Posts
      325
      Views

      avan

      Hey @Shavy-Gaming

      I don't know C but with a little bit of googling I was able to find a Java implementation of a deque using a one-dimensional array.

      Here is the link:

      https://codereview.stackexchange.com/questions/120722/array-based-deque-in-java

      Here is the solution found on the page. You might be able to understand it enough to implement a C version of it. Keep in mind the main method just tests the Deque in this case. Good luck!

      import java.util.NoSuchElementException; import java.util.Random; public class Deque { private final int arr[]; private int head; private int size; public Deque(int capacity) { arr = new int[capacity]; } public void addLast(int element) { checkCapacity(); arr[(head + size++) % arr.length] = element; } public void addFirst(int element) { checkCapacity(); if (head == 0) { arr[(head = arr.length - 1)] = element; } else { arr[(--head) % arr.length] = element; } size++; } public int removeFirst() { checkNotEmpty(); int ret = arr[head]; head = (head + 1) % arr.length; size--; return ret; } public int removeLast() { checkNotEmpty(); int ret = arr[(head + size - 1) % arr.length]; size--; return ret; } @Override public String toString() { StringBuilder sb = new StringBuilder("["); for (int i = 0; i < size; ++i) { sb.append(arr[(head + i) % arr.length]); if (i < size - 1) { sb.append(", "); } } return sb.append("]").toString(); } public int size() { return size; } private void checkCapacity() { if (arr.length == size) { throw new IllegalStateException("No more space is available."); } } private void checkNotEmpty() { if (size == 0) { throw new NoSuchElementException("Trying to pop an empty deque."); } } public static void main(String args[]) { Deque deque = new Deque(10); Random random = new Random(); for (int op = 0; op < 30; ++op) { if (deque.size() == 0) { int num = random.nextInt(100); System.out.print("Adding " + num + " to front: "); deque.addLast(num); System.out.println(deque); } else { boolean add = random.nextBoolean(); if (add) { boolean front = random.nextBoolean(); int num = random.nextInt(100); if (front) { System.out.print("Adding " + num + " to front: "); deque.addFirst(num); System.out.println(deque); } else { System.out.print("Adding " + num + " to back: "); deque.addLast(num); System.out.println(deque); } } else { boolean front = random.nextBoolean(); if (front) { System.out.print("Removing from front: "); deque.removeFirst(); System.out.println(deque); } else { System.out.print("Removing from back: "); deque.removeLast(); System.out.println(deque); } } } } } }
    • S

      SOLVED Using Mysql results to populate html
      Javascript + jQuery • ejs javascript mysql • • sequelman  

      10
      10
      Posts
      47
      Views

      S

      Now I can add the 20 other fields in need in that form. 😁

      Thanks again for your help I really appreciate it.

    • I

      SOLVED hey avan can you teach me how to deobfuscate this javascript code to make it readable again ?
      Javascript + jQuery • • imnoob  

      2
      2
      Posts
      53
      Views

      avan

      Hey @imnoob

      Took me a long time but here you go 🙂

      https://codepen.io/avansardar/pen/zYrgmJb?editors=0010

    • Ayush Gwari 0

      SOLVED Pattern problem
      Coding Question & Answers • • Ayush Gwari 0  

      3
      3
      Posts
      54
      Views

      Ayush Gwari 0

      Hey thanks avan for clearing my doubt regarding this problem and special thanks for explaining the solution very clear in video format.

    • Mying Humtsoe

      SOLVED can anyone one help me know to solve this...i am new to coding and i really confused.
      Coding Question & Answers • • Mying Humtsoe  

      3
      3
      Posts
      204
      Views

      Mying Humtsoe

      @avan thank you so much sir from the deepest of my heart, i have spent days trying to find answer to this problem and googling for solution but failed and i wanted to give up, you are a life saver 😥 😭

    • Alan Daniel

      SOLVED Matlab : How can I automatically let Matlab input the file in sequence?
      Coding Question & Answers • • Alan Daniel  

      5
      5
      Posts
      43
      Views

      Alan Daniel

      Thanks a lot. You are brillant!

    • Alan Daniel

      SOLVED How to retrieve data from a specific REST endpoint. (prefer using Python)
      Python • • Alan Daniel  

      5
      5
      Posts
      65
      Views

      Alan Daniel

      @avan said in How to retrieve data from a specific REST endpoint. (prefer using Python):

      equests.get(url = URL)

      extracting data in json format

      data = r.json()

      Get value for blobJson

      blobJson = data[0]["blobJson"]

      Convert string to list

      yes, thanks! it works well!

    • AshutoshxxTeotia

      SOLVED why this code is not giving o/p as 3?
      C • • AshutoshxxTeotia  

      2
      2
      Posts
      9
      Views

      avan

      Hey @AshutoshxxTeotia

      How about something like this

      main(); int main() { printf("%d",tried(1,2)); } void tried(int a,int b) { int c=a+b; return c; }
    • C

      SOLVED Adding classes to javascript onhover code
      Javascript + jQuery • • cthornval  

      5
      5
      Posts
      21
      Views

      C

      Hey Avan! thanl you so much it worked!

    • Ayush gwari

      SOLVED Getting array out of bound exception in given problem
      Java • • Ayush gwari  

      3
      3
      Posts
      10
      Views

      avan

      Hey @Ayush-gwari

      Did that work for you? If so, do you mind marking my answer as the correct one. Thank you.

    • AshutoshxxTeotia

      SOLVED why this code is not working guys!
      Coding Question & Answers • • AshutoshxxTeotia  

      3
      3
      Posts
      13
      Views

      AshutoshxxTeotia

      you are right bro I got it just look at the last variable in the same line.

    • Lpokimo

      SOLVED Java Game engine Problem
      Java • • Lpokimo  

      10
      10
      Posts
      38
      Views

      avan

      @Lpokimo said in Java Game engine Problem:

      input = new Input(null); (This

      In your version you have

      input = new Input(null);

      in original version it is correct

      input = new Input(this);

      Line 26 in GameContainer.java file

    • Frankie Pa21

      SOLVED I know it is not coding but i was hoping you could help Trouble with math
      Coding Question & Answers • • Frankie Pa21  

      2
      2
      Posts
      16
      Views

      avan

      Hey Boonie!

      Not sure what they mean by 'best' prediction but every time you roll a die you get a 1 in 6 (or 1/6) chance that you roll a six. So if you roll it 6 times you just have to multiple 1/6 by 6 So

      1/6 * 6 = 1

      So my guess would be 1. I hope that helps boonie.

    • William W. Hensley

      SOLVED Creating a list from the the intersection of two lists containing unique integers
      Python • • William W. Hensley  

      5
      5
      Posts
      11
      Views

      William W. Hensley

      Thanks! This works and it only takes up 4 lines of code. The computation time is also much faster than my code. I think that I understand why it works faster as well. Your code executes after looping 23 times. However, my code executes after 11 iterations of 23 or 253 iterations which is 11 times more than my code. Also, it took 13.7 milliseconds, whereas as mine took 185 milliseconds which is 13.5 times as fast. I suspect that the method that I used where I changed my list into a set and then returned to transform it into a list also took more time than your method you recommended to me, which could partially explain the discrepancy in computation time as well.

    • Tony Cardinal

      SOLVED python code with tensorflow does not work
      Python • • Tony Cardinal  

      4
      4
      Posts
      156
      Views

      avan

      @Tony-Cardinal said in python code with tensorflow does not work:

      module 'tensorflow' has no attribute 'div'

      This might be a Tensorflow 2.0 versus 1.0 issue? I don't program in python but I found the following stackoverflow answer that might help:

      https://stackoverflow.com/questions/55142951/tensorflow-2-0-attributeerror-module-tensorflow-has-no-attribute-session

      If I am right you can do something like:

      tf.compat.v1.div(x,y)

      or

      import tensorflow.compat.v1 as tf tf.disable_v2_behavior()
    • William W. Hensley

      SOLVED PYTHON: Checking Primality of Integers
      Python • python3 • • William W. Hensley  

      10
      10
      Posts
      12
      Views

      William W. Hensley

      ok, I understand now

    • MPG Radio

      SOLVED Parsing m3u from single column to two equal columns
      PHP • • MPG Radio  

      5
      5
      Posts
      19
      Views

      MPG Radio

      got it going and works just fine with some minor adjustments to fit the application.
      demo

      function outputPlaylist($playlist) { $entries = parse_m3u($playlist); echo "<div class='row'>\n"; echo "<pre>\n"; $size = sizeof($entries); $size_half = ceil($size / 2); $counter = 0; echo "<div class='row'>\n"; echo "<div class='column'>\n"; foreach($entries as $entry) { // Check for half way point if($counter++ == $size_half ){ // Close column and open new one echo "</div>\n"; } printf ("%s\n", $entry['title'], $entry['artist'] ); } // Close column and row echo "</div>\n"; echo "</pre>"; echo "</div>\n"; } ?>
    • MPG Radio

      SOLVED Adding an extention .txt to a saved file from checkbox selections
      PHP • • MPG Radio  

      3
      3
      Posts
      16
      Views

      MPG Radio

      That's so weird it works with this change..

      $name = time(); $txtName = $name . ".txt"; $myFile=fopen($txtName,"a"); $txt = $VarCheck; fwrite($myFile,$txt); fclose($myFile);