0% found this document useful (0 votes)
33 views3 pages

Program K Re Aside Bug 3

This document contains code for a C program that allows a user to input equations line by line and stores them in an array for later processing. It prompts the user to input each line of an equation and uses pointers and dynamic memory allocation to store the input integers in an array. It includes functions for input, storing in arrays, and freeing allocated memory. The overall purpose is to build an array representation of the user-input equations for later solving or processing.

Uploaded by

Khalid Bagus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Program K Re Aside Bug 3

This document contains code for a C program that allows a user to input equations line by line and stores them in an array for later processing. It prompts the user to input each line of an equation and uses pointers and dynamic memory allocation to store the input integers in an array. It includes functions for input, storing in arrays, and freeing allocated memory. The overall purpose is to build an array representation of the user-input equations for later solving or processing.

Uploaded by

Khalid Bagus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1: #include <stdio.

h>
2: #include <conio.h>
3: #include <string.h>
4: #include <ctype.h>
5: #include <stdlib.h>
6:
7: main()
8: {
9:
10: printf("============================================================\n");
11: printf("================PROGRAM PENYELESAI PERSAMAAN================\n");
12: printf("============================================================\n\n");
13:
14: printf("Masukkan persamaan pada baris yang tersedia.\nBila selesai ketik '~'.\n\n");
15:
16: int **KVa;
17: int *KVP = (int*)malloc(4*sizeof(int));
18: char *pinjam = (char*)malloc(14*sizeof(char));
19: char *penunjuk;
20: int *penunjukkvp;
21: char p;
22: int i = 0,count,j;
23: int angka;
24: penunjuk = pinjam;
25: penunjukkvp = KVP;
26: for(angka = 1;(angka-1)<= i;angka++)
27: {
28: printf("%d. ",angka);
29: x:
30: p = getche();
31: switch(p)
32: {
33: case '~':
34: printf("\n\nSeluruh Persamaan telah dimasukkan.");
35: printf("\n1. %d",KVP[1]);
36:
37: printf("\n\ni = %d\n", (i-1));
38: break;
39: case '.':
40: if(angka == 1)
41: {
42: //KV = (int*)realloc(KV,(i-1));
43: int *KV[(i-1)];
44: for(count = 0;count <= (i-1);count++)
45: {
46: KV[count] = (int*)malloc(sizeof(int)*(i-1));
47: }
48: KVa = KV;
49: for(count = 0; count <= (i-1); count++)
50: {
51: KVa[(angka-1)][count] = KVP[count];
52: }
53: printf("\n");
54: j = 0;
55: break;
56: }
57: else
58: {
59: for(count = 0; count <= (i-1); count++)
60: {
61: KVa[(angka-1)][count] = KVP[count];
62: //*(*(KVa+(angka-1))+count) = KVP[count];
63: }
64: j = 4;
65: printf("\n");
66: break;
67: }
68: default :
69: if(isdigit(p))
70: {
71: *penunjuk = p;
72: penunjuk++;
73: goto x;
74: }
75: else if(islower(p) || isupper(p))
76: {
77: if(angka == 1)
78: {
79: *penunjuk = '\0';
80: penunjukkvp[i] = atoi(pinjam);
81: i += 1;
82: penunjuk = pinjam;
83: goto x;
84: }
85: else
86: {
87: *penunjuk = '\0';
88: penunjukkvp[j] = atoi(pinjam);
89: j += 1;
90: penunjuk = pinjam;
91: goto x;
92: }
93: }
94: else
95: {
96: goto x;
97: }
98: }
99: if(i == angka)
100: {
101: break;
102: }
103: }
104: printf("\n\nSeluruh Persamaan telah dimasukkan.");
105: printf("\nKVa00 = %d",KVa[0][0]);
106: printf("\n &KVP0 = %d", &KVP[0]);
107: printf("\n KVP0 = %d", KVP[0]);
108: printf("\n\nj = %d\n", j);
109: printf("\n\nangka-1 = %d\n", (angka-1));
110: free(KVP);
111: free(pinjam);
112: getch();
113:
114: }

You might also like