Write a C program not C++, only C to do the following with pointer: 1) Declare a
ID: 3913547 • Letter: W
Question
Write a C program not C++, only C to do the following with pointer:
1) Declare an array of pointers named alpha of 15 components of type int.
2) Output the value of the 12th component of the alpha.
3) Set the value of the 5th component of the alpha to 22.
4) Set the value of the 9th component of the alpha to the sum of the 7th and 14th
components of the alpha.
5) Set the value of the 3rd component of the alpha to four times the value of the 9th
component minus 33.
6) Output alpha so that three (3) components appear on each line.
Explanation / Answer
1.
Declare an array alpha of 15 components of type int.
int alpha[15];
2.
Output the value of the 10th component of the alpha array.
printf("%d ",alpha[9]);
3.
Set the value of the 5th component of the alpha to 22.
alpha[4] = 22;
4.
Set the value of the 9th component of the alpha to the sum of the 7th and 14th
components of the alpha.
alpha[8] = alpha[6] + alpha[13];
5.
Set the value of the 3rd component of the alpha to four times the value of the 9th
component minus 33.
alpha[2] = 4*alpha[8] – 33;
6)
Output alpha so that three (3) components appear on each line.
for(int i = 0; i <= count; i++)
{
if (i % 3 == 0)
{
printf(" ");
}
printf("%d ",alpha[i]);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.