Professional Documents
Culture Documents
Worksheet For CS3
Worksheet For CS3
/* This program “Illustration of datatypes.c” demonstrates fundamental data types in C : char, int, float
and double */
#include <stdio.h>
main()
{
char ch = 'a' ;
int num = 1234;
float f_num = 12.56;
double d_num = 1234.0;
}
Compile and execute the program and observe the output.
Task 1.3: Write a program to find the ASCII equivalent of ‘a’ –‘z’, ‘A’-‘Z’ and ‘1’ – ‘9’
Task 1.4: Write a program to find the size of each int data type.
Exercise 2: This exercise demonstrates the use of modifiers. Program to be used is “modifier.c”
Exercise 4: This exercise demonstrates the use of printf() and scanf() functions. Program to be
used is “Print_scan.c”
Task 1.2:
printf("\"welcome to SAP LABS\b\b\b\b\"");
Task 2: What is the output for the following code fragments?
Code 1:
printf ("Welcome\n");
printf ("to \n");
printf ("SAP");
Code 2:
printf ("C = A\/B");
Code 3:
printf ("Welcome\b\b\b");
printf ("to\b");
printf ("SAP");
Code 4:
printf ("Welcome\b\b\b\n");
printf ("to\b\n");
printf ("SAP");
Code 2:
int a;
printf("Enter some integer number\n");
scanf("%d",a);
printf("The value of a = %d", a);
Task 4: Declare two integer variables and find out the address where they are stored in the
memory
int a = 10, b = 30;
printf ("a = %d, b = %d\n", a, b );
printf ("address of a = %d, b = %d\n", &a, &b );
z = x + y + 30;
printf("z = %d\n", z);
z = y / x;
printf("z = %d\n", z);
z = y/6;
printf("z = %d\n", z);
z = a + b + 30;
printf("z = %d\n", z);
Code 2:
int x, y = 10;
int z = 'a';
x = y + z;
printf("x = %d", x);
Task 2:
int result, data1 = 0x1234, data2 = 0x8ABC;
result = data1 + data2;
(result > 0 )? printf("result is greater than zero"): printf("result is less than or equal to
zero");
Task 5 : Write a program to find whether the given number is odd or even.
Exercise 8 : This exercise demonstrates shorthand notation
Task 1: what is the output for the following program?
Code 1:
int x = 20;
x-=10;
printf("%d",x);
Code 2:
int x = 20;
x=-10;
printf("%d",x);
Code 3:
int x = 20;
Worksheet for CS3
x= -10;
printf("%d",x);
x = 2/3*4^2 ;
printf("x = %d\n", x);
x = 1+2/3*4+5;
printf("x = %d", x);
Task 2: What is the output for the following program?
Code 1:
int k ,i = 10; j = 10;
k = ++i + ++j;
printf (" i = %d, j = %d, k = %d", i, j, k);
Code 2:
int k ,i = 10; j = 10;
k = ++i + ++i;
printf (" i = %d, j = %d, k = %d", i, j, k);
Code 3:
int k ,i = 10; j = 10;
k = i++ + j++;
printf (" i = %d, j = %d, k = %d", i, j, k);
Code 4:
int k ,i = 10; j = 10;
k = ++i + j++;
printf (" i = %d, j = %d, k = %d", i, j, k);