Write a program that will do the following: 1. Define a 7 element float array na
ID: 3622090 • Letter: W
Question
Write a program that will do the following:1. Define a 7 element float array named ar_x
2. Define 3 integer variables s , u and v
3. Define 3 integer pointer variables pts , ptu and ptv and have these point to the variables defined above, respectively
4. Using scanf() enter the 3 variables from the keyboard using the pointers to them
5. Send to the standard output both the address and value of each variable (s, u & v)
6. Send to the standard output the sum of all three variables(s, u & v) (using the pointers)
7. Send to the standard output the result of s divided by v (using the pointers)
8. Send to the standard output the result of u multiplied by v(using the pointers)
9. Define two pointers pxa and pxb to point to the 3rd and 6th elements of array ar_x
10. Send to the standard output the difference between pxa and pxb
11. Send to the standard output the address of pxa
12. Increment pxa by 1 and send to the standard output the new address of pxa
I will be using the compiler Dev C++ please make sure it compiles. This is a entry level C++ course...
Lifesaver given to the CORRECT solution!
Explanation / Answer
Hope this helps. Let me know if you have any questions. Please rate. :) #include int main() { /**** * * NOTE: if you want addresses printed in hexadecimal instead of * decimal, just change the %d to %x within the printf function * ****/ //1. Define a 7 element float array named ar_x float ar_x[7]; //2. Define 3 integer variables s , u and v int s, u, v; //3. Define 3 integer pointer variables pts , ptu and ptv and have these point to the variables defined above, respectively int *pts, *ptu, *ptv; pts = &s; ptu = &u; ptv = &v; //4. Using scanf() enter the 3 variables from the keyboard using the pointers to them printf("Enter integers s, u, and v: "); scanf("%d %d %d", pts, ptu, ptv); //5. Send to the standard output both the address and value of each variable (s, u & v) printf("Address of s: %d ", pts); printf("Value of s: %d ", *pts); printf("Address of u: %d ", ptu); printf("Value of u: %d ", *ptu); printf("Address of v: %d ", ptv); printf("Value of v: %d ", *ptv); //6. Send to the standard output the sum of all three variables(s, u & v) (using the pointers) printf("Sum of all three: %d ", *pts + *ptu + *ptv); //7. Send to the standard output the result of s divided by v (using the pointers) printf("Using integer division, s / v = %d ", (*pts)/(*ptv)); printf("Using floating point division, s / v = %f ", (*pts * 1.0) / (*ptv * 1.0)); //8. Send to the standard output the result of u multiplied by v(using the pointers) printf("u * v = %d ", (*ptu) * (*ptv)); //9. Define two pointers pxa and pxb to point to the 3rd and 6th elements of array ar_x float *pxa, *pxb; pxa = ar_x + 2; // assuming the 1st element is ar_x[0] (as opposed to the "0th" element) pxb = ar_x + 5; //10. Send to the standard output the difference between pxa and pxb printf("pxa - pxb = %d ", pxa - pxb); //11. Send to the standard output the address of pxa printf("Address of pxa = %d ", pxa); //12. Increment pxa by 1 and send to the standard output the new address of pxa pxa++; printf("New address of pxa = %d ", pxa); return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.