Skip to content

Instantly share code, notes, and snippets.

@duken-blog
Created April 2, 2020 11:27
Show Gist options
  • Save duken-blog/3cd38ef58237d5cbbdd3e24100741e11 to your computer and use it in GitHub Desktop.
Save duken-blog/3cd38ef58237d5cbbdd3e24100741e11 to your computer and use it in GitHub Desktop.
Mengubah Char menjadi Int (C)
#include <stdio.h>
int main(){
char c[5] = "23452";
char d[5] = "23452";
int hasil=0, kali=3;
int ubah;
// mengubah 1 karakter dari sebuah array
ubah = c[2] - '0';
hasil = kali*ubah; // hasil=12
printf("hasil pekalian : %d\n",hasil);
// mengubah array char menjadi int
ubah = atoi(d);
hasil=kali*ubah; // hasil=70356
printf("Hasil pekalian : %d\n",hasil);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment