Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- float* Calculate(char* buffer);
- int main()
- {
- char *poc = (char* )malloc(sizeof(char)+2*sizeof(int));
- float *resenje;
- int a, b;
- printf("Operacija(0-3): ");
- scanf("%c",poc);
- printf("Unesite dva celobrojna podatka: ");
- scanf("%d %d",poc+sizeof(char),poc+sizeof(char)+sizeof(int));
- resenje=Calculate(poc);
- a = *((int *)(poc+sizeof(char)));
- b = *((int *)(poc+sizeof(char)+sizeof(int)));
- switch(*poc){
- case '0': printf("%d + %d: %.2f",a,b,*resenje);
- break;
- case '1': printf("%d - %d: %.2f",a,b,*resenje);
- break;
- case '2': printf("%d * %d: %.2f",a,b,*resenje);
- break;
- case '3': if(b!=0) printf("%d / %d: %.2f",a,b,*resenje);
- else printf("\nGreska!\nDeljenje sa nulom!!");
- break;
- }
- return 0;
- }
- float* Calculate(char* buffer)
- {
- float *resenje = (float*)malloc(sizeof(float));
- switch(*buffer){
- case '0': *resenje = *((int *)(buffer+sizeof(char))) + *((int *)(buffer+sizeof(char)+sizeof(int)));
- break;
- case '1': *resenje = *((int *)(buffer+sizeof(char))) - *((int *)(buffer+sizeof(char)+sizeof(int)));
- break;
- case '2': *resenje = *((int *)(buffer+sizeof(char))) * *((int *)(buffer+sizeof(char)+sizeof(int)));
- break;
- case '3': if(*((int *)(buffer+sizeof(char)+sizeof(int)))!=0) *resenje = *((int *)(buffer+sizeof(char))) / *((int *)(buffer+sizeof(char)+sizeof(int)));
- else *resenje = 0;
- break;
- }
- return resenje;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement