encik pot pet 0 Report post Posted August 12, 2004 jawapan awak boleh post dalam thread ni..1. dgn menggunakan 'nested loop'/gelung bersarang, paparkana) $$$$$$$$$$$$$$$FFEFEDFEDCFEDCBFEDCBAc) A ABA ABCBA ABCDCDA ABCDEDCBA d)***************2. Rafi ada duit RM 3.74, untuk masukkan ke dalam tabung, dia kena tukar dalam bentuk duit syiling. Sila kira bilangan syiling 50sen, 20sen, 10sen, 5sen, 1sen yang Rafi dapat?input: floatoutput: integer2 utk bilangan syiling------------sekian... sila post code awak masingp/s:ada soalan2 yang telah dipetik dari buku.. kalau dah buat tu..post jer Quote Share this post Link to post Share on other sites
hotfloppy 19 Report post Posted August 12, 2004 a) #include <stdio.h> main() { int i, j; for (i=0; i<5; i++) { for (j=0; j<=i; j++) { printf("$"); } printf("\n"); } }yang lain lain tu aku penah buat kecuali b ngan c, tapi dah lupa yang d tu output aku tak cukup satu asterik kat bawah skali p/s bagus gak test camni.. hehehe.. hidup zeph (ayat ala ala manga) Quote Share this post Link to post Share on other sites
raihan 0 Report post Posted August 12, 2004 (edited) // uwaa.. exercising my mind, lama lew tak sentuh // salam ceria // /me listen Raihan - Haji Menuju Allah\n int menaik(const char w, const int n) { int i, j; for(i = 0; i < n; i++) { for(j = 0; j <= i; j++) printf("%c",w); printf('\n'); } return n < 1 ? 1 : 0; } // yehaa, malas nak layan, kalau ada error :P int menaiklainmacam(char w, const int n) { char j; const char i = w - (char)n, k = w; // ? if(!isalpha(i)) return 1; for(;w >= i; w--) { for(j = k; j > w; j--) printf("%c", j); printf('\n'); } return 0; } int menurun(const char w, int n) { int j; for(;n > 0; n--) { for(j = 1; j <= n; j++) printf(w); // printf('\n'); } return n < 1 ? 1 : 0; // ? }[/code] Edited August 22, 2004 by raihan Quote Share this post Link to post Share on other sites
encik pot pet 0 Report post Posted August 13, 2004 soalan no #2 takde orang submit lagi Quote Share this post Link to post Share on other sites
raihan 0 Report post Posted August 16, 2004 hurm... takde saper yg peka dgn channel ni???keep em works, zeph Quote Share this post Link to post Share on other sites
akuBest 0 Report post Posted August 18, 2004 A'kum. ni aku try jawab no 2 tuh. Jawapan 1 #include<stdio.h> #include<conio.h> main() { float duit, sen; int limapuluh=0, duapuluh=0, sepuluh=0, limasen=0, satusen=0; clrscr(); printf("Masukkan duit : RM "); scanf("%f", &duit); sen = duit * 100; printf("\nSen awal : %.0f", sen); do { if(sen >= 50) { limapuluh++; sen = sen - 50; } else if(sen >= 20) { duapuluh++; sen = sen - 20; } else if(sen >= 10) { sepuluh++; sen = sen - 10; } else if(sen >= 5) { limasen++; sen = sen - 5; } else if(sen >= 1) { satusen++; sen = sen - 1; } else printf("\nRalat"); }while(sen != 0); printf("\n50 sen : %d", limapuluh); printf("\n20 sen : %d", duapuluh); printf("\n10 sen : %d", sepuluh); printf("\n5 sen : %d", limasen); printf("\n1 sen : %d", satusen); printf("\nsen : %.0f", sen); } yang ni lak aku guna tatasusunan. Jawapan 2 #include<stdio.h> #include<conio.h> main() { float duit, sen; int duitpecah[5]={50, 20, 10, 5, 1}; int bahagiduit[5]={0, 0, 0, 0, 0}; clrscr(); printf("Masukkan duit : RM "); scanf("%f", &duit); sen = duit * 100; printf("\nSen awal : %.0f", sen); for(int x=0; x<5; x++) { while(sen >= duitpecah[x]) { bahagiduit[x]++; sen = sen - duitpecah[x]; } } for(int y=0; y<5; y++) printf("\n%d sen : %d", duitpecah[y], bahagiduit[y]); printf("\nsen : %.0f", sen); } Aku try gitu-gitu jer. Kot2 ada spa2 nak try run, kot ada error. Quote Share this post Link to post Share on other sites
idealmy 0 Report post Posted August 21, 2004 mcm penah buat jer soklan mcm nie? masa blaja c dulu. Quote Share this post Link to post Share on other sites
raihan 0 Report post Posted August 22, 2004 aku bestkod u ni mungkin best skit kalau gunakan mod(%)dan kurangkan penggunaan gelung , kan. cuba lagi.pastu biasa lengkapkan int main(... dgn pulangan return integer (4bytes).tak nak pun takpe, tak salah~ Quote Share this post Link to post Share on other sites
XtremgenX 0 Report post Posted August 31, 2004 Ni cara utk aku buat soalan 1 c. tp cam panjang sgt. ada idea utk perbaiki kh? #include <stdio.h>int main(int argc, char *argv[]){ int i = 0, j = 0, k = 0; char chr = 'E'; for(i = 4; i >= 0; i--) { for(j = 0; j < i; j++) printf(" "); for(j = 4; j >= i; j--) printf("%c", chr - j); for(k = 2; k >= j; k--) printf("%c", ((chr - j) + k) - 4); printf("\n"); } return 0;} Quote Share this post Link to post Share on other sites
raihan 0 Report post Posted September 1, 2004 XtremgenXcuba u tengok camner contoh penggunaan printf("%[initial point]s",text); saya.mungkin u leh pendekkan lagi koding u tu.#include <stdio.h> #define INITIAL "20" int main(int argc, char *argv[]) { char buf[BUFSIZ]; char *text = "hello"; sprintf(buf, "%s", text); printf("%"INITIAL"s\n",buf); sprintf(buf, "%s%s", buf, text); printf("%"INITIAL"s\n",buf); return 0; } Quote Share this post Link to post Share on other sites
XtremgenX 0 Report post Posted September 2, 2004 raihan makseh.. ni coding terbaru yg aku buat ikut idea engko.#include <stdio.h> #define INITIAL "40" int main(int argc, char *argv[]) { char buf[BUFSIZ], *chr = "A"; for(int i = 0; i <= 4; i++) { sprintf(buf, "%s%c", buf, *chr + i); printf("%"INITIAL"s", buf); for(int k = 1; k <= i; k++) printf("%c", (*chr + i) - k); printf("\n"); } return 0; }dua loop awal tu dh hilang dah.. Quote Share this post Link to post Share on other sites
encik pot pet 0 Report post Posted September 2, 2004 (edited) heh.. pls bring more faster/smaller codesitulah tujuan saya buat thread sebeginiedit:another challenge/aktiviti will come.. Edited September 2, 2004 by zeph Quote Share this post Link to post Share on other sites
Ancient One 3 Report post Posted September 5, 2004 1(a) Some info regarding the printf function...You write %s to generate a sequence of characters from the values stored in the argument C string..... The conversion generates no more than p characters, up to but not including the terminating null character.yang maner p refer kepada precision field. So let just solve 1(a) this way : #include <stdio.h> char str[] = "$$$$$"; int i = 0; void main() { while (++i < sizeof(str)) printf("%.*s\n", i, str); } 1( Benda yang sama apply, just change char str[] = "$$$$$"; to char str[] = "FEDCBA"; 1(d) Same concept as 1(a) and 1(, but now #include <stdio.h> char str[] = "*****"; int i = sizeof(str); void main() { while (i-- > 0) printf("%.*s\n", i, str); } 2. #include <stdio.h> float fwang; unsigned sen50, sen20, sen10, sen5, sen1; unsigned div(unsigned num, unsigned denom, unsigned *remainder) { *remainder = num % denom; return num/denom; } void main() { printf("Wang (dalam format ringgit.sen) : "); scanf("%f", &fwang); { unsigned wang = fwang*100; sen50 = div(wang, 50, &wang); sen20 = div(wang, 20, &wang); sen10 = div(wang, 10, &wang); sen5 = div(wang, 5, &wang); sen1 = wang; } printf("\nSen\tBilangan\n===\t========\n"); printf("50 \t%d\n20 \t%d\n10 \t%d\n5 \t%d\n1 \t%d\n", sen50, sen20, sen10, sen5, sen1); } Quote Share this post Link to post Share on other sites
cade 0 Report post Posted March 31, 2005 (edited) soalan seterusnya:1) camna nak cari nombor perdana?#include <stdio.h>main(){ int n, i=1, j, c; clrscr(); printf("Enter Number Of Terms"); scanf("%d",&n); while(i<=n) { c=0; for(j=1;j<=i;j++) { if(i % j == 0) c++; } if(c==2) { printf("%d",i) i++; } getch();}can someone tell me what is the wrong with this code? 2) Camna: input: 5 output:112123123412345 p/s: aku baru belajar C. Sampai skrg aku tak tau..diharap pakar sekalian membantu Edited April 1, 2005 by cade Quote Share this post Link to post Share on other sites
castlevama 0 Report post Posted April 4, 2005 (edited) soalan 2 tau la..#include<stdio.h>void main(){int num,row,col;printf("Please enter one integer from 1 to 5:");scanf("%d",&num);for(row=1;row<=num;row++) { printf("\n"); for (col=1;col<=row;col++) printf("%d",col); }return;}soalan 2 tu okla.. yg 1 xtau le.. try wat dpt 1eror lg.. xtau ktna..aku pn bru je blaja C ni.. Edited April 4, 2005 by castlevama Quote Share this post Link to post Share on other sites
isfann 0 Report post Posted April 4, 2005 aku nak tnya arr.. aku berminat nak belajar c ni.. tapi dlm perkembangan skrg ni.... bukanke programming lebih kepada gui?... apa pendapat anda?..err.. dlm keadaam camner yang kita memerlukan programming dlm konsole?.. camner nak cakap ar.r... iss.. korang faham ke apa yang aku cuba sampaikan ni?.. hehehe Quote Share this post Link to post Share on other sites
encik pot pet 0 Report post Posted April 4, 2005 aku nak tnya arr.. aku berminat nak belajar c ni.. tapi dlm perkembangan skrg ni.... bukanke programming lebih kepada gui?... apa pendapat anda?..err.. dlm keadaam camner yang kita memerlukan programming dlm konsole?.. camner nak cakap ar.r... iss.. korang faham ke apa yang aku cuba sampaikan ni?.. hehehe←awak jangan pandang sebelah mata program berbentuk console...banyak jugak program yg lebih sesuai berbentuk console berbanding gui'ed jikalau awak tak berminat utk programming console dalam c, anggapla ianya utk belajar bahasa C dari segi syntax, structure, semantic, etcand... ==> http://www.winprog.org/tutorial/ Quote Share this post Link to post Share on other sites
cade 0 Report post Posted April 5, 2005 (edited) 2) Camna: input: 5 output:112123123412345 ←for (i=1;i<nilai;i++) { for(j=1; j<=i;j++) { printf("%d",j); } printf("\n"); } Edited April 6, 2005 by cade Quote Share this post Link to post Share on other sites
hotfloppy 19 Report post Posted April 6, 2005 (edited) 2) Camna: input: 5 output:112123123412345 for (outval = inval; outval > 0; outval--) { printf ("%d\n", outval); } coding ni lagi simple kot tapi tak tau la leh run ke tak sebab aku wat ni kat cc, takde compiler. ade sesape nak tolong run kan ? kot kot ade error ke >_< Edited April 6, 2005 by hotfloppy Quote Share this post Link to post Share on other sites
encik pot pet 0 Report post Posted April 7, 2005 for (outval = inval; outval > 0; outval--) { printf ("%d\n", outval); } ←tanpa mengompile terlebih dahulu aku dah nampak error katprintf ("%d\n", outval);p/s: kalau kat cc, download dev-c++..kejap jer Quote Share this post Link to post Share on other sites
1kHz 0 Report post Posted April 7, 2005 lain sikit char str[6] = "12345"; char* str2; for(int i=1; i<6; i++) { str2 = new char[i+1]; strncpy(str2, str, i); str2[i] = '\0'; cout << str2 <<endl; } Quote Share this post Link to post Share on other sites
hotfloppy 19 Report post Posted April 7, 2005 ha'a la, salah kaw kaw ... hehehhe aku kat kolej skang ni, dah try compile, humang aii... logic error Quote Share this post Link to post Share on other sites
fatah 0 Report post Posted April 14, 2005 (edited) lalala~ lama x masuk cnie lah.. char str[6] = "12345"; char* str2; for(int i=1; i<6; i++) { str2 = new char[i+1]; // best la pebuatan ko kt sini, geget karang, x boleh tau. strncpy(str2, str, i); str2[i] = '\0'; cout << str2 <<endl; } int i; char str[7] = "1""\0""2345"; for(i=0; i<5;i++) { cout << str <<endl; str[i+1] = str[i+2]; str[i+2] = 0; }} int i, j; const int userinput = 5; for(i=1; i<=userinput; i++) { for(j=1; j<=i; j++) cout << j; cout << endl; } Edited April 14, 2005 by fatah Quote Share this post Link to post Share on other sites
1kHz 0 Report post Posted April 14, 2005 int i; char str[7] = "1""\0""2345"; for(i=0; i<5;i++) { cout << str <<endl; str[i+1] = str[i+2]; str[i+2] = 0; }}←cis.. yg ni terer siyuuutt.. dahsyat2... Quote Share this post Link to post Share on other sites
Vibrunnica 0 Report post Posted August 12, 2005 (edited) wohh...Gila la korang...cam kod FBI pon ada...hehehehaku pon nak try gak aaa...(baru seminggu blajar).... + curi sket skill En. Fatah...sebab kat 3 jam try dia jadik lain ...silap kat sini ( yg last : cout<<y<<endl;) so hangin je aku tgk....BTW ni jwp aku...sempat wat yg ni jek.... nanti try yg lain la{ for (int x=1;x<6;x++){ for (int y=1;y<=x;y++) cout<<y; cout<<endl;} Edited August 12, 2005 by Vibrunnica Quote Share this post Link to post Share on other sites