# Degree of a Cycle Graph

Given the number of vertices in a Cycle Graph. The task is to find the Degree and the number of Edges of the cycle graph.

Degree: Degree of any vertex is defined as the number of edge Incident on it.

Cycle Graph: In graph theory, a graph that consists of single cycle is called a cycle graph or circular graph. The cycle graph with n vertices is called Cn.

Properties of Cycle Graph:-

• It is a Connected Graph.
• A Cycle Graph or Circular Graph is a graph that consists of a single cycle.
• In a Cycle Graph number of vertices is equal to number of edges.
• A Cycle Graph is 2-edge colorable or 2-vertex colorable, if and only if it has an even number of vertices.
• A Cycle Graph is 3-edge colorable or 3-edge colorable, if and only if it has an odd number of vertices.
• In a Cycle Graph, Degree of each vertx in a graph is two.
• The degree of a Cycle graph is 2 times the number of vertices. As each edge is counted twice.

Examples:

```Input: Number of vertices = 4
Output: Degree is 8
Edges are 4
Explanation:
The total edges are 4
and the Degree of the Graph is 8
as 2 edge incident on each of
the vertices i.e on a, b, c, and d. Input: number of vertices = 5
Output: Degree is 10
Edges are 5
```

Below is the implementaion of the above problem:

Program 1: For 4 vertices cycle graph

## C++

 `// C++ implementation of above program. ` ` `  `#include ` `using` `namespace` `std; ` ` `  `// function that calculates the ` `// number of Edge in a cycle graph. ` `int` `getnumberOfEdges(``int` `numberOfVertices) ` `{ ` `    ``int` `numberOfEdges = 0; ` ` `  `    ``// The numberOfEdges of the cycle graph ` `    ``// will be same as the numberOfVertices ` `    ``numberOfEdges = numberOfVertices; ` ` `  `    ``// return the numberOfEdges ` `    ``return` `numberOfEdges; ` `} ` ` `  `// function that calculates the degree ` `int` `getDegree(``int` `numberOfVertices) ` `{ ` `    ``int` `degree; ` ` `  `    ``// The degree of the cycle graph ` `    ``// will be twice the numberOfVertices ` `    ``degree = 2 * numberOfVertices; ` ` `  `    ``// return the degree ` `    ``return` `degree; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` ` `  `    ``// Get the number of vertices ` `    ``int` `numberOfVertices = 4; ` ` `  `    ``// Find the numberOfEdges and degree ` `    ``// from the numberOfVertices ` `    ``// and print the result ` `    ``cout << ``"For numberOfVertices = "` `         ``<< numberOfVertices ` `         ``<< ``"\nDegree = "` `         ``<< getDegree(numberOfVertices) ` `         ``<< ``"\nNumber of Edges = "` `         ``<< getnumberOfEdges(numberOfVertices); ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java implementation of above program. ` `import` `java.io.*; ` ` `  `class` `GFG { ` ` `  `    ``// function that calculates the ` `    ``// number of Edge in a cycle graph. ` `    ``static` `int` `getnumberOfEdges(``int` `numberOfVertices) ` `    ``{ ` `        ``int` `numberOfEdges = ``0``; ` ` `  `        ``// The numberOfEdges of the cycle graph ` `        ``// will be same as the numberOfVertices ` `        ``numberOfEdges = numberOfVertices; ` ` `  `        ``// return the numberOfEdges ` `        ``return` `numberOfEdges; ` `    ``} ` ` `  `    ``// function that calculates the degree ` `    ``static` `int` `getDegree(``int` `numberOfVertices) ` `    ``{ ` `        ``int` `degree; ` ` `  `        ``// The degree of the cycle graph ` `        ``// will be twice the numberOfVertices ` `        ``degree = ``2` `* numberOfVertices; ` ` `  `        ``// return the degree ` `        ``return` `degree; ` `    ``} ` ` `  `    ``// Driver code ` `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` `        ``// Get the number of vertices ` `        ``int` `numberOfVertices = ``4``; ` ` `  `        ``// Find the numberOfEdges and degree ` `        ``// from the numberOfVertices ` `        ``// and print the result ` `        ``System.out.print(``"For numberOfVertices = "` `                         ``+ numberOfVertices ` `                         ``+ ``"\nDegree = "` `                         ``+ getDegree(numberOfVertices) ` `                         ``+ ``"\nNumber of Edges = "` `                         ``+ getnumberOfEdges(numberOfVertices)); ` `    ``} ` `} ` ` `  `// This code is contributed by anuj_67.. `

## Python3

 `# Python3 implementation of above program. ` ` `  `# function that calculates the  ` `# number of Edge in a cycle graph. ` `def` `getnumberOfEdges(numberOfVertices) : ` ` `  `    ``# The numberOfEdges of the cycle graph  ` `    ``# will be same as the numberOfVertices ` `    ``numberOfEdges ``=` `numberOfVertices ` ` `  `    ``# return the numberOfEdges ` `    ``return` `numberOfEdges ` ` `  `# function that calculates the degree  ` `def` `getDegree(numberOfVertices) : ` ` `  `    ``# The degree of the cycle graph  ` `    ``# will be twice the numberOfVertices ` `    ``degree ``=` `2` `*` `numberOfVertices ` ` `  `    ``# return the degree ` `    ``return` `degree ` ` `  ` `  `# Driver code      ` `if` `__name__ ``=``=` `"__main__"` `: ` ` `  `    ``# Get the number of vertices  ` `    ``numberOfVertices ``=` `4` ` `  `    ``# Find the numberOfEdges and degree  ` `    ``# from the numberOfVertices  ` `    ``# and print the result  ` `    ``print``(``"For numberOfVertices ="``, numberOfVertices, ` `          ``"\nDegree ="``, getDegree(numberOfVertices), ` `          ``"\nNumber of Edges ="``, getnumberOfEdges(numberOfVertices)) ` ` `  ` `  `# This code is contributed by ANKITRAI1 `

## C#

 `// C# implementation of above program. ` `using` `System; ` ` `  `class` `GFG { ` ` `  `    ``// function that calculates the ` `    ``// number of Edge in a cycle graph. ` `    ``static` `int` `getnumberOfEdges(``int` `numberOfVertices) ` `    ``{ ` `        ``int` `numberOfEdges = 0; ` ` `  `        ``// The numberOfEdges of the cycle graph ` `        ``// will be same as the numberOfVertices ` `        ``numberOfEdges = numberOfVertices; ` ` `  `        ``// return the numberOfEdges ` `        ``return` `numberOfEdges; ` `    ``} ` ` `  `    ``// function that calculates the degree ` `    ``static` `int` `getDegree(``int` `numberOfVertices) ` `    ``{ ` `        ``int` `degree; ` ` `  `        ``// The degree of the cycle graph ` `        ``// will be twice the numberOfVertices ` `        ``degree = 2 * numberOfVertices; ` ` `  `        ``// return the degree ` `        ``return` `degree; ` `    ``} ` ` `  `    ``// Driver code ` `    ``public` `static` `void` `Main() ` `    ``{ ` `        ``// Get the number of vertices ` `        ``int` `numberOfVertices = 4; ` ` `  `        ``// Find the numberOfEdges and degree ` `        ``// from the numberOfVertices ` `        ``// and print the result ` `        ``Console.WriteLine(``"For numberOfVertices = "` `                          ``+ numberOfVertices ` `                          ``+ ``"\nDegree = "` `                          ``+ getDegree(numberOfVertices) ` `                          ``+ ``"\nNumber of Edges = "` `                          ``+ getnumberOfEdges(numberOfVertices)); ` `    ``} ` `} ` ` `  `// This code is contributed by anuj_67.. `

## PHP

 ` `

Output:

```For numberOfVertices = 4
Degree = 8
Number of Edges = 4
```

Program 2: For 6 vertices cycle graph

## C++

 `// C++ implementation of above program. ` ` `  `#include ` `using` `namespace` `std; ` ` `  `// function that calculates the ` `// number of Edge in a cycle graph. ` `int` `getnumberOfEdges(``int` `numberOfVertices) ` `{ ` `    ``int` `numberOfEdges = 0; ` ` `  `    ``// The numberOfEdges of the cycle graph ` `    ``// will be same as the numberOfVertices ` `    ``numberOfEdges = numberOfVertices; ` ` `  `    ``// return the numberOfEdges ` `    ``return` `numberOfEdges; ` `} ` ` `  `// function that calculates the degree ` `int` `getDegree(``int` `numberOfVertices) ` `{ ` `    ``int` `degree; ` ` `  `    ``// The degree of the cycle graph ` `    ``// will be twice the numberOfVertices ` `    ``degree = 2 * numberOfVertices; ` ` `  `    ``// return the degree ` `    ``return` `degree; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` ` `  `    ``// Get the number of vertices ` `    ``int` `numberOfVertices = 6; ` ` `  `    ``// Find the numberOfEdges and degree ` `    ``// from the numberOfVertices ` `    ``// and print the result ` `    ``cout << ``"For numberOfVertices = "` `         ``<< numberOfVertices ` `         ``<< ``"\nDegree = "` `         ``<< getDegree(numberOfVertices) ` `         ``<< ``"\nNumber of Edges = "` `         ``<< getnumberOfEdges(numberOfVertices); ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java implementation of above program. ` `class` `GfG { ` ` `  `    ``// function that calculates the ` `    ``// number of Edge in a cycle graph. ` `    ``static` `int` `getnumberOfEdges(``int` `numberOfVertices) ` `    ``{ ` `        ``int` `numberOfEdges = ``0``; ` ` `  `        ``// The numberOfEdges of the cycle graph ` `        ``// will be same as the numberOfVertices ` `        ``numberOfEdges = numberOfVertices; ` ` `  `        ``// return the numberOfEdges ` `        ``return` `numberOfEdges; ` `    ``} ` ` `  `    ``// function that calculates the degree ` `    ``static` `int` `getDegree(``int` `numberOfVertices) ` `    ``{ ` `        ``int` `degree; ` ` `  `        ``// The degree of the cycle graph ` `        ``// will be twice the numberOfVertices ` `        ``degree = ``2` `* numberOfVertices; ` ` `  `        ``// return the degree ` `        ``return` `degree; ` `    ``} ` ` `  `    ``// Driver code ` `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``// Get the number of vertices ` `        ``int` `numberOfVertices = ``6``; ` ` `  `        ``// Find the numberOfEdges and degree ` `        ``// from the numberOfVertices ` `        ``// and print the result ` `        ``System.out.println(``"For numberOfVertices = "` `                           ``+ numberOfVertices + ``"\nDegree = "` `                           ``+ getDegree(numberOfVertices) ` `                           ``+ ``"\nNumber of Edges = "` `                           ``+ getnumberOfEdges(numberOfVertices)); ` `    ``} ` `} ` ` `  `// This code contributed by Rajput-Ji `

