Prog. 1 : Displays the
value of an int variable on the screen using printf() function
#include <stdio.h>
main()
{
int myNumber;
myNumber = 786;
printf("Value of
myNumber is : %d\n", myNumber); return(0) ;
}
Output :
Value of myNumber is : 786
Prog. 2: displays the
values of three int variables on the screen using printf() function.
#include <stdio.h>
main()
{
int n1, n2, n3;
n1 = 10;
n2 = 50;
n3 = n1 * n2;
printf("%d multiplied
by %d is : %d\n", n1, n2, n3); return(0) ;
}
Output :
10 multiplied by 50is : 500
Prog. 3: Displays the values of char variable on the screen using the
conversion specifications %c and %d.
#include <stdio.h>
main()
{
char letter;
letter = '#';
printf("Character stored in letter is :
%c\n", letter);
printf("Integer value
stored in letter is : %d\n", letter); return(0);
}
Output :
Character stored in letter is : #
Integer value stored in letter is : 35
Prog. 4: Displays the
extreme values of integral types on the screen.
#include <stdio.h>
main()
{
int n1 = -32768, n2 =
32767;
short int n3 = -128, n4 = 127;
long int n5 = -2147483648L,
n6 = 2147483647L; signed int n7 = -32768, n8 = 32767; unsigned int n9 = 0, n10
= 65535U; signed short int n11 = -128, n12 = 127;
unsigned short int n13 = 0, n14 = 255;
signed long int n15 =
-2147483648L, n16 = 2147483647L; unsigned long int n17 = 0, n18 = 4294967295UL;
printf("int: n1 = %d, n2 = %d\n", n1, n2); printf("short int: n3
= %d, n4 = %d\n", n3, n4);
printf("long int: n5 = %ld, n6 =
%ld\n", n5, n6);
printf("signed int: n7 = %d, n8 =
%d\n", n7, n8);
printf("unsigned int: n9 = %u, n10 =
%u\n", n9, n10);
printf("signed short int: n11 = %d, n12 =
%d\n", n11, n12);
printf("unsigned short
int: n13 = %d, n14 = %d\n", n13, n14);
printf("signed long int: n15 = %ld, n16 =
%ld\n", n15, n16);
printf("unsigned long int: n17 = %lu, n18 =
%lu\n", n17, n18);
return(0);
}
Output:
int: n1 = -32768, n2 = 32767
short int: n3 = -128, n4 = 127
long int: n5 = -2147483648, n6 = 2147483647
signed int: n7 = -32768, n8 = 32767
unsigned int: n9 = 0, n10 = 65535
signed short int: n11 = -128, n12 = 127
unsigned short int: n13 = 0, n14 = 255
signed long int: n15 = -2147483648, n16 = 2147483647
unsigned long int: n17 = 0, n18 = 4294967295
Prog. 5: Displays the
extreme values of float types on the screen.
/* This program displays the extreme values of float type on the */
/* screen by passing the variables to printf() function. */
#include <stdio.h>
main()
{
float f1 = -3.4e-38F, f2 = -3.4e+38F;
float f3 = 3.4e-38F, f4 = 3.4e+38F;
float f5 = -10.34F, f6 = 25.83F;
printf("f1 = %e, f2 = %e\n", f1, f2);
printf("f3 = %e, f4 = %e\n", f3, f4);
printf("f1 = %g, f2 = %g\n", f1, f2);
printf("f3 = %g, f4 = %g\n", f3, f4);
printf("f5 = %f, f6 = %f\n", f5, f6);
return(0);
}
Output :
f1 = -3.400000e-38, f2 = -3.400000e+38
f3 = 3.400000e-38, f4 = 3.400000e+38
f1 = -3.4e-38, f2 = -3.4e+38
f3 = 3.4e-38, f4 = 3.4e+38
f5 = -10.340000, f6 = 25.830000

No comments:
Post a Comment