Question

In: Computer Science

Create C program that takes 1 parameter: a number. Using that number, dynamically allocate a memory...

Create C program that takes 1 parameter: a number.

Using that number, dynamically allocate a memory so you store that number of integers.

Write integers in order starting from 1 until you fill all that memory.

Print the addresses and values of the first and the last integer stored in the memory.

Solutions

Expert Solution

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int n=atoi(argv[1]);
int *array = (int*)malloc(n*sizeof(int));
for(int i=0;i<n;i++)
{
*(array+i)=(i+1);
}
printf("Address of first integer: %p and Value of first integer: %d\n",&array[0],array[0]);
printf("Address of last integer: %p and Value of last integer: %d\n",&array[n-1],array[n-1]);
return 0;
}


Related Solutions

Create C program that takes 1 parameter: a number. Using that number, dynamically allocate a memory...
Create C program that takes 1 parameter: a number. Using that number, dynamically allocate a memory so you store that number of integers. Write integers in order starting from 1 until you fill all that memory. Print the addresses and values of the first and the last integer stored in the memory. Help ASAP!!!
Create a c program that takes 1 parameter, a number using that number, dynamically allocate a...
Create a c program that takes 1 parameter, a number using that number, dynamically allocate a memory so you store that number of integers write integers in order starting from 1 until you fill all that memory print the address and values of the first and the last integer stored in the memory
Write a modified version of the program below. In this version, you will dynamically allocate memory...
Write a modified version of the program below. In this version, you will dynamically allocate memory for the new C-string and old C-string, using the new keyword. Your program should ask the user for the size of the C-string to be entered, and ask the user for the C-string, then use new to create the two pointers (C-strings).   Then, call Reverse, as before. Don’t forget to use delete at the end of your program to free the memory! #include <iostream>...
Prime Sum C program !! Dynamically allocated memory Let P(n) denote the sum of the first...
Prime Sum C program !! Dynamically allocated memory Let P(n) denote the sum of the first n prime numbers. For example, P(1) = 2 and P(3) = 10, since the first three prime numbers are 2, 3 and 5, respectively. Write a program to determine the value of the function P(n) for different values of n. The first few prime sums are 2, 5, 10, 17, 28, 41, 58 and 77. Input The first line of the input file contains...
Create a C++ program that generates a random number from 1 to 100 using the rand()...
Create a C++ program that generates a random number from 1 to 100 using the rand() function. Give the user a total 5 chances to guess the number. Stop the program and indicate the user guessed the correct number and should be applauded. Also, please find out which guess was the closest to the actual number. For example, if the rand() produces 57 and the user guessed 10, 80, 52, 33 and 44 in their respective turns then print out...
Create a memory diagram for the following C program when the program reaches point 1. void...
Create a memory diagram for the following C program when the program reaches point 1. void foo (int *a); int bar(int *x); int search(int *c); int main(void) { int q, p=10; q= search(&p); return 0; } void foo(int *a) { *a += 2; //point 1 *f *= 10; } int bar(int *x) { return 2* *x; } int search(int *c) { int z= *c + bar(c); foo(c); return z; }
Can someone do this python program? Write a function that takes a number as a parameter...
Can someone do this python program? Write a function that takes a number as a parameter and then prints out all of the factors for that number.
Using loop statements, write a C++ program which takes the number of items that a shopper...
Using loop statements, write a C++ program which takes the number of items that a shopper wants to buy, and then takes the price of each item, and at the end tells the shopper how much she must pay. This is a sample of the output: How many items do you have in your basket? 3 Enter the price in dollar? 10.25 Enter the price in dollar? 20.75 Enter the price in dollar? 67.5 You must pay 98.5 $ today.
with C# create a console application project that outputs the number of bytes in memory that...
with C# create a console application project that outputs the number of bytes in memory that each of the following number types use, and the minimum and maximum values they can have: sbyte, byte, short, ushort, int, uint, long, ulong, float, double, and decimal. Try formatting the values into a nice-looking table! More Information: You can always read the documentation, available at https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting for Composite Formatting to learn how to align text in a console application. Your output should look...
Write a program in C or C++ that takes a number series of size n (n...
Write a program in C or C++ that takes a number series of size n (n integers) as input from the user, push all the numbers to the stack, and reverse the stack using recursion. Please note that this is not simply popping and printing the numbers, but the program should manipulate the stack to have the numbers stored in reverse order. In addition to the provided header file, the students can use the following function to print the content...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT