Devilzc0de Forum Follow @devilzc0de
  • Home
  • Hacking
  • Networking
  • Programming
  • O.S
  • Server
  • Tweets
  • Search
  • Member List
  • Calendar
Current time: 05-24-2013, 09:09 PM Hello There, Guest! (Login — Register)
Devilzc0de Forum › Information Technology › Programming › C / C++ v
« Previous 1 2 3 4 5 ... 15 Next »

[Ask] Penjelasan Program Ini Gimana Ya??

Home General Computer Multimedia Business Lounge

Post Reply 
Tweet
Threaded Mode | Linear Mode
Ask Penjelasan Program Ini Gimana Ya??
06-24-2012, 11:19 PM
Post: #1
littleshadow Offline
./Devilz 1st Cadet
Posts: 20
Joined: Jan 2012
Reputation: 0
Penjelasan Program Ini Gimana Ya??
Permisi om-mastah.. ane mau tanya, maklum masih newbie... suram

ane punya coding tentang Find Shortest Path menggunakan Dijkstra Algorithm sama Floyd-Warshall Algorithm. yang mau ane tanyain itu penjelasan coding dari keduanya gimana ya?? galau

Dijkstra Algorithm
Code:
#include<stdio.h>
#include<stdlib.h>
void main()
{
    int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index;
    printf("enter the cost matrix\n");
    for(i=1;i<=5;i++)
    for(j=1;j<=5;j++)
    scanf("%d",&a[i][j]);
    printf("enter  number of paths\n");
    scanf("%d",&p);
    printf("enter possible paths\n");
    for(i=1;i<=p;i++)
    for(j=1;j<=5;j++)
    scanf("%d",&path[i][j]);
    for(i=1;i<=p;i++)
    {
        t[i]=0;
        stp=st;
        for(j=1;j<=5;j++)
        {
            edp=path[i][j+1];
            t[i]=t[i]+a[stp][edp];
            if(edp==ed)
                break;
            else
                stp=edp;
        }
    }
        min=t[st];index=st;
        for(i=1;i<=p;i++)
    {
        if(min>t[i])
        {
            min=t[i];
            index=i;
        }
    }
printf("minimum cost %d",min);
printf("\n minimum cost path ");
for(i=1;i<=5;i++)
{
    printf("--> %d",path[index][i]);
    if(path[index][i]==ed)
    break;
}
}

Floyd-Warshall Algoritm
Code:
#include <stdio.h>
#include <stdlib.h>

int n; /* Then number of nodes */
int dist[16][16]; /* dist[i][j] is the length of the edge between i and j if
            it exists, or 0 if it does not */

void printDist() {
    int i, j;
    printf("    ");
    for (i = 0; i < n; ++i)
        printf("%4c", 'A' + i);
    printf("\n");
    for (i = 0; i < n; ++i) {
        printf("%4c", 'A' + i);
        for (j = 0; j < n; ++j)
            printf("%4d", dist[i][j]);
        printf("\n");
    }
    printf("\n");
}

/*
    floyd_warshall()

    after calling this function dist[i][j] will the the minimum distance
    between i and j if it exists (i.e. if there's a path between i and j)
    or 0, otherwise
*/
void floyd_warshall() {
    int i, j, k;
    for (k = 0; k < n; ++k) {
        printDist();
        for (i = 0; i < n; ++i)
            for (j = 0; j < n; ++j)
                /* If i and j are different nodes and if
                    the paths between i and k and between
                    k and j exist, do */
                if ((dist[i][k] * dist[k][j] != 0) && (i != j))
                    /* See if you can't get a shorter path
                        between i and j by interspacing
                        k somewhere along the current
                        path */
                    if ((dist[i][k] + dist[k][j] < dist[i][j]) ||
                        (dist[i][j] == 0))
                        dist[i][j] = dist[i][k] + dist[k][j];
    }
    printDist();
}

int main(int argc, char *argv[]) {
    FILE *fin = fopen("dist.txt", "r");
    fscanf(fin, "%d", &n);
    int i, j;
    for (i = 0; i < n; ++i)
        for (j = 0; j < n; ++j)
            fscanf(fin, "%d", &dist[i][j]);
    fclose(fin);

    floyd_warshall();

    return 0;
}

Thanks Sebelumnya...
Find all posts by this user
Quote this message in a reply
06-25-2012, 09:14 AM
Post: #2
sodri126 Offline
./Devilz 1st Cadet
Posts: 5
Joined: Jun 2012
Reputation: 0
RE: Penjelasan Program Ini Gimana Ya??
Mungkin aja bawab ane Dewa
Find all posts by this user
Quote this message in a reply
06-25-2012, 01:37 PM
Post: #3
DC™Rebels Offline
Alayer_Terbaik_di DC
Posts: 869
Joined: Jun 2012
Reputation: 12
RE: Penjelasan Program Ini Gimana Ya??
(06-24-2012 11:19 PM)littleshadow Wrote:  Permisi om-om.. ane mau tanya, maklum masih newbie... suram

ane punya coding tentang Find Shortest Path menggunakan Dijkstra Algorithm sama Floyd-Warshall Algorithm. yang mau ane tanyain itu penjelasan coding dari keduanya gimana ya?? galau

Dijkstra Algorithm
Code:
#include<stdio.h>
#include<stdlib.h>
void main()
{
    int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index;
    printf("enter the cost matrix\n");
    for(i=1;i<=5;i++)
    for(j=1;j<=5;j++)
    scanf("%d",&a[i][j]);
    printf("enter  number of paths\n");
    scanf("%d",&p);
    printf("enter possible paths\n");
    for(i=1;i<=p;i++)
    for(j=1;j<=5;j++)
    scanf("%d",&path[i][j]);
    for(i=1;i<=p;i++)
    {
        t[i]=0;
        stp=st;
        for(j=1;j<=5;j++)
        {
            edp=path[i][j+1];
            t[i]=t[i]+a[stp][edp];
            if(edp==ed)
                break;
            else
                stp=edp;
        }
    }
        min=t[st];index=st;
        for(i=1;i<=p;i++)
    {
        if(min>t[i])
        {
            min=t[i];
            index=i;
        }
    }
printf("minimum cost %d",min);
printf("\n minimum cost path ");
for(i=1;i<=5;i++)
{
    printf("--> %d",path[index][i]);
    if(path[index][i]==ed)
    break;
}
}

Floyd-Warshall Algoritm
Code:
#include <stdio.h>
#include <stdlib.h>

int n; /* Then number of nodes */
int dist[16][16]; /* dist[i][j] is the length of the edge between i and j if
            it exists, or 0 if it does not */

void printDist() {
    int i, j;
    printf("    ");
    for (i = 0; i < n; ++i)
        printf("%4c", 'A' + i);
    printf("\n");
    for (i = 0; i < n; ++i) {
        printf("%4c", 'A' + i);
        for (j = 0; j < n; ++j)
            printf("%4d", dist[i][j]);
        printf("\n");
    }
    printf("\n");
}

/*
    floyd_warshall()

    after calling this function dist[i][j] will the the minimum distance
    between i and j if it exists (i.e. if there's a path between i and j)
    or 0, otherwise
*/
void floyd_warshall() {
    int i, j, k;
    for (k = 0; k < n; ++k) {
        printDist();
        for (i = 0; i < n; ++i)
            for (j = 0; j < n; ++j)
                /* If i and j are different nodes and if
                    the paths between i and k and between
                    k and j exist, do */
                if ((dist[i][k] * dist[k][j] != 0) && (i != j))
                    /* See if you can't get a shorter path
                        between i and j by interspacing
                        k somewhere along the current
                        path */
                    if ((dist[i][k] + dist[k][j] < dist[i][j]) ||
                        (dist[i][j] == 0))
                        dist[i][j] = dist[i][k] + dist[k][j];
    }
    printDist();
}

