Question

•The variable used to determine the length of your arrays should be a global variable. • In main, you will ask the user for t
without allocating memory dinamical
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C CODE:

#include<stdio.h>
int array_length;//Global Variable
void aaa(float ar1[],float ar2[]){
   float ar3[array_length];//Array declaration
   int i=0;
   //Summation stored into that array
   for(i=0;i<array_length;i++){
       ar3[i]=ar1[i]+ar2[i];
   }
   printf("The values added together are: \n");
   for(i=0;i<array_length;i++){
       printf("%lf \t",ar3[i]);
   }
}
int main(){
   int n,i;
   //Prompting User to give array range
   printf("\nHow many values will your array have?");
   scanf("%d",&n);
   //Assigning value of n toGlobal Variable.
   array_length=n;
   float ar1[n],ar2[n];
   printf("Please provide values of 1st array\n");
   //Taking input
   for(i=0;i<n;i++){
       scanf("%f",&ar1[i]);
   }
   printf("\nPlease provide values of 2nd array\n");
   for(i=0;i<n;i++){
       scanf("%f",&ar2[i]);
   }
   aaa(ar1,ar2);//Passing two array
   return 0;
}

OUTPUT:

How many values will your array have?3 Please provide values of 1st array 1.1 1.2 1.3 Please provide values of 2nd array 4.1

PLEASE DO LIKE AND DO COMMENT IF YOU ARE HAVING ANY DOUBTS.

Add a comment
Know the answer?
Add Answer to:
without allocating memory dinamical •The variable used to determine the length of your arrays should be...
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
  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • Write one single program that does all of the following tasks, in order. You should practice...

    Write one single program that does all of the following tasks, in order. You should practice proper Top Down Design and Procedural Abstraction techniques unless otherwise noted. -Write a program with the following functions, with the correct number of arguments for each function. -void fillUpArray ( argument1, argument2) This function should read in a text file called "villagers.txt" (You will create your own). "villagers.txt" is a text file of numbers in ascending order, ranging anywhere from 1 to 100, nonrepeating....

  • I should use the array and loop to create a java program according to the instruction,...

    I should use the array and loop to create a java program according to the instruction, but I have no idea how to do it. Introduction This lab assignment continues to give you practice using loops, particularly loops with variable termination conditions, and it also provides you an opportunity to use one-dimensional arrays. Recall that an array is used to store a collection of data. The data can be values of Java primitive data types or else objects (for instance,...

  • CS 241 Program 03 Due: Thursday, October 18th Main topics: Arrays& Pointers Memory allocation ram Specification:...

    CS 241 Program 03 Due: Thursday, October 18th Main topics: Arrays& Pointers Memory allocation ram Specification: A stack is a container that can be defined in terms of an array where all adds are preformed at the end of the sequence of existing values, and all removes are also preformed at end of the sequence of existing values. An empty stack is one that has no existing values in the array at all. We use the notion of top of...

  • Concepts tested by the program: Working with one dimensional parallel arrays Use of functions Use of...

    Concepts tested by the program: Working with one dimensional parallel arrays Use of functions Use of loops and conditional statements Description The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown below. The Lo Shu Magic Square has the following properties: The grid contains the numbers 1 – 9 exactly The sum of each row, each column and each diagonal all add up to the same number. s is shown below: Write a program that...

  • Need the c code please, also please only use <stdio.h> library. Simple code please Define a...

    Need the c code please, also please only use <stdio.h> library. Simple code please Define a struct with teg Capacitor that holds the following Information about a capacitor: Model number (e.g. 11-123U), capacitance (e.g. 1000 u.f), voltage (e.g. 2.5 V), cost {$6.50} Create your main program file capacltorsInfac. Declare two variables of type struct Capacitor and populate them with the following values: First' variable: model Is 11-123U, capacitance Is 100, voltage Is 25 and cost Is $6.00 Second variable: model...

  • PROGRAM DESCRIPTION: In this assignment, you will be creating a memory matching game in C++. In t...

    c++ PROGRAM DESCRIPTION: In this assignment, you will be creating a memory matching game in C++. In this game, the user will need to match up the pairs symbols A,B,C,D,E on a 4x4 array. For example, the array could be initialized like the following: In this case, X represents an empty slot. The goal is for the user to match the A to the A, the B to the B, etc, until all pairs are matched up to win the...

  • Arrays Arravs Introduction Your ninth programming assignment will consist of two C++programs. Your programs should compile...

    Arrays Arravs Introduction Your ninth programming assignment will consist of two C++programs. Your programs should compile correctly and produce the specified output. Please note that your programs should comply with the commenting and formatting rules we discussed in class. Please see the descriptive ile on eLearning for details. Program 1- Linear Search Algorithm In Computer Science, it is often very important to be able to locate a specific data item inside a list or collection of data. Algorithms that perform...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

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