"Hello World!" in C

Sort by

recency

|

641 Discussions

|

  • + 0 comments
    import random
    import string
    password=""
    charlist=string.ascii_letters+string.digits+string.punctuation
    limit=int(input("enter the size of the password"))
    for i in range(limit):
        i=random.choice(charlist)
        password+=i
    
    print(password)
    
  • + 0 comments

    include

    include

    include

    include

    include

    include

    include

    include

    include

    include

    char* readline(); char* ltrim(char*); char* rtrim(char*);

    int parse_int(char*);

    /* * Complete the 'fizzBuzz' function below. * * The function accepts INTEGER n as parameter. */

    void fizzBuzz(int n) { for (int i = 1; i <= n; i++) { if (i % 3 == 0 && i % 5 == 0) { printf("FizzBuzz\n"); } else if (i % 3 == 0) { printf("Fizz\n"); } else if (i % 5 == 0) { printf("Buzz\n"); } else { printf("%d\n", i); } } }

    int main() { int n = parse_int(ltrim(rtrim(readline())));

    fizzBuzz(n);
    
    return 0;
    

    }

    char* readline() { size_t alloc_length = 1024; size_t data_length = 0;

    char* data = malloc(alloc_length);
    
    while (true) {
        char* cursor = data + data_length;
        char* line = fgets(cursor, alloc_length - data_length, stdin);
    
        if (!line) {
            break;
        }
    
        data_length += strlen(cursor);
    
        if (data_length < alloc_length - 1 || data[data_length - 1] == '\n') {
            break;
        }
    
        alloc_length <<= 1;
    
        data = realloc(data, alloc_length);
    
        if (!data) {
            data = '\0';
    
            break;
        }
    }
    
    if (data[data_length - 1] == '\n') {
        data[data_length - 1] = '\0';
    
        data = realloc(data, data_length);
    
        if (!data) {
            data = '\0';
        }
    } else {
        data = realloc(data, data_length + 1);
    
        if (!data) {
            data = '\0';
        } else {
            data[data_length] = '\0';
        }
    }
    
    return data;
    

    }

    char* ltrim(char* str) { if (!str) { return '\0'; }

    if (!*str) {
        return str;
    }
    
    while (*str != '\0' && isspace(*str)) {
        str++;
    }
    
    return str;
    

    }

    char* rtrim(char* str) { if (!str) { return '\0'; }

    if (!*str) {
        return str;
    }
    
    char* end = str + strlen(str) - 1;
    
    while (end >= str && isspace(*end)) {
        end--;
    }
    
    *(end + 1) = '\0';
    
    return str;
    

    }

    int parse_int(char* str) { char* endptr; int value = strtol(str, &endptr, 10);

    if (endptr == str || *endptr != '\0') {
        exit(EXIT_FAILURE);
    }
    
    return value;
    

    }

  • + 0 comments

    include

    include

    include

    include

    int main() { char s[100]; gets(s); printf("Hello, World! \n"); puts(s);
    return 0; }

  • + 0 comments

    int main() {

    char s[100];
    scanf("%[^\n]%*c", &s);
    
    printf("Hello, World! \n");
    printf(s);    
    return 0;
    

    }

  • + 0 comments
    //Boundary Traversal of a Binary Tree
    #include <iostream>
    #include <vector>
    using namespace std;
    
    struct Node {
        int val;
        Node *left, *right;
        Node(int x) : val(x), left(nullptr), right(nullptr) {}
    };
    
    void leftBoundary(Node* node, vector<int>& res) {
        if (!node || (!node->left && !node->right)) return;
        res.push_back(node->val);
        if (node->left) leftBoundary(node->left, res);
        else leftBoundary(node->right, res);
    }
    
    void leaves(Node* node, vector<int>& res) {
        if (!node) return;
        if (!node->left && !node->right) res.push_back(node->val);
        leaves(node->left, res);
        leaves(node->right, res);
    }
    
    void rightBoundary(Node* node, vector<int>& res) {
        if (!node || (!node->left && !node->right)) return;
        if (node->right) rightBoundary(node->right, res);
        else rightBoundary(node->left, res);
        res.push_back(node->val);
    }
    
    vector<int> boundaryTraversal(Node* root) {
        vector<int> res;
        if (!root) return res;
        res.push_back(root->val);
        leftBoundary(root->left, res);
        leaves(root->left, res);
        leaves(root->right, res);
        rightBoundary(root->right, res);
        return res;
    }
    
    int main() {
        Node* root = new Node(1);
        root->left = new Node(2);
        root->right = new Node(3);
        root->left->left = new Node(4);
        root->left->right = new Node(5);
        root->right->left = new Node(6);
        root->right->right = new Node(7);
        vector<int> res = boundaryTraversal(root);
        for (int x : res) cout << x << " ";
        return 0;
    }