Created
April 2, 2020 11:27
-
-
Save duken-blog/3cd38ef58237d5cbbdd3e24100741e11 to your computer and use it in GitHub Desktop.
Mengubah Char menjadi Int (C)
This file contains 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
#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