Question

Write a C program convert.c that converts each number in an array by the sum of...

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 function should use pointer arithmetic (instead of array subscripting). In other words, eliminate the loop index variables and all use of the [] operator in the function.

1) The program will read in the number of element of the array, for example, 4, then read in the numbers in the array, for example, 3 16 81 9.

2) In the main function, declare the input array after reading in the number of element of the array, then read in the elements, and declare the output array, then call the convert function. The main function should display the converted array.  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Note:- if you have any query then comment below.please upvote.

#include<stdio.h>

void convert(int *a1,int n,int *a2)
{
int i;
for(i=0;i<n;i++)
{
a2[i]=(a1[i]+6)%10;
}
}
int main()
{
int n,i;
printf("Enter the size of array; ");
scanf("%d",&n);
int a1[n],a2[n];

printf("Enter the array elements:\n ");
for(i=0;i<n;i++)
{
scanf("%d",&a1[i]);
}

convert(&a1,n,&a2);
//printing the value of array a2 for reminder
for(i=0;i<n;i++)
{
printf("%d ",a2[i]);
}
}

Enter the size of array 5 nter the array elements: 928 4 2 940 3 Process returned 5 〈0x5 〉 execution time : 11.798 s Press an

Add a comment
Know the answer?
Add Answer to:
Write a C program convert.c that converts each number in an array by the sum of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    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...

  • Write a c program that finds the uncommon elements from two array elements using pointers only...

    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...

  • In C language Write a program that includes a function search() that finds the index of...

    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...

    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...

  • this program is in C. Write a program that computes the number of elements in an...

    this program is in C. Write a program that computes the number of elements in an array divisible by a user specified number. Declare an integer array of size 7 and read the array elements from the user. Then, read a number k from the user and compute the number of elements in the array divisible by k. Consider the following example. 3 elements in this array are divisible by 2 ({2,2,4}). Sample execution of the program for this array...

  • Write a program in C++ language that finds the largest number in an array of positive...

    Write a program in C++ language that finds the largest number in an array of positive numbers using recursion. Your program should have a function called array_max that should pass in an int array, and an int for the size of the array, respectively, and should return an int value. As an example, given an array of size 10 with contents: {10, 9, 6, 1, 2, 4, 16, 8, 7, 5} The output should be: The largest number in the...

  • - Write a program that performs several operations on an array of positive ints. The program...

    - Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...

  • please use c ++ language and write the comment too. thanks Pointer Arithmetic Write a function...

    please use c ++ language and write the comment too. thanks Pointer Arithmetic Write a function that passes an array address to a function as a pointer. Using pointer arithmetic, the function determines the average, high, and low value of the array. Your function should have this header: void pointerArithmetic(int *array, int size, double &average, int &high, int &low) Parameter size is the number of elements in array. You may not use the subscript notation [] inside your function –...

  • in C language Write a program to find the element of an array, which occurs maximum...

    in C language Write a program to find the element of an array, which occurs maximum number of times and its count. The program should accept the array elements as input from the user and print out the most occurring element along with its count. Hint: array size is 5. For example: Enter array elements (array size 5): 22321 Output: Max occurring element: 2. count: 3

  • Write a C program that takes two sets of characters entered by the user and merge...

    Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT