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

\" C programming\" Create a program called dataExercise.c that declares the foll

ID: 3588952 • Letter: #

Question

" C programming"

Create a program called dataExercise.c that declares the following variables and displays their values:

1) Declare a character variable with value 'a', and display the character using printf with a %c format. Then add a second printf that displays the characater with a %d format.

2) Declare a short int variable with a value set to the maximum value of a short int (the maximum value for whatever machine I happen to use to grade your assignment - so use the correct limits.h constant). Display the value using printf with a %d format.

3) Declare a double variable with a value set to positive infinity. Display the value using printf with a %f format.

4) Prompt the user and accept the following 4 types of values from a single input line: char int char float

5 )Display the values that were read in (4)

6) Prompt the user and accept the following types of values from a single input line: char float int char

7) Display the values that were read in (6)

8 )Prompt the user and accept an integer value

9 ) Display the value read in (8) in a right-justified field of width 15, with leading zeroes

10) Prompt the user and accept a float value

11) Display the value read in (10) in a right-justified field of width 15, with 2 decimal points of precision, and leading spaces

Sample Output , sample input

Program: dataExercise.c
Author: Doug Jones
a
97
32767
+INF
Enter char int char float: a 5 b 5.5
You entered: 'a' 5 'b' 5.500
Enter char float int char: a 6.5 6 b
You entered: 'a' 6.500 6 'b'
Enter an integer value: 5
You entered: 000000000000005
Enter a float value: 6.5
You entered:            6.50

-----------------------------------PC OUTPUT--------------------------------------------

Program: dataExercise.c
Author: Doug Jones
a
97
32767
1.#INF00
Enter char int char float: a 5 b 5.5
You entered: 'a' 5 'b' 5.500
Enter char float int char: a 6.5 6 b
You entered: 'a' 6.500 6 'b'
Enter an integer value: 5
You entered: 000000000000005
Enter a float value: 6.5
You entered:            6.50

Explanation / Answer

#include <stdio.h>
#include <limits.h>
#include <math.h>
int main()
{
char test='a',c1,c3,d1,d4;
int c2,d3,i;
float c4,d2,d;
double f = INFINITY;
printf(" %c",test);
printf(" %d",test);
printf(" %d", SHRT_MAX);
printf(" %f",f);
printf(" Enter in format :char int char float");
scanf("%c %d %c %f",&c1,&c2,&c3,&c4);
printf(" You entered:%c %d %c %f ",c1,c2,c3,c4);
printf(" Enter in format :char float int char");
scanf("%c %f %d %c",&d1,&d2,&d3,&d4);
printf(" You entered:%c %f %d %c ",d1,d2,d3,d4);
printf(" Enter an integer value: ");
scanf("%d",&i);
printf("%015d", i);
printf(" Enter an decimal value: ");
scanf("%f",&d);
printf("%15.2f", d);
return 0;
}

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