Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- void bin_add(int ,int );
- void bin_sub(int, int);
- int bin(int);
- int main(){
- int op1,op2;
- printf("enter the 1st operand:\t");
- scanf("%d",&op1);
- printf("enter the 2nd operand:\t");
- scanf("%d",&op2);
- bin_add(op1,op2);
- bin_sub(op1,op2);
- }
- int bin(int number){
- int q,rem,*bits;
- bits=(int)calloc(10,10*sizeof(int));
- int counter=0;
- do {
- rem=number%2;
- q=number/2;
- bits[counter]=rem;
- // printf("%d",bits[counter]);
- number=q;
- ++counter;
- }while(q!=0);
- // printf("\n\n");
- int *result;int size=0;
- result= (int )calloc(counter,counter*sizeof(counter));
- for(int x=counter-1;x>=0;x--){
- int second_counter=0;
- // printf("%d",bits[x]);
- result[second_counter]=bits[x];
- printf("%d",result[second_counter]);
- }
- printf("\n");
- return result;
- }
- void bin_add(int op1, int op2 ){
- int *bin_op1; int *bin_op2;
- printf("\nThe first operand:\n");
- bin_op1=bin(op1);
- printf("\nThe second operand :\n");
- bin_op2=bin(op2);
- printf("The sum is:\n");
- bin(op1+op2);
- }
- void bin_sub(int op1,int op2){
- int *bin_op1; int *bin_op2;
- printf("\nThe first operand:\n");
- bin_op1=bin(op1);
- printf("\nThe second operand :\n");
- bin_op2=bin(op2);
- printf("The subtaction is:\n");
- int sub=op1-op2;
- if(sub>=0){
- bin(sub);
- }
- else{
- printf("-");
- bin(abs(sub));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement