Programming language C
Please go through this carefully. Needs function void add(int *a1, int n, int *a2)
Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on.
You need to check for even and odd length of arrays. In case of an odd number of integers, leave the central integer in the original list as it is.
As part of the solution, write and call the function add() with the following prototype. The add function should add the numbers of a1 as described above.
void add(int *a1, int n, int *a2);
The add() function should use pointer arithmetic – not subscripting – to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function.
In the main function, ask the user to enter the length of the array, declare the array with the length, call the add function, and display the output array.
Example input/output #1: Enter the length of the array: 5 Enter the elements of the array: 8 4 1 3 9 Output: 17 7 1
Example input/output #2: Enter the length of the array: 4 Enter the elements of the array: 3 4 1 7 Output: 10 5
Source code:
#include<stdio.h>
#include<stdlib.h>
void add(int *a1,int n,int *a2)
{
int i,j,k=0;
if(n%2==0)
{
for(i=0,j=n-1;i<j;i++,j--)
{
*(a2+k)=*(a1+i)+*(a1+j);
k++;
}
}
else
{
for(i=0,j=n-1;i!=j;i++,j--)
{
*(a2+k)=*(a1+i)+*(a1+j);
k++;
}
*(a2+k)=*(a1+i);
k++;
}
}
main()
{
int *a1,*a2,n,i;
printf("Enter the total array elements of a1:
");
scanf("%d",&n);
a1=(int*)malloc(sizeof(int)*n);
if(n%2==0)
a2=(int*)malloc(sizeof(int)*(n/2));
else
a2=(int*)malloc(sizeof(int)*(n/2+1));
for(i=0;i<n;i++)
{
printf("Enter element %d:
",(i+1));
scanf("%d",(a1+i));
}
add(a1,n,a2);
printf("\nArray 1 elements are: ");
for(i=0;i<n;i++)
{
printf("%d ",*(a1+i));
}
printf("\nArray 2 elements are: ");
if(n%2==0)
{
for(i=0;i<n/2;i++)
{
printf("%d
",*(a2+i));
}
}
else
{
for(i=0;i<=n/2;i++)
{
printf("%d
",*(a2+i));
}
}
}
Output:


Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...
Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...
In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...
In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...
1. Write a program that reads in two arrays (a1 and a2) of numbers and creates a new array (a3) of numbers such that the new array contains all the unique numbers of a1 and a2. Assume the input array elements are unique elements. In the main function, ask the user to enter the length of each array, declare and reads in the numbers for each array, and calculate and display the output array. Example input/output #1: Enter the length...
Write a c program that finds the uncommon elements from two array elements using pointers only . For example : Enter the length of the array one : 5 Enter the elements of the array one: 9 8 5 6 3 Enter the length of the array two: 4 Enter the elements of the array two: 6 9 2 1 output: 8 5 3 2 1 void uncommon_ele(int *a, int n1, int *b, int n2, int *c, int*size); The function...
1. Write a function that converts a string into an int. Assume the int is between 10 and 99. Do not use the atoi() or the stoi() function. 2. Write a function prototype for problem 1. 3. Write a function call for the function you defined in problem 1. 4. Write a function that converts an int between 10 and 99 into a string. 5. Write a function prototype for problem 4. 6. Write a function call for function you...
pls help Write a method void remove(int *a, int index) that will remove the number at the given index and shift all remaining numbers one position to the left in the array a. Assume 1that the last element of the array is -1. Now, write a main function that will define an array int A[40]=[3, 5, 9, 17, 24, -1]; read from user input an index; and call the method remove passing array A and the index given by the...
sort.c
#include <stdlib.h>
#include <stdio.h>
#include "libsort.h"
int main()
{
int* array;
int size, c;
float median;
printf("Enter the array size:\n");
scanf("%d", &size);
array = (int*) malloc(size *
sizeof(int));
printf("Enter %d integers:\n", size);
for (c = 0; c < size; c++)
scanf("%d",
&array[c]);
sort(array, size);
printf("Array sorted in ascending
order:\n");
for (c = 0; c < size; c++)
printf("%d ",
array[c]);
printf("\n");
median = find_median(array,...
Create qz5.c to include all of the following function prototypes: void check1(char *, char, int *); void check2(char *, char, int *); void display(char, int); Then, implement main() to perform the tasks below: Define a 10-element char array with initial values of any lower case letters of your selection. Values can duplicate. Define a pointer that points to the above array. Print the array completely with double spaces before each character. See screenshot below for a sample. Call check1() with...
IN C++ Write a function numberOfOddNumbers that takes an array of integers and its size (length) as parameters and then returns the number of the odd numbers found in the array. For example, if an array called list stores the following values: int list []= { 1,1, 8,6,9,4,3,9595,0 }; Then the call of numberOfOddNumbers (list,9) should return 5. If instead, the list had stored these values: int list2[] = { 2, 4, 6, 8, 10, 208 }; Then the call...