Created
October 20, 2015 05:40
-
-
Save exemuel/5cf183216a782297d89a to your computer and use it in GitHub Desktop.
Menghitung Jumlah Karakter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Nama file: hitungk.c * | |
* Menghitung jumlah karakter */ | |
#include <stdio.h> | |
int main() | |
{ | |
int k, nspasi, nlain2, ndigit; | |
nspasi = nlain2 = ndigit = 0; | |
printf("Berikan sebuah kalimat, akhiri dengan \'#\'\n"); | |
while ((k = getchar()) != '#') | |
{ | |
switch (k) | |
{ | |
case '0': | |
case '1': | |
case '2': | |
case '3': | |
case '4': | |
case '5': | |
case '6': | |
case '7': | |
case '8': | |
case '9': | |
ndigit++; | |
break; | |
case '\r': | |
printf("\n"); | |
case ' ': | |
case '\t': | |
nspasi++; | |
break; | |
default : | |
nlain2++; | |
break; | |
} | |
} | |
printf("jumlah angka=%d, ", ndigit); | |
printf("spasi=%d, lain-lain=%d.\n", nspasi, nlain2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment