 # C++ Programming Code Examples

## C++ > Computer Graphics Code Examples

### C++ Program to Find MST(Minimum Spanning Tree) using Prim's Algorithm

``` C++ Program to Find MST(Minimum Spanning Tree) using Prim's Algorithm This C++ program depicts the Prim's Algorithm which finds the minimal spanning tree(tree consisting of the minimum weights of edges connecting any two vertices) in a graph. #include <iostream> #include <conio.h> using namespace std; struct node { int fr, to, cost; }p; int c = 0, temp1 = 0, temp = 0; void prims(int *a, int b[], int i, int j) { a[i] = 1; while (c < 6) { int min = 999; for (int i = 0; i < 7; i++) { if (a[i] == 1) { for (int j = 0; j < 7; ) { if (b[i][j] >= min || b[i][j] == 0) { j++; } else if (b[i][j] < min) { min = b[i][j]; temp = i; temp1 = j; } } } } a[temp1] = 1; p[c].fr = temp; p[c].to = temp1; p[c].cost = min; c++; b[temp][temp1] = b[temp1][temp]=1000; } for (int k = 0; k < 6; k++) { cout<<"source node:"<<p[k].fr<<endl; cout<<"destination node:"<<p[k].to<<endl; cout<<"weight of node"<<p[k].cost<<endl; } } int main() { int a; for (int i = 0; i < 7; i++) { a[i] = 0; } int b; for (int i = 0; i < 7; i++) { cout<<"enter values for "<<(i+1)<<" row"<<endl; for (int j = 0; j < 7; j++) { cin>>b[i][j]; } } prims(a, b, 0, 0); getch(); } ```

C Language Break Statements Switch Case - Break Statements are useful when you want your program-flow to come out of the switch body. Whenever break is encountered in the switch body, the control comes out of switch

C Code using of &(ampersand) *(asterisk) - C We have already seen in the first example that we can display the address of a variable using ampersand sign. I have used &num to access the address of variable num. The &...

Cryptography by Transposition Technique - This "C++" Program implement transposition technique. In "Cryptography", a transposition cipher is a method of encryption by which the positions held by units of plaintext (which are

Find Maximum Minimum using Functions - First give a meaningful name to our function. Say max() function is used to find maximum between two numbers. Second, we need to find maximum between two numbers. And

Egg Game graphic programming code in C - Go back to normal graphics mode or deleting viewport. Checking the egg position. Display mouse pointer. Define the upper left boundry of mouse. Define the bottom right boundry

Program Find the Length of the Linked list - C Program to Find the length of the linked list using Recursion. This program uses Recursive Function and calculates the length of a string. The user enters a string to find it's length. List

C Code Convert Days to Years Weeks Days - C program to input number of days from user and convert it to years, weeks and days. How to convert days to years, weeks in C. Input days from user. Store it in some variable say...

Create a File, Write content, Read content - C Programming language code to creating a file, writing content, reading the content. Open myfile.txt for output and write a string to disk. Open myfile.txt for input and read