Algoritma9.2

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <cstring> #include <stdio.h> using namespace std; //Nama : Nagita Elsa //Nim : 3420230026 void garis() { puts("======================================"); } void ttd(char nama[20], char email[20]) { cout << "Nama : " << nama << endl; cout << "Email : " << email << endl; } void program_strlen() { char nama[20] = "Nagita Elsa"; garis(); puts("\tContoh Program Strlen"); garis(); cout << "Nama yang anda masukkan adalah " << nama << endl; cout << "Jumlah karakternya adalah " << strlen(nama) << endl; } void program_strcmp() { garis(); puts("\tContoh Program Strcmp"); garis(); char a1[] = "S", a2[] = "s", b1[] = "S"; cout << "Hasil pertandingan " << a1 << " dan " << a2 << " -> "; cout << strcmp(a1, a2) << endl; cout << "Hasil pertandingan " << a2 << " dan " << a1 << " -> "; cout << strcmp(a2, a1) << endl; cout << "Hasil pertandingan " << a1 << " dan " << b1 << " -> "; cout << strcmp(a1, b1) << endl; } int main() { int pilih; printf("Silahkan pilih program [1/2] :"); cin >> pilih; // scanf("%d", &pilih); cout << endl; /* There are two problems with using scanf() to get a number: first, validation/error handling is poor. The second problem is that of leaving characters in the buffer. Sumber: http://faq.cprograming.com/cgi-bin/smartfaq.cgi?answer=1043372399&id=1043254835 */ if(pilih == 1) { program_strlen(); } else if(pilih == 2) { program_strcmp(); } else { printf("Maaf pilihan anda salah.."); } garis(); ttd("Nagita Elsa", "nagitaelsa39@gmail.com"); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines