Program to implement Breadth First Search C++

What is Breadth First Search? Breadth first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root (or some arbitrary node of a graph) and explores the neighbor nodes first, before moving to the next level neighbors. Compare BFS with the equivalent, but more memory-efficient … Read more

C++ Program to find the Slope of line

GIVEN: Coordinates of its end points Here is the c program to find slope of line #include<iostream> #include<cmath> using namespace std; #define PI 3.14 int slope(int x1,int y1, int x2,int y2) { float tanx,s; tanx=(y2-y1)/(x2-x1); s=atan(tanx); s=(180/PI)*s; return s; } int main() { float x1,x2,y1,y2,x,tanx,s; while(true) { cout<<"enter the co_ordinate of point A"; cin>>x1>>y1; cout<<"enter … Read more

Sum of even & odd numbers in c++

Program to find sum of even & odd numbers in C++ from 1 to N. #include<iostream> using namespace std; int main() { int n; int sum=0,sum1=0; cout<<"enter the number of element"<<endl; cin>>n; for(int i=0;i<=n;i++) { if(i%2==0) { sum=sum+i; } } cout<<"sum of even number is = "<<sum<<endl; for(int i=0;i<=n;i++) { if(i%2!=0) { sum1=sum1+i; } } … Read more

Memory Leaks in C++

How to find memory leaks in C++? Memory leaks in C++ are dangerous thing that may lead your application to crash. Imagine your code allocates new blocks of memory again and again. At the some point no more free memory available and the process just crashes. Fortunately C++ comes with destructors that are automatically called … Read more