# Homework Help: C: String arithmetic

Tags:
1. Jan 13, 2016

### gruba

1. The problem statement, all variables and given/known data
Write a program (without using GMP library - https://gmplib.org) which performs arithmetic operations on large positive integers (addition, subtraction, multiplication and division). Maximum number of digits in one number is 100.
Large number is the number that can't be represented by standard data types (long long, ...), and it is represented as a string.
Then allow incrementing and decrementing of a string, and finding the smallest and the largest string in an array of n strings.

2. The attempt at a solution

How would you do incrementing, decrementing and comparing Bignum strings?
Here is the addition:
Code (Text):

#include<stdio.h>
#define MAX 100//max. number of digits
typedefstruct
{
int arr[MAX];//array for one number
}NUMBER;
{
int i,digit=0;
char ch[101];
scanf("%s",ch);

while(ch[digit])//number of digits
digit++;

for(i=0;i < MAX;i++)
{
digit--;
if(digit >=0)
else
}
}

{
int carry=0;
int i,temp;
for(i=0;i < MAX;i++)
{
temp=a.arr[i]+b.arr[i]+carry;//sum
carry=temp /10;//store carry
}
}

{
int i;

for(;i>=0;i--)
}
int main()
{
NUMBER x,y,z;
printf("enter two positive integers: \n");
print(&z);
return0;
}

2. Jan 13, 2016

### Staff: Mentor

Incrementing is just adding 1, and decrementing is subtracting 1 (or adding 9999.....99 and ignoring the overflow)

How do you compare numbers like those by eye? The same can be done in code.
Code (Text):
35356959849283293
35846625235464635
4735939384293894

3. Jan 13, 2016

### Staff: Mentor

There are a couple of missing spaces in your code, below.
typedefstruct needs a space after typedef
voidprint needs a space after void