\" C Programming\" Write a program that declares variables of the following type
ID: 3599064 • Letter: #
Question
" C Programming"
Write a program that declares variables of the following types, and initializes
each variable to some non-zero value:
1. int
2. long int
3. unsigned int
4. float
5. double
6. long double
7. char
For each variable, display the maximum (positive) non-infinite value that can be represented.
Expressions Sum
Write a program that accepts a 5 digit integer value, calculates the sum of
the digits, and then displays the product of the value multiplied by the sum
of the digits. For example, if the user enters 12345 then the program would
display 12345 · 15 = 185175
Explanation / Answer
#include<stdio.h>
#include<limits.h>
#include <float.h>
// limits.h and float.h these are predefined directories which have the constants to show the min and max values
int main()
{
int a=1;
printf("intialized value : %d ",a);
long int b=123;
printf("intialized value : %ld ",b);
unsigned int c=2;
printf("intialized value : %u ",c);
float d =2.3;
printf("intialized value : %f ",d);
double e=2.44;
printf("intialized value : %f ",e);
long double f=3.555;
printf("intialized value : %lg ",f);
char g='p';
printf("intialized value : %c ",g);
printf ("now printing max values of above variables ");
printf("The maximum value of INT = %d ", INT_MAX);
printf("The maximum value of LONG INT = %d ", LONG_MAX);
printf("The maximum value of UNSIGNED INT = %d ", UINT_MAX);
printf("The maximum value of CHAR = %d ", CHAR_MAX);
printf("The maximum value of FLOAT = %f ", FLT_MAX);
printf("The maximum value of DOUBLE = %f ", DBL_MAX);
printf("The maximum value of DOUBLE = %LG ", LDBL_MAX );
return 0;
}
output:
intialized value : 1
intialized value : 123
intialized value : 2
intialized value : 2.300000
intialized value : 2.440000
intialized value : 1.19777e-317
intialized value : p
now printing max values of above variables
The maximum value of INT = 2147483647
The maximum value of LONG INT = 2147483647
The maximum value of UNSIGNED INT = -1
The maximum value of CHAR = 127
The maximum value of FLOAT = 340282346638528860000000000000000000000.000000
The maximum value of DOUBLE = 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
The maximum value of DOUBLE = 1.19777E-317
*********************************************************************************************************************
#include <stdio.h>
void main()
{
long num, temp, dig, sum = 0;
printf("Enter the number ");
scanf("%ld", &num);
temp = num;
while (num > 0) //this while loop is to count the sum of the digits
{
dig = num % 10;
sum = sum + dig;
num /= 10;
}
printf("use input number is : %ld ", temp);
printf("sum of the digits is : %ld = %ld ", temp, sum);
int total=temp*sum; //product of the value multiplied by the sum of the digits:
printf(" product of the value multiplied by the sum of the digits:%d ",total);
}
output:
Enter the number
12345
use input number is : 12345
sum of the digits is : 12345 = 15
product of the value multiplied by the sum of the digits:185175
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.