Skip to content

Instantly share code, notes, and snippets.

@exemuel
Created October 20, 2015 05:40
Show Gist options
  • Save exemuel/5cf183216a782297d89a to your computer and use it in GitHub Desktop.
Save exemuel/5cf183216a782297d89a to your computer and use it in GitHub Desktop.
Menghitung Jumlah Karakter
/* 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