int main(int argc, char *argv[]) {
    FILE *fin = fopen("dist.txt", "r");
    fscanf(fin, "%d", &n);
    int i, j;
    for (i = 0; i < n; ++i)
        for (j = 0; j < n; ++j)
            fscanf(fin, "%d", &dist[i][j]);
    fclose(fin);

    floyd_warshall();

    return 0;
}

Thanks Sebelumnya...

Nunggu gengsternya aja om karna gengster DC pinter2 om :)
Visit this user's website Find all posts by this user
Quote this message in a reply
07-02-2012, 11:44 PM
Post: #4
littleshadow Offline
./Devilz 1st Cadet
Posts: 20
Joined: Jan 2012
Reputation: 0
RE: Penjelasan Program Ini Gimana Ya??
aduhh... bantuin donk gan... stress
Find all posts by this user
Quote this message in a reply
07-06-2012, 07:51 PM
Post: #5
monyett Offline
./Devilz Officer
Posts: 131
Joined: Jul 2012
Reputation: 2
RE: Penjelasan Program Ini Gimana Ya??
Ini perlu dijelasin baris per baris atau gimana? Yang gak paham bahasa C nya atau algoritmanya? Kalo algoritmanya, ada penjelasan di http://en.wikipedia.org/wiki/Floyd%E2%80..._algorithm sama http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

Fyi, wikipedia itu ensiklopedi lho, ditulis untuk orang awam.
Find all posts by this user
Quote this message in a reply
10-14-2012, 12:48 PM
Post: #6
guntur9090 Offline
./Devilz Officer
Posts: 55
Joined: Mar 2012
Reputation: 0
RE: Penjelasan Program Ini Gimana Ya??
Maksudnya penjelasan outputnya atau penjelasan cara kerjanya omz?
Find all posts by this user
Quote this message in a reply
10-28-2012, 05:40 PM
Post: #7
momoi Offline
./Devilz 1st Cadet
Posts: 7
Joined: Oct 2012
Reputation: 0
RE: Penjelasan Program Ini Gimana Ya??
(06-24-2012 11:19 PM)littleshadow Wrote:  Permisi om-om.. ane mau tanya, maklum masih newbie... suram

ane punya coding tentang Find Shortest Path menggunakan Dijkstra Algorithm sama Floyd-Warshall Algorithm. yang mau ane tanyain itu penjelasan coding dari keduanya gimana ya?? galau

Dijkstra Algorithm
Code:
#include<stdio.h>
#include<stdlib.h>
void main()
{
    int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index;
    printf("enter the cost matrix\n");
    for(i=1;i<=5;i++)
    for(j=1;j<=5;j++)
    scanf("%d",&a[i][j]);
    printf("enter  number of paths\n");
    scanf("%d",&p);
    printf("enter possible paths\n");
    for(i=1;i<=p;i++)
    for(j=1;j<=5;j++)
    scanf("%d",&path[i][j]);
    for(i=1;i<=p;i++)
    {
        t[i]=0;
        stp=st;
        for(j=1;j<=5;j++)
        {
            edp=path[i][j+1];
            t[i]=t[i]+a[stp][edp];
            if(edp==ed)
                break;
            else
                stp=edp;
        }
    }
        min=t[st];index=st;
        for(i=1;i<=p;i++)
    {
        if(min>t[i])
        {
            min=t[i];
            index=i;
        }
    }
printf("minimum cost %d",min);
printf("\n minimum cost path ");
for(i=1;i<=5;i++)
{
    printf("--> %d",path[index][i]);
    if(path[index][i]==ed)
    break;
}
}

Floyd-Warshall Algoritm
Code:
#include <stdio.h>
#include <stdlib.h>

int n; /* Then number of nodes */
int dist[16][16]; /* dist[i][j] is the length of the edge between i and j if
            it exists, or 0 if it does not */

void printDist() {
    int i, j;
    printf("    ");
    for (i = 0; i < n; ++i)
        printf("%4c", 'A' + i);
    printf("\n");
    for (i = 0; i < n; ++i) {
        printf("%4c", 'A' + i);
        for (j = 0; j < n; ++j)
            printf("%4d", dist[i][j]);
        printf("\n");
    }
    printf("\n");
}

