Jump to content
Sign in to follow this  
vVv

Nested Loop

Recommended Posts

salam pada warga putera, saya nak minta tolong sikit pada otai2 programing tentang c.bawah ni coding dengan output yang saya dapat,

#include <stdio.h>
#include <stdlib.h>

int main()
{
void makemileskmtable(double,double,double,double,double);
double start,end,inc=1,split,lola;
char miles,kilometers;

printf ("What is the starting value for miles?\n");
scanf ("%lf",&start);
printf ("What is the end value for miles?\n");
scanf ("%lf",&end);

printf ("mile\t kilometers\t mile\t kilometers\n");

makemileskmtable(start,end,inc,split,lola);

system("PAUSE");
return 0;
}

void makemileskmtable(double x, double y, double z,double k,double j)
{
double km1,mile,split,n,km2,the,nextmile,a;

for(mile=x;mile<split;mile=mile+z)/*a*/
{
km1=mile*1.61;
split=x+y/2;
the=(mile-mile+split+1);

for(the=(mile-mile+split+1)-1;the<=y;the++)/*b*/
{
km2=the*1.61;
printf ("%.2f\t %.2f\t %.2f\t %.2f\t\n",mile,km1,the,km2);
}
}
}


outputnye:

[img]http://img560.imageshack.us/img560/6315/outputjj.jpg[/img]

masalahnya saya tak nak loop dia

Share this post


Link to post
Share on other sites
asal aku nya output x kuar mcm ko nyer output?

[url="http://imageshack.us/photo/my-images/842/unledjnj.jpg/"][img]http://img842.imageshack.us/img842/8264/unledjnj.jpg[/img][/url] Edited by otai_g

Share this post


Link to post
Share on other sites
[quote name='vVv' timestamp='1309131639' post='1070772']
salam pada warga putera, saya nak minta tolong sikit pada otai2 programing tentang c.bawah ni coding dengan output yang saya dapat,

#include <stdio.h>
#include <stdlib.h>

int main()
{
void makemileskmtable(double,double,double,double,double);
double start,end,inc=1,split,lola;
char miles,kilometers;

printf ("What is the starting value for miles?\n");
scanf ("%lf",&start);
printf ("What is the end value for miles?\n");
scanf ("%lf",&end);

printf ("mile\t kilometers\t mile\t kilometers\n");

makemileskmtable(start,end,inc,split,lola);

system("PAUSE");
return 0;
}

void makemileskmtable(double x, double y, double z,double k,double j)
{
double km1,mile,split,n,km2,the,nextmile,a;

for(mile=x;mile<split;mile=mile+z)/*a*/
{
km1=mile*1.61;
split=x+y/2;
the=(mile-mile+split+1);

for(the=(mile-mile+split+1)-1;the<=y;the++)/*b*/
{
km2=the*1.61;
printf ("%.2f\t %.2f\t %.2f\t %.2f\t\n",mile,km1,the,km2);
}
}
}


outputnye:

[img]http://img560.imageshack.us/img560/6315/outputjj.jpg[/img]

masalahnya saya tak nak loop dia
[/quote]

Bukan ke kalau taknak loop , buang FOR loop ? :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...