Program for Shortest path using Dijkstra Algorithm in c++

The following program illustrates the Shortest Path using Dijkstra Algorithm in C++:   #include <iostream.h> #include <conio.h> #define MAX_NODE 50 struct node{ int vertex; int weight; node *next; }; struct fringe_node{ int vertex; fringe_node *next; }; node *adj[MAX_NODE]; //For storing Adjacency list of nodes.int totNodes; //No. of Nodes in Graph.constint UNSEEN=1,FRINGE=2,INTREE=3; //status of node.int status[MAX_NODE];//status … 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

How -1 is greater than 4?

Explain why output is “-1 is greater than 4”? CODE:   #include<stdio.h>int main(){ printf(“%d”,sizeof(int)); if(sizeof(int)>-1) { printf(“\n\n 4 is greater than -1”); } else { printf(“\n\n -1 is greater than 4”); } return 0;}     OUTPUT: 4-1 is greater than 4 Can you explain the above code and tell us why is it printing … Read more