## Python3

 `# Python 3 implementation of above program ` ` `  `# function that calculates the ` `# number of Edge in a cycle graph. ` `def` `getnumberOfEdges(numberOfVertices): ` ` `  `    ``numberOfEdges ``=` `0` ` `  `    ``# The numberOfEdges of the cycle graph ` `    ``# will be same as the numberOfVertices ` `    ``numberOfEdges ``=` `numberOfVertices ` ` `  `    ``# return the numberOfEdges ` `    ``return` `numberOfEdges ` ` `  `# function that calculates the degree ` `def` `getDegree(numberOfVertices): ` ` `  `    ``# The degree of the cycle graph ` `    ``# will be twice the numberOfVertices ` `    ``degree ``=` `2` `*` `numberOfVertices ` ` `  `    ``# return the degree ` `    ``return` `degree ` ` `  `# Driver code ` `if` `__name__ ``=``=` `"__main__"``:  ` `     `  `    ``# Get the number of vertices ` `    ``numberOfVertices ``=` `6` ` `  `    ``# Find the numberOfEdges and degree ` `    ``# from the numberOfVertices ` `    ``# and print the result ` `    ``print``(``"For numberOfVertices = "``,  ` `           ``numberOfVertices, ``"\nDegree = "``,  ` `               ``getDegree(numberOfVertices), ` `          ``"\nNumber of Edges = "``,  ` `        ``getnumberOfEdges(numberOfVertices)) ` ` `  `# This code is contributed by ChitraNayal `

## C#

 `// C# implementation of above program. ` `class` `GfG { ` ` `  `    ``// function that calculates the ` `    ``// number of Edge in a cycle graph. ` `    ``static` `int` `getnumberOfEdges(``int` `numberOfVertices) ` `    ``{ ` `        ``int` `numberOfEdges = 0; ` ` `  `        ``// The numberOfEdges of the cycle graph ` `        ``// will be same as the numberOfVertices ` `        ``numberOfEdges = numberOfVertices; ` ` `  `        ``// return the numberOfEdges ` `        ``return` `numberOfEdges; ` `    ``} ` ` `  `    ``// function that calculates the degree ` `    ``static` `int` `getDegree(``int` `numberOfVertices) ` `    ``{ ` `        ``int` `degree; ` ` `  `        ``// The degree of the cycle graph ` `        ``// will be twice the numberOfVertices ` `        ``degree = 2 * numberOfVertices; ` ` `  `        ``// return the degree ` `        ``return` `degree; ` `    ``} ` ` `  `    ``// Driver code ` `    ``static` `void` `Main() ` `    ``{ ` ` `  `        ``// Get the number of vertices ` `        ``int` `numberOfVertices = 6; ` ` `  `        ``// Find the numberOfEdges and degree ` `        ``// from the numberOfVertices ` `        ``// and print the result ` `        ``System.Console.WriteLine(``"For numberOfVertices = "` `                                 ``+ numberOfVertices + ``"\nDegree = "` `                                 ``+ getDegree(numberOfVertices) ` `                                 ``+ ``"\nNumber of Edges = "` `                                 ``+ getnumberOfEdges(numberOfVertices)); ` `    ``} ` `} ` ` `  `// This code contributed by mits `

## PHP

 ` `

Output:

```For numberOfVertices = 6
Degree = 12
Number of Edges = 6
```

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.