/*
    floyd_warshall()

    after calling this function dist[i][j] will the the minimum distance
    between i and j if it exists (i.e. if there's a path between i and j)
    or 0, otherwise
*/
void floyd_warshall() {
    int i, j, k;
    for (k = 0; k < n; ++k) {
        printDist();
        for (i = 0; i < n; ++i)
            for (j = 0; j < n; ++j)
                /* If i and j are different nodes and if
                    the paths between i and k and between
                    k and j exist, do */
                if ((dist[i][k] * dist[k][j] != 0) && (i != j))
                    /* See if you can't get a shorter path
                        between i and j by interspacing
                        k somewhere along the current
                        path */
                    if ((dist[i][k] + dist[k][j] < dist[i][j]) ||
                        (dist[i][j] == 0))
                        dist[i][j] = dist[i][k] + dist[k][j];
    }
    printDist();
}

int main(int argc, char *argv[]) {
    FILE *fin = fopen("dist.txt", "r");
    fscanf(fin, "%d", &n);
    int i, j;
    for (i = 0; i < n; ++i)
        for (j = 0; j < n; ++j)
            fscanf(fin, "%d", &dist[i][j]);
    fclose(fin);

    floyd_warshall();

    return 0;
}

gan knpa ngga make #include <iostream.h>

gunanya:
1.iostream.h
2.conio.h
3.stdio.h


tolong jelasin donk gan...
ane ada UTS minggu depan.... tolong pencerahan nya gan....
binggung knpa ngga dipake iostream.h gan...
mohon bimbingan nya y gan.. makasiii

stressstressstressprustasiprustasi
Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Topic Tools
Topic Link :
BBCode :
HTML Code :
View a Printable Version Send Thread to a Friend Subscribe to this thread
Submit Google Submit Face book Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [Ask] Buat Program the_critical 13 332 02-05-2013 08:17 PM
Last Post: the_critical
  [Tutor] Send Mail Gmail & Yahoo dengan Program C# kadoel 8 240 12-17-2012 09:27 AM
Last Post: kadoel
  [Tutor] Program Send Mail dengan C# kadoel 18 373 12-15-2012 07:20 PM
Last Post: hazel
Thumbs Up [Tutor] Program Urutkan Data dengan metode insertion sort chentiz 4 151 12-10-2012 10:18 PM
Last Post: chentiz
  [Tutor] Program Penghitung Jarak Tempuh dan Konsumsi BBM (galon/mil) hitheir 9 252 12-02-2012 09:36 PM
Last Post: bari
  [ASK] program stack (need fast) chaosloki 10 252 11-14-2012 11:36 PM
Last Post: momoi
Heart [Solved] Penjelasan Kode Ini.... Faizal97 5 217 11-07-2012 01:41 PM
Last Post: Super Moderator
  Program pertama c++ ane(hanya share) Faizal97 4 152 11-06-2012 09:53 PM
Last Post: Faizal97
  [Solved] Gambar Flowchart nya gimana?? the_critical 10 282 11-06-2012 08:02 PM
Last Post: Rakagi
Sad [Ask] Bikin output segitiga bintang begini modelnya gimana ya? farhan007 5 643 10-16-2012 10:49 PM
Last Post: Rpm46

Users Browsing
1 Guest(s)

  • Contact Us
  • devilzc0de
  • Return to Top
  • Mobile Version
  • RSS Syndication
  • Help
Current time: 05-24-2013, 09:09 PM Powered By MyBB, © 2002-2013 MyBB Group. Theme created by Justin S. | Mixed By Chaer.Newbie | Fixed By Aditya

USING THIS SITE INDICATES THAT YOU HAVE READ AND ACCEPT OUR TERMS. IF YOU DO NOT ACCEPT THESE TERMS, YOU ARE NOT AUTHORIZED TO USE THIS SITE