Search:

Type: Posts; User: john.c

Page 1 of 20 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    4
    Views
    177

    #include #include //...

    #include <stdio.h>
    #include <stdlib.h>

    // Print array a of size n on a single line.
    void print(int* a, int n)
    {
    for (int i = 0; i < n; i++)
    printf("%d ", a[i]);
    ...
  2. Of course. But I'm not sure I understand what you...

    Of course. But I'm not sure I understand what you mean. :confused:



    #include <stdio.h>

    int main()
    {
    printf("Hello\n"); // happens once, then never again
  3. Replies
    3
    Views
    128

    It really isn't very complicated. Asking the...

    It really isn't very complicated.
    Asking the user for the number of digits in the input number is not a good solution since the program can calculate that (which is what mag is for).
    Here it is...
  4. If you get rid of the break and let the loop...

    If you get rid of the break and let the loop condition stop the loop, then the loop increment will run once more so the final printf, after the loop, will need to print p - 1 (as in my second example...
  5. Replies
    3
    Views
    128

    Perhaps: #include typedef...

    Perhaps:


    #include <stdio.h>

    typedef unsigned long long ull;

    int main()
    {
    ull n;
  6. You need to learn to: * properly indent your...

    You need to learn to:
    * properly indent your code;
    * stop using goto (use while and for instead)
    * use arrays
    * use functions
    * don't flush(stdin)
  7. Replies
    43
    Views
    690

    pass

    pass
  8. #include #include int...

    #include <stdio.h>
    #include <stdbool.h>

    int main ()
    {
    int nth_prime;
    printf("What prime number do you want to find: ");
    scanf("%d", &nth_prime);

    int p = 2;
  9. There is no "solved" marker. :cool:

    There is no "solved" marker. :cool:
  10. The entire standard library (libc) is available...

    The entire standard library (libc) is available by default. I believe the library option is -lc, but you don't need to manually add that.

    However, for historical reasons, the math library (libm)...
  11. Replies
    43
    Views
    690

    Using a bitmap is a pretty good idea. You could...

    Using a bitmap is a pretty good idea. You could store the numbers that way without converting to an int array. Then it's easy to compare to the drawn number to count matches.

    I set the code for...
  12. Replies
    43
    Views
    690

    The reason I didn't do it that way is to get the...

    The reason I didn't do it that way is to get the values in sorted order. I would change one thing in my original code, though, which is to use position 0 in the used array.


    void...
  13. Thread: Size_t problem

    by john.c
    Replies
    1
    Views
    96

    It's hard to understand what you are trying to...

    It's hard to understand what you are trying to do, but maybe:


    #include <stdio.h>
    #include <string.h>

    int main() {
    char s1[100], s2[100];
    printf ("Introduza duas strings: ");
    ...
  14. Replies
    43
    Views
    690

    #include #include #include...

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    #define NUM_TO_PICK 6
    #define HIGH_NUM 49

    void generate_ticket(int *ticket) {
    int used[HIGH_NUM + 1] = {0}; // initialized...
  15. Replies
    18
    Views
    226

    Neither gcc nor clang (with -std=c99 -Wall -W...

    Neither gcc nor clang (with -std=c99 -Wall -W -pedantic) gives an error or warning.


    // file1.c ///////////////////////////////
    #include <stdio.h>

    int Global_Variable;

    void...
  16. I didn't even think of boiling it down to a...

    I didn't even think of boiling it down to a single equation. That's pretty nifty. As written it will overflow at a lower value (49796), which I guess is an advantage of doing it in pieces. Your...
  17. Comparing the brute force and the smarter...

    Comparing the brute force and the smarter solution for an input of 4 billion:
    * the first does 4 billion additions to sum, 4 billion increments of i, 4 billion comparisons, and 4 billion jumps back...
  18. Replies
    15
    Views
    292

    I was able to recreate the problem and then fix...

    I was able to recreate the problem and then fix it again. :biggrin:
  19. Replies
    15
    Views
    292

    It is not in your interest to be a dick. I spent...

    It is not in your interest to be a dick.
    I spent the last 10 minutes finding the answer, but now I don't feel like posting it.
  20. Replies
    15
    Views
    292

    How about if you just use char instead of...

    How about if you just use char instead of unsigned char?

    (And you never said anything about trying it in a new project, so I asked.)
  21. Replies
    15
    Views
    292

    Doesn't seem possible, does it. Did you start a...

    Doesn't seem possible, does it.
    Did you start a new project, copy paste the code, and run it?
  22. Replies
    15
    Views
    292

    It should be: #include int...

    It should be:


    #include <iostream>

    int main() {
    std::cout << "12" << static_cast<unsigned char>(133) << "34" << '\n';

    // or
    std::cout << "12" << (unsigned char)(133) << "34"...
  23. Replies
    10
    Views
    281

    It ultimately stems from the fact that in a...

    It ultimately stems from the fact that in a multi-user machine, memory initially allocated to a new process is zeroed by the OS, lest it contain information from a previous process, possibly run by a...
  24. Your code does get the correct answer. There's...

    Your code does get the correct answer.
    There's no reason to worry about overflow with limit set to 100, alghouth if it was necessary you can calculate it using the forumula for the sum of numbers...
  25. Thread: Writing a Code

    by john.c
    Replies
    8
    Views
    248

    Only very special values of y (magical values...

    Only very special values of y (magical values indeed) will create a trapeze.
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4