Jump to content
Sign in to follow this  
yusina

C Compiler( For) Dan Do......while

Recommended Posts

kpd sesapa sudi bantu...

tulis aturcara lengkap guna gelung for() untuk menghasilkan output spt berikut

1 2 3 4 5 6

2 4 6 8 10 12

3 6 9 12 15 18

4 8 12 16 20 24

5 10 15 20 25 30

6 12 18 24 30 36

b. tulis aturcara lengkap do....while utk hasilkan output spt berikut;

n 4n

1 4

2 16

3 64

4 256

5 1024

6 4096

minta tolong la sapa2 boleh bantu

Share this post


Link to post
Share on other sites

A'kum. sebelum nak org lain bantu, tolong la bantu diri sendiri dulu.....

wkslm ..

kalu saya tau x tanya la org....

dah try wat x leh...

kalu ada sesapa nak ngajar subjek ni ..aku nak belajar la...

A'kum. sebelum nak org lain bantu, tolong la bantu diri sendiri dulu.....

1 2 3 4 5 6 -54

2 4 6 8 10 12 -54

3 6 9 12 15 18 -54

4 8 12 16 20 24 -54

5 10 15 20 25 30 -54

6 12 18 24 30 36 -54

bila run ada kat ujung -54. knp

Share this post


Link to post
Share on other sites

biasanya kalau nak minta tolong ni dia kena kasi kod yang erroneous tu dulu. baru le orang leh tolong. OK.

#include<stdio.h>

int x, x2, x3, x4, x5, x6;

void main(){

for (x=1;x<=6;++x)

{

x2=x+x;

{

x3=x2+x;

{

x4=x3+x;

{

x5=x4+x;

{

x6=x5+x;

printf("\n%d %d %d %d %d %d %d", x, x2, x3, x4, x5, x6);

getch();

}

Share this post


Link to post
Share on other sites

#include<stdio.h>

int x, x2, x3, x4, x5, x6;

void main(){

for (x=1;x<=6;++x)

{

x2=x+x;

{

x3=x2+x;

{

x4=x3+x;

{

x5=x4+x;

{

x6=x5+x;

printf("\n%d %d %d %d %d %d %d", x, x2, x3, x4, x5, x6);

getch();

}

sila gunakan fungsi kod.....

#include<stdio.h>
int x, x2, x3, x4, x5, x6;
void main(){
for (x=1;x<=6;++x)
{
x2=x+x;
{
x3=x2+x;
{
x4=x3+x;
{
x5=x4+x;
{
x6=x5+x;
printf("\n%d %d %d %d %d %d %d", x, x2, x3, x4, x5, x6);
getch();
}

...tukarkan codebox kepada code sebab forum ni buggy sket.... :lol:

Edited by Gaara92

Share this post


Link to post
Share on other sites

#include<stdio.h>

int x, x2, x3, x4, x5, x6;

void main(){

for (x=1;x<=6;++x)

{

x2=x+x;

{

x3=x2+x;

{

x4=x3+x;

{

x5=x4+x;

{

x6=x5+x;

printf("\n%d %d %d %d %d %d %d", x, x2, x3, x4, x5, x6);

getch();

}

macam mana code ni boleh compile,conio.h takde utk function getch().pastu %d tu terlebih satu..

Share this post


Link to post
Share on other sites

Kalo takder fungsi getch(), tak boleh ke? :P

ok, ini dia tips coding utk soalan ( a ):

#include <stdio.h>
#include <conio.h>
int x, x2, x3, x4, x5, x6;
void main(){
for (x=1;x<=6;++x)
{
x2=x+x;
x3=x2+x;
x4=x3+x;
x5=x4+x;
x6=x5+x;
printf("\n%d %d %d %d %d %d", x, x2, x3, x4, x5, x6);
}
getch();
}
Tapi, kalo nak tau, pakai satu variable pun dah jadi, macam ini::
#include <stdio.h>
#include <conio.h>
int x;
void main(){
for (x=1;x<=6;++x)
{
printf("\n%d %d %d %d %d %d", x, x+x, x+x+x, x+x+x+x, x+x+x+x+x, x+x+x+x+x+x);
}
getch();
}

Haa, terkejut!!??

**Kalo expert sangat, pakai gelung bersarang; gelung dalam gelung... tau buat?

Apa pulak coding utk soalan ( b )? Maghi kasi tengok dlu!

Edited by mfar

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...