Guidelines for adding C++/Java/Python/C#/JavaScript code to existing articles of GeeksforGeeks

Last Updated : 08 Aug, 2022

You may please first go through code writing instructions: Guide to write an article

Guidelines for writing code for an existing code on GeeksforGeeks:

  1. This guideline is for those who directly write in https://write.geeksforgeeks.org/. To write code in multiple languages use the format shown below:
    Click on the Add Code button present in the Toolbar provided.
    Improve-Article-02

    Click on the Add Another Language button and further select the language to be added from the drop-down list provided.
    Improve-Article-03

    Use the Arrow Keys to change the sequence of the codes.
    Improve-Article-04

    To Format your code, use the Format button provided. Further, use the Run button to check if your code generates the correct output and click on the Proceed button to add your code with the other existing codes.
    Improve-Article-05

  2. Please note that all of these attributes must match in all the programs:
    1. Variable names
    2. Function names
    3. Comments
    4. Output
    5. Approach used (Say, if stack is used to solve a problem, then all problems MUST be solved using stack)

    See the following examples:

    C++

    // C++ program to find factorial of given number
    #include <iostream>
    using namespace std;
    
    // function to find factorial of given number
    unsigned int factorial(unsigned int n)
    {
        if (n == 0)
            return 1;
        return n * factorial(n - 1);
    }
    
    // Driver code
    int main()
    {
        int num = 5;
        cout << "Factorial of "
            << num << " is " << factorial(num) << endl;
        return 0;
    }
    
    // This code is contributed by Shivi_Aggarwal
    
    

    Python3

    # Python 3 program to find
    # factorial of given number
    
    # Function to find factorial of given number
    def factorial(n):
        
        if n == 0:
            return 1
        
        return n * factorial(n-1)
    
    # Driver Code
    num = 5;
    print("Factorial of", num, "is",
    factorial(num))
    
    # This code is contributed by Smitha Dinesh Semwal
    
    

    Java

    // Java program to find factorial of given number
    class Test {
        // method to find factorial of given number
        static int factorial(int n)
        {
            if (n == 0)
                return 1;
    
            return n * factorial(n - 1);
        }
    
        // Driver method
        public static void main(String[] args)
        {
            int num = 5;
            System.out.println("Factorial of " + num
                            + " is " + factorial(5));
        }
    }
    
    

    C#

    // C# program to find factorial
    // of given number
    using System;
    
    class Test {
        // method to find factorial
        // of given number
        static int factorial(int n)
        {
            if (n == 0)
                return 1;
    
            return n * factorial(n - 1);
        }
    
        // Driver method
        public static void Main()
        {
            int num = 5;
            Console.WriteLine("Factorial of "
                            + num + " is " + factorial(5));
        }
    }
    
    // This code is contributed by vt_m
    
    

    JavaScript

    <script>
    // Javascript to find factorial
    // of given number
    
    // function to find factorial
    // of given number
    function factorial(n) {
    if (n == 0) return 1;
    return n * factorial(n - 1);
    }
    
    // Driver Code
    let num = 5;
    document.write("Factorial of " + num + " is " + factorial(num));
    
    // This code is contributed by Saurabh Jaiswal
    
    </script>
    
    

  3. Please put your name at the end in comments if you wish to. For example:
     // This code is contributed by Amit Khandelwal
  4. During submission of Code Addition Mention ‘LanguageName – Code Addition‘ in Reason to Improve box and Select Type – Code Addition and then click on Submit for Review.
  5. If you wish to improve an existing code in one language before adding your code, you can first email us modified existing code first to improvement@geeksforgeeks.org.

Share your thoughts in the comments