this code was a conversion from my prevous code i have written in C, what i like from python are it simplicity.... as you can compare from my prevous code
|
place i kept my code
this code was a conversion from my prevous code i have written in C, what i like from python are it simplicity.... as you can compare from my prevous code
|
this program ask user input for base value and the limit value of the exponent
variabel explanation:
x is used for interval value
y is used for base value
z is used for exponent container
v is used for limit value
|
from my previous program program penghitung uang pecahan dengan python i've rewrite the code in C
#include <stdio.h> /*change currency counter program*/ int main(){ int amount, result, rest; /*user input*/ printf ("welcome to amount currency counter program \n"); printf ("input your amount change "); scanf ("%d", &amount); /*mulai proses*/ result=amount/100000; rest=amount%100000; printf ("your change amount : \n"); printf ("%d", result); printf(" seratusribuan \n"); if (rest>=50000){ result=rest/50000; rest=rest%50000; printf("%d", result); printf(" limapuluhribuan \n"); } if (rest>=20000){ result=rest/20000; rest=rest%20000; printf("%d", result); printf(" duapuluhribuan \n"); } if (rest>=10000){ result=rest/10000; rest=rest%10000; printf("%d", result); printf(" sepuluhribuan \n"); } if (rest>=5000){ result=rest/5000; rest=rest%5000; printf("%d", result); printf(" limaribuan \n"); } if (rest>=1000){ result=rest/1000; rest=rest%1000; printf("%d", result); printf (" seribuan \n"); } if (rest>=500){ result=rest/500; rest=rest%500; printf("%d", result); printf (" limaratusan \n"); } if (rest>=100){ result=rest/100; rest=rest%100; printf("%d", result); printf (" seratusan \n"); } getchar(); return 0; } |
after visiting allaboutalgoritma, i've interested seeing their change currency, so i decided to convert it in python. forgive me if you're confused with the language cause it's indonesian
#change currency program print "welcome to my change currency program" amount = input("your money amount") result=amount/100000 rest=amount%100000 print "your change amount" print result, "seratusribuan" if (rest>=50000): result=rest/50000 rest=rest%50000 print result, "limapuluhribuan" if (rest>=20000): result=rest/20000 rest=rest%20000 print result, "duapuluhribuan" if (rest>=10000): result=rest/10000 rest=rest%10000 print result, "sepuluhribuan" if (rest>=5000): result=rest/5000 rest=rest%5000 print result, "limaribuan" if (rest>=1000): result=rest/1000 rest=rest%1000 print result, "seribuan" if (rest>=500): result=rest/500 rest=rest%500 print result, "limaratusan" if (rest>=100): result=rest/100 rest=rest%100 print result, "seratusan" else: print "rupiah" |
here is my simple age counter program, the concept still same likemy previous code's
#include <iostream> //age counter program using namespace std; int main() { //variable declaration char name[32]; int bday, bmonth, byear; int tday, tmonth, tyear; int bdate, tdate; int day, month, year; //input process cout<<"who are you? "; cin>> name; //input birth cout<<"input birth day "; cin>> bday; cout<<"input birth month "; cin>> bmonth; cout<<"input birth year "; cin>> byear; //input recent cout<<"input recent day "; cin>> tday; cout<<"input recent month "; cin>> tmonth; cout<<"input recent year "; cin>> tyear; cin.ignore(); //algorythm processing bdate=bday+(bmonth*30)+(byear*365); tdate=tday+(tmonth*30)+(tyear*365); //result processing day=(tdate-bdate)%365%30; month=(tdate-bdate)%365/30; year=(tdate-bdate)/365; //result cout<< name; cout<< ","<< day<<","<< month<< ","<<year; //commentation if (year<=5){ cout<<" you're still baby"; } else if (year<=17){ cout<<" you're still young"; } else if (year<=40){ cout<<" you're an adult"; } else if (year<=99){ cout<<" you're old enough"; } else { cout<<" are you serious?"; } cin.get(); return 1; } |
this was the C version of my precious age counter program
#include <stdio.h> #include <stdlib.h> #include <string.h> /*age counter program*/ int main() { /*variable declaration*/ char name[32]; int bday, bmonth, byear; int tday, tmonth, tyear; int tdate, bdate; int day, month, year; /*user input*/ printf ("who are you \n"); scanf ("%s[^\n]", name); /*input birth day*/ printf ("input birth day \n"); scanf ("%d", &bday); printf ("input birth month \n"); scanf ("%d", &bmonth); printf ("input birth year \n"); scanf ("%d", &byear); /*input recent day*/ printf ("input recent day \n"); scanf ("%d", &tday); printf ("input recent month \n"); scanf ("%d", &tmonth); printf ("input recent year \n"); scanf ("%d", &tyear); /*algorhytm processing*/ bdate=bday+(bmonth*30)+(byear*365); tdate=tday+(tmonth*30)+(tyear*365); /*result processing*/ year=(tdate-bdate)/365; month=(tdate-bdate)%365/30; day=(tdate-tmonth)%365%30; /*result*/ printf("%s %d %d %d", name, day, month, year); /*comment about age*/ if (year <= 5) { printf ("\n you're still baby \n"); } else if (year <= 17) { printf ("\n you're still young\n"); } else if (year <= 40) { printf ("\n you're an adult \n"); } else if (year <= 99) { printf ("\n you're old enough \n"); } else { printf ("\n are you serious? \n"); } getchar(); return 0; } |
this is a Hello world in C, yes! i know, that many other site's has create same topic.
#include <stdio.h> int main() { printf ("Hello world!"); getchar(); return 0; } |
there's a tradition in programming that newbie should success performing hello world, so this is my hello world
|
this example will create an "pop up" that ask user input, enjoy it
|
honestly, i never use this keymail, but i decided to posting this code, so you can help me understanding this code
i've got this code from IndonesiaHacker.org , but it's not 100% pure anymore, there's some line i've changed. but that will not affect the program, cause i'm just change the commentation
i've using DevC++ 4.9.9.2 portable. and got some problem when compiling, after i've read instruction in line 37-40. it's all clear
|