Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1 Begin this program by creating two arrays of integers, each holding te

ID: 665622 • Letter: P

Question

Problem 1

Begin this program by creating two arrays of integers, each holding ten elements of data. Create a third array of integers for a result array. Your main program will take the two arrays of integers and pass them to the function subtract(). Inside the function, subtract the first array from the second array and put the difference into the third array. Print the values of all three arrays back in the main program.



Problem 2

Write a C program containing a linked list of ten integer numbers. Have the program display the numbers in the list.



Problem 3

Write a C program which defines and uses a macro min(x,y) that, when given two numbers, returns the smaller of the two.

Explanation / Answer

Problem 1

#include<stdio.h>

void subtract(int first[],int second[],int result[])
   {
       for(int i=0;i<10;i++)
       {
           result[i]=second[i]-first[i];
       }
   }

int main()
   {
       int first[]={2,5,2,1,6,2,5,2,1,6};
       int second[]={7,9,10,12,45,7,9,10,12,45};
       int result[10];

       subtract(first,second,result);
printf("First array ");
       for(int i=0;i<10;i++)
       {
printf("%d ",first[i]);
       }

       printf(" Second array ");
       for(int i=0;i<10;i++)
       {
printf("%d ",second[i]);
       }

       printf(" Result array ");
       for(int i=0;i<10;i++)
       {
printf("%d ",result[i]);
       }
   }

Problem 2


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

void main()
{
struct node
{
int num;
struct node *ptr;
};

typedef struct node NODE;

NODE *head, *first, *temp=0;
int count = 0;
int choice = 1;
first = 0;
int ch=0;
while(ch<10)
{
head =(NODE*) malloc(sizeof(NODE));
printf("Enter the data item ");
scanf("%d", &head-> num);

if(first != 0)
{
temp->ptr = head;
temp = head;
}
else
{
first = temp = head;
}
fflush(stdin);

ch++;
} /* End of while */

temp->ptr = 0;
temp = first; /* reset temp to the beginning*/
printf(" Elements of the linked list is ");

while(temp!=0)
{
printf("%d=>", temp->num);
count++;
temp = temp -> ptr;
}
printf("NULL ");
printf("No. of nodes in the list = %d ", count);
}

Problem 3

#include<stdio.h>

#define min(x,y) x<y?x:y

int main()
{
int x=3;
int y=9;
printf("Smaller of two is %d",min(x,y));
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote