Tugas Bahasa C 19-10-2009

Untuk Program no 1 digunakan perintah seperti ini:

#include <stdio.h>
#include <conio.h>
#include <iostream.h>
void main()
{

int kup, sti, pir, a=0;
clrscr();
printf(“Program Untuk Menghitung Penukaran Kupon”);
printf(“\n”);
printf(“Masukkan Jumlah Kupon: “);scanf(“%d\n”,kup);
printf(“\n”);
sti = kup % 5;
while ( kup >= 5 )
{
kup = kup – 5;
a = a + 1;
}
printf(“Anda Mendapatkan: “);
printf(“\n”);
printf(“Piring Sebanyak: %d”,a);print(” pcs.”);
printf(“Sticker Sebanyak: %d”,sti);print( “pcs.”);
getche();
}

dan untuk Program no 2 digunakan perintah:

#include <iostream.h>

#include <conio.h>

#include <stdlib.h>

const int ESC = 27;

int main()

{

int key = 0;

int choise = 0;

long number;

while(key != ESC)

{

cout << “Choose Your Number Base\n”;

cout << “\n\t1. Hexadecimal.”;

cout << “\n\t2. Octal.”;

cout << “\n\t3. Decimal.”;

cout << “\n\t4. Exit.\n\t “;

cin >> choise;

switch(choise)

{

case 1: clrscr();

cout << “Enter a Hex number: “;

cin >> hex >> number;

cout << “\n value in octal = “

<< oct << number << endl;

cout << ” value in decimal = “

<< dec << number << endl;

break;

case 2: clrscr();

cout << “Enter a Octal number: “;

cin >> oct >> number;

cout << “\n value in hex = “

<< hex << number << endl;

cout << ” value in decimal = “

<< dec << number << endl;

break;

case 3: clrscr();

cout << “Enter a dec number: “;

cin >> dec >> number;

cout << “\n value in octal = “

<< oct << number << endl;

cout << ” value in hex = “

<< hex << number << endl;

break;

case 4: clrscr();

cout << “Program terminated by user…”;

exit(0);

break; //Unreachable code….

default : clrscr();

cout << “ERROR ~ Invalid selection\n\n”;

break;

}

cout << “Press any key to continue or ‘Esc’ to exit”;

key = getche();

clrscr();

}

cout << “Program terminated by user…”;

return 0;

}

untuk program no.2 bukan hanya mengkonversi dari desimal ke octal dan hexadesimal, namun juga bisa dari octal ke desimal dan hexadesimal, serta dari hexadesimal ke octal dan desimal.

~Download~ (file .cpp)

“kenapa baru kepikiran tadi pas di i-lab ya yang no. 1… padahal tugasnya udah di kumpulin… nyesel mode = “ON”

One Response to Tugas Bahasa C 19-10-2009

  1. Adi says:

    thanx gan, bermanfaat neh…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: