Program to add function for long integer

Assignment Help Programming Languages
Reference no: EM13948498

Long interger linked list add function

Posting I am working on program assignment in structures (c language)after entering the required intergers the add function will not compile.I receive error messages I am using a Microsoft c, c++ 6.0 compiler. The help required is to provide a working add function in c. Hopefully after that I will be be able to write similar functions to subtract multiply and divide.

The given problem requires that an add function be provided that should add two given lists n and m.

The source code of the problem is attached

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node
{
int data; // char field data
struct node* next; //pointer field next
}NODE,*NODEP,**NODEPP; //defines three common types

// Function prototypes

void addhead(NODEPP listp,int value);

void getinput1( NODEPP );

void getinput2( NODEPP );
void showtext ( char* );
void showlist( char*,NODEP);
void add_list( listp );
void add();
void subtract();
void multiply();
void divide();
void main (void)
{

char cmd;

showtext(" Enter a to add, s to subtract, m to multiply , d to divide,q when finished");
for (;;)
{
scanf("%c",&cmd);

switch(cmd)
{
case 'a': add(); //addition

break;
case 's': subtract(); // subtract
break;
case 'm':multiply(); //multiply
break;
case 'd':divide(); //divide
break;
case 'q':
exit(0);
break;
}
showtext("nEND OF RUNn");
}

}// end of main

// Adds new node at the heaad of the list. puts value in the data field

void addhead(NODEPP listp, int value)
{

NODEP p = (NODEP)malloc( sizeof (NODE));
p->data = value; // Data Field gets value
p->next = *listp; // links p node to old head
*listp = p; // makes p a new head node
}

void getinput1( NODEPP listp ) //creats a linked list containing numbers
{ // entered by the user.(uses add_to_list)

int n;

printf("Enter a series of integers (! when finished ):");

while((scanf("%d",&n))==1)

addhead(listp,n); //Add new node to list

}

void getinput2( NODEPP listp) //creats a linked list containing numbers
{ // entered by the user.(uses add_to_list)

int m;

printf("Enter a second series of integers (! when finished ):");

while((scanf("%d",&m))==1)

addhead(listp,m); //Add new node to list

}

void showtext ( char* string ) //Displays text
{

printf(string);

}

void showlist(char* string, NODEP list) // Prints list to screen
{

int i =1;
showtext(string);
while (list !=NULL)
{
printf( "%5d",list->data);
if(i++% 10 ==0)showtext("n");
list =list->next;
}
showtext("n END OF LISTn");

}

void add(NODEPP listp ) //add function
{
NODEP n= NULL;
NODEP m =NULL;
NODEP t= NULL;

int tPtr;
tPtr=&t;
showtext( "**INITIAL LIST DATA**n");

getinput1( &n);
showlist("List 1n",n);
getchar();

getinput2( &m);
showlist("List 2n",m);

getchar();

while(t!=0)
{
t->data= n->data+m->data;
}

showlist( "The sum of List 1 and List 2 is:n",t);
}
void subtract(NODEPP listp)

{

}

void multiply()
{

}

void divide()
{

}

Reference no: EM13948498

Questions Cloud

Creates a series of random 2d objects : Part 1: Create a program (OpenGL, or DirectX) that creates a series of random 2D objects, (or 3D objects that only move in 2D), about 25 is probably good but you may need more or less and has them move around on the screen, they should wrap around..
Determine the angular velocity of the disk : The 10-g bullet having a velocity of 800 m>s is fired into the edge of the 5-kg disk as shown. Determine the angular velocity of the disk just after the bullet becomes embedded into its edge. Also, calculate the angle u the disk will swing when it..
Replace the letter n with the letter g and alter the pointer : Then how do I replace the letter N with the letter G and alter the pointers so that the new letter appears in the list in its proper place in alphabetical order?
Prepare an annual budget for the activity of moving material : Prepare an annual budget for the activity of moving materials, assuming that all of the capacity of the activity is used. Identify which resources you would treat as fixed costs and which would be viewed as variable costs.
Program to add function for long integer : The help required is to provide a working add function in c. Hopefully after that I will be be able to write similar functions to subtract multiply and divide.
Does the test show enough evidence to reject the findings : A newspaper writes" this show that there is roughly a 92 percent chance that the difference between the two counts is due to some irregularity other than simply chance alone" Do you agree with the newspaper's interpretation of the p-value Explain ..
Horizontal and vertical components of reaction : If it is supported by the cable AB and hinge at C, determine the tension in the cable when the truck begins to accelerate at 5 m> s2. Also, what are the horizontal and vertical components of reaction at the hinge C?
Design a normalized relational database management system : Design a completely Normalized Relational Database Management System that meets both the high-level and technical requirements of the web-based project management system.
Prepare a schedule of cash receipts for august and september : Kendall Law Firm has found from experience that 30 percent of its services are for cash. Prepare a schedule of cash receipts for August and September.

Reviews

Write a Review

Programming Languages Questions & Answers

  Design program to asks for number of fat grams

Design a program that asks for the number of fat grams and calories in a food item. Validate the input as follows: Make sure the number of fat grams and calories are not less than 0.

  Create application program to declare two circles

Create an application program that declares two circles set radius of one manually but allow the other to use default value supplied by constructor then display each circles values.

  Timer interrupt to coordinate peripherals on microcontroller

The timer interrupts to coordinate peripherals on the microcontroller. Use code from prior labs to drive the peripherals and will make minor modifications to use the interrupts.

  Designing class to denote person-s height

Design a class, PersonHeight, to denote the person's height. Our class will include the following members.

  Create a windows form application in c#

The total price will be the number of computed rental days times the cost for the model of car selected ($19.95/day for Compact, $24.95/day for Standard and $39/day for Luxury).

  Application to make a guessing game

The number I guess should be compared with the random generated number. If I guess correctly, the second field could display a message like "you win", else it should display "more" or "less" depending on my guess. If I fail to guess those 5 times,..

  Program a robot to run mile-long steeplechase

Program a robot to run mile-long steeplechase where steeples are made from beepers instead of wall segmesnts. the robot must jumb the steeples in this race by picking the beepers that make up the steeples.

  Write recursive programs with lists and backtracking

Objectives: For this assignment, you'll learn how to use Prolog to write recursive programs with lists and backtracking. Problem: There are three parts to this assignment. They are all related

  Design class named loan that holds account number

Design a class named Loan that holds account number, name of account holder, amount borrowed, term, and interest rate. Include methods to set values for each data field.

  Write a program to assign the integer values

Write a program to assign the integer values 1 through 25 to a 25-element integer array. Then, print the array as five separate lines, each containing five elements separated by commas

  Explain the use of xml dom

When the XMLHttpRequest object receives XML data, it parses and stores the data as an XML DOM object in the responseXML property. Why does the XML DOM used in the above example?

  Identify where each security application or countermeasure

Briefly describe each of the listed network security applications and security countermeasures. Identify where each security application or countermeasure is located within the seven domains of a typical IT infrastructure.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd