IN C PROGRAMMING, NOT C++
Here is Assignment A8 for reference.
CODE:
#include<stdio.h>
#include<conio.h>
#define SIZE 6 //define the size of array
void getData(double *array, int size){
int i;
printf("Please Enter %d numbers\n", size);
for(i=0; i<size; i++){
scanf("%lf", (array+i));//input the
values from command line
}
}
void displayData(double *array, int size){
printf("\n\n ----------------- Displaying the array
data ----------------------\n\n");
int i;
printf("\n------- Method 1 ----------\n\n");
for(i=0; i<size; i++){
printf("%.2lf ", array[i]);//print
the numbers to 2 decimal places
}
printf("\n\n\n------- Method 2 ----------\n\n");
for(i=0; i<size; i++){
printf("%.2lf ",
*(array+i));//print the numbers to 2 decimal places
}
printf("\n\n\n------- Method 3 ----------\n\n");
for(i=0; array+i < array+size; i++){
printf("%.2lf ", array[i]);//print
the numbers to 2 decimal places
}
printf("\n\n\n------- Method 4 ----------\n\n");
for(i=0; array+i < array+size; i++){
printf("%.2lf ",
*(array+i));//print the numbers to 2 decimal places
}
}
void main(){
double grade[SIZE];//create grade array of size=SIZE
i.e 6
getData(grade, SIZE);//input the data to the
array
displayData(grade, SIZE);//print the array data
getch();//hold the console output
}
SCREENSHOTS:
OUTPUT:
In case of any doubts, dolet me know in the comments section. I'll get it resolved :)
IN C PROGRAMMING, NOT C++ Rewrite the program you submitted for A8 to use pointers, pointer...
Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as follows: If you did not complete A8, you will need to start with those instructions, and then, change your code based on the instructions here The main() function should: Create a fixed or dynamic array, e.g., double grade[SIZE] or double *grade = malloc(...) or calloc(...) Concerning the function call for getData(), pass the address of the array and its size to pointers; depending on...
Modify the following C code to the changes listed below. Please format code correctly. #include <stdio.h> #include <stdlib.h> #define SIZE 5 void displayData(int [], int s); void getData(int array[], int size) { for(int i=0; i<SIZE; i++) { scanf("%d", &array[i]); } } int main() { int grades[SIZE]; for(int i=0; i<SIZE; i++) { grades[i] = 0; } getData(grades,SIZE); displayData(grades, SIZE); } void displayData(int grades[], int size) { for(int i=0; i<size;...
Write in C code: Define an array f=[23,-12,34,-56,-10,12,19], using call-by-reference (use pointers), to pass the array to a function, named Summation. In main: Define array, pass array, print out the array and the result returned from Summation on screen. In function Summation: 1)take array and size from main 2) sum each element according to the following rules 3) if the value of f(i) is positive, add 2*f(i) to the sum 4)if the value of f(i) is negative, add -3*f(i) to...
C programming. 1.Create a program that does the following - Creates three pointers, a character pointer professor, and two integer pointers student_ids, grades - Using dynamic memory, use calloc to allocate 256 characters for the professor pointer - Prompts the professor for their name, and the number of students to mark. - Stores the professor’s name using the professor pointer and in an integer the number of students to mark. - Using dynamic memory, use malloc to allocate memory for...
Here's an assignment that'll give you some practice with pointers. All you have to do is write a program that allows the user to populate an array of doubles (5 values) by calling the function InitArray. After the user has entered all the values, then call the function DispRevArray to display the array in reverse. Main will create and allocate space for an array of type double for 5 elements. Then you will create and allocate a pointer that will...
Hello I need help with this program. Should programmed in C!
Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...
C programming
3. (40 pts) Define an array fof size 10, using call-by-reference (that is, use of pointers), to pass the array to a function, named summation In main: define array, pass array, print out the array and the results on screen In function summation: take array from main and sum the array using the formula below: 10 fO 2 246 NOTE: you must use call-by-reference (the pointer) to call functions, as required; otherwise, no credits will be given.
Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question: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...
In Exercise 1, displayAnimal uses an Animal reference variable as its parameter. Change your code to make the displayAnimal function anim parameter as an object variable, not a reference variable. Run the code and examine the output. What has changed? Polymorphic behavior is not possible when an object is passed by value. Even though printClassName is declared virtual, static binding still takes place because anim is not a reference variable or a pointer. Alternatively we could have used an Animal...
Question: C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to prov... C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to provide practice programming using structs and pointers. Your program will accept user input and store it in a dynamic array of structs. First, you will define a structure to describe a item to be bought. Your program will prompt the user for the initial size of the array. It will...