contoh progarm c++ for math.h(matematika algorithm)


NAMA : vasko edo minter gultom

NIM : 071402009

MODUL 2 .LATIHAN 1.

#include <iostream.h>

int main()

{

char brs[64];

cout << “Tuliskan satu baris kalimat dan tekan <Enter>” << endl;

cin.getline(brs, sizeof(brs), ‘X’);

cout << “Baris pertama: ” << brs << endl;

cin.getline(brs, sizeof(brs));

cout << “Baris kedua: ” << brs << endl;

return 0;

}

MODUL 2 .LATIHAN 2.B

#include <iostream.h>

int main()

{

int c, i;

char text[128];

cout << “Tuliskan sembarang kalimat: ” << endl;

cin.getline(text, sizeof(text));

i = cin.gcount();

cout << “Anda menuliskan: ” ;

for (c=0 ; c < i; c++)

cout << text[c];

cout << endl;

return 0;

}

MODUL 2 .LATIHAN 3.C

#include <iostream.h>

int main()

{

int c, i;

char text[128];

cout << “Tuliskan sembarang kalimat: ” << endl;

cin.getline(text, sizeof(text));

i = cin.gcount();

cout << “Anda menuliskan: “;

for(c = 0; c < i; c++)

cout << text[c];

cout << endl;

cout << “Kode ASCII masing-masing huruf: ” << endl;

for(c = 0; c < i; c++)

cout << text[c] << ” = ” << ((int)text[c]) << endl;

cout << endl;

return 0;

}

MODUL 2 .LATIHAN 4.D

#include <iostream.h>

#include <ctype.h>

int main()

{

int htgHrf[26],htgAng[10], i, j;

char ch;

//inisialisasi hitungan tiap2 karakter ke 0

for(i=0; i<26; i++)

htgHrf[i] = 0;

for(j=0; j<10; j++)

htgAng[j] = 0;

cout << “Tuliskan sembarang kalimat dan akhiri dengan <ENTER>” << endl;

do

{

ch = cin.get();

if ((ch >= ‘a’) && (ch <= ‘z’))

cin.putback(toupper(ch));

else if ((ch >= ‘A’) && (ch <= ‘Z’))

htgHrf[ch-‘A’]++;

else if ((ch >= ‘0’) && (ch <= ‘9’))

htgAng[ch-‘0’]++;

}

while(ch != ‘\n’);

cout << “Tabulasi huruf: ” << endl;

for(i=0; i<26; i++)

{

cout.put((char)(‘A’ + i));

cout << “=” << htgHrf[i];

if(i<25)

cout << “, “;

}

cout << endl;

cout << “Tabulasi huruf: ” << endl;

for(j=0; j<10; j++)

{

cout.put((char)(‘0’ + j));

cout << “=” << htgAng[j];

if(j<9)

cout << “, “;

}

cout << “.” << endl;

return 0;

}

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s