Answer to Question #288708 in C for Thank you!

Question #288708

Input of number of numbers: 3


Input number 1: 4


Input number 2: 2


Input number 3: 1



Select Number System: 1


[1] Binary


[2] Octal


[3] Hexadecimal



Select operators: A


[A] Addition


[B] Subtraction


[C] Multiplication


[D] Division



The numbers are: 4, 2, 1


The number system is: Binary


The converted number is/are: 0100, 0010, 0001


The operator is: addition


Do you want to try again? (y/n)? y



1
Expert's answer
2022-01-19T13:02:20-0500
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>

#define MAX_NUMS	100
long long bin(int n)
{
  long long bin = 0;
  int rem, i = 1;


  while (n!=0) {
    rem = n % 2;
    n /= 2;
    bin += rem * i;
    i *= 10;
  }


  return bin;
}


int Octal(int decimalNumber)
{
    int octalNumber = 0, i = 1;


    while (decimalNumber != 0)
    {
        octalNumber += (decimalNumber % 8) * i;
        decimalNumber /= 8;
        i *= 10;
    }


    return octalNumber;
}
int main()
{
	int Nums[MAX_NUMS];
	int n,NumCount,NumSys,Ops;
	
	printf("\n\tInput No. of numbers: "); scanf("%d",&NumCount);
	for(n=0;n<NumCount;n++)
	{
		printf("\n\tInput Number #%d = ",n+1);	scanf("%d",&Nums[n]);
	}
	printf("\n\nPress-1 for Binary.");
	printf("\nPress-2 for Octal.");
	printf("\nPress-3 for Hexadecimal.");
	printf("\n\tEnter Option: "); scanf("%d",&NumSys);
	
	printf("\n\nPress-1 for Addition.");
	printf("\nPress-2 for Substraction.");
	printf("\nPress-3 for Multiplication.");
	printf("\nPress-4 for Division.");
	printf("\n\tEnter Option: "); scanf("%d",&Ops);


	printf("The numbers are: ");
	for(n=0;n<NumCount;n++) printf("%5d,",Nums[n]);
	if(NumSys==1) 
	{
		printf("\n\tThe operation is BINARY.");
		printf("\n\tThe converted number(s) is/are: ");
		for(n=0;n<NumCount;n++) printf("%lld\t",bin(Nums[n]));
	}
	if(NumSys==2) 
	{
		printf("\n\tThe operation is OCTAL.");
		for(n=0;n<NumCount;n++) printf("%d\t",octal(Nums[n]));
	}
	if(NumSys==3) 
	{
		printf("\n\tThe operation is HEXADECIMAL.");
		for(n=0;n<NumCount;n++) printf("%X\t",Nums[n]);
	}
	
	if(Ops==1) printf("\n\tThe operation is addition.");
	if(Ops==2) printf("\n\tThe operation is substraction.");
	if(Ops==3) printf("\n\tThe operation is multiplication.");
	if(Ops==4) printf("\n\tThe operation is division.");
	return(0);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS