Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a simple C program using pointers. The program has only the main function,

ID: 670083 • Letter: W

Question

Write a simple C program using pointers. The program has only the main function, in which there are 2 variables: (a) small that can hold real values in the range [0, 1], inclusive (the square brackets on both ends of the range mean that both “border” values are included in the range); and (b) large that can hold only integer values in the range [103, 106]. The program should do the following:

1) Declare variables named small and large with appropriate data types, and arbitrary initial values (limit the number of digits after the decimal point to 5).

2) Print the values of small, large and their sum.

3) Define two pointers: one pointing to small and the other to large.

4) Use pointers to assign new, different values for small and large, and print small and large.

5) Print the values of both pointers (i.e., the addresses of the small and large variables).

6) Ask the user to enter new values for the above variables, and show an error message if a variable receives an out-of-range value. For example, entering 3.6 for small or 100 for large should result in an error message.

Explanation / Answer

#include<stdio.h>
void main()
{
float small=0.15634;
int large=104;
float *fptr;
fptr=&small;
int *iptr;
iptr=&large;
float sum=small+large;
printf("The sum of %6.5f and %d is %8.5f ",small,large,sum);
*fptr=0.87634;
*iptr=102;
printf("Modified small is now %6.5f ",*fptr);
printf("Modified large is now %d ",*iptr);
printf("Address of small is: %x ", fptr);
printf("Address of large is: %x ", iptr);
printf("Please enter a new value for variable small between 0 and 1");
scanf("%6.5f",&small);
fptr=&small;
printf("%6.5f",*fptr);
if(*fptr<0||*fptr>1)
{
  printf("Please enter a value of small between 0 and 1");
  scanf("%6.5f", fptr);
}
printf("%f",*fptr);*/
printf("Please enter a new value for variable large between 103 and 106 ");
scanf("%d",&large);
if(large<103 || large>106)
{
  printf("Please enter a value between 103 and 106 ");
  scanf("%d",&large);
}
printf("Modified small is now %6.5f ",small);
printf("Modified large is now %d ",large);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote