Você está na página 1de 14

' $

PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 1

Tutorial

 

Programming & Data Structure: CS 11001 
 

 
Section - 9/C
 
DO NOT POWER ON THE MACHINE 
Department of Computer Science and Engineering
I.I.T. Kharagpur
Autumn Semester: 2007 - 2008 (03.08.2007)

& %
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 2

Download

Download the file tut030807.ps from


Programming & Data Structures ... of

http://www.facweb.iitkgp.ernet.in/∼goutam

View the file using the command kghostview & or


ggv &

& %
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 3

Tutorial II

A 3-digit radix-complement decimal (rcd or 10’s


complement) numeral is defined as follows:
1. A numeral is a sequence of three decimal
digits.
2. A +ve numeral has 0, 1, 2, 3, or 4 as the most
significant digit. Its denotation is usual. A −ve
numeral has 5, 6, 7, 8, or 9 as the most
significant digit.
3. If a number n is represented as a 3-digit rcd
numeral, −n is represented as 1000 − n in rcd.

& %
Answer the following questions:
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 4

1. What is the value of 729 (rcd) in standard


decimal?
2. What is the range of decimal numbers
represented as 3-digit rcd?
3. What is the range of decimal numbers
represented as n-digit rcd?
4. What is the range of decimal numbers
represented as 3-digit radix-6, 6-complement
numeral. Answer the same question for
n-digits.
5. Answer the previous question for radix-2, 2’s
complement numerals.
& %
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 5

6. What will be the results of addition in 3-digit


rcd in the following cases (all numbers are in
rcd): (i) 123 + 234, (ii) 123 + 877, (iii) 403 +
311, (iv) 900 + 800, (v) 540 + 630
7. What will be the representation of 301 and
825 (3-digit rcds) as 6-digit rcds?

& %
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 6

Tutorial II

1. Convert the decimal numeral 1234 to a binary


numeral.
2. Convert the unsigned binary numeral
0110 1001 to a decimal numeral.
3. Convert the unsigned binary numeral
1011 1010 0001 1110 to hexadecimal (Hex) and
octal (Oct) numerals.
4. What is the range of unsigned integers that
can be stored in 12-bits?
& %
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 7

Tutorial II

1. Add the following two 4-bit unsigned integers:


0101 + 1001.
2. Give 2’s complement representations of ±109
in 8-bits. What will be the representation in
12-bits?
3. What is the range of numbers that can be
represented in 8-bit 2’s complement form.

& %
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 8

Tutorial II.1

Write a C program that reads a small positive


integer of one or two digits, and prints the sum of
the digits.

Input Output
5 5
15 6
79 16

& %
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 9

Tutorial II.2

Write a C program that reads a positive integer


of three digits (no leading zero), and prints the
integer whose digits are in reverse order.

Input Output
123 321
705 507

& %
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 10

Tutorial II.3

Write a C program that reads a floating-point


number x and prints the value of the polynomial

3x2 + 5x + 9.

You cannot use more than two multiplication


operations.

Input Output
1.0 17.0
2.5 40.25

& %
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 11

Tutorial II.4

A chemical compound has c% of carbon, h% of


hydrogen, n% of nitrogen and o% of oxygen by
mass. The molar mass of the compound is m.
Write a C program to find the number of different
atoms in the molecule. Assume that the molar
mass of carbon, hydrogen, nitrogen and oxygen
are: 12.011, 1.008, 14.01 and 16.00 respectively.

& %
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 12

Caffeine: 194.2
Input Output
C: 49.48 %, H: 5.15 %, C: 8, H: 10
N: 28.87 %, O: 16.49 % N: 4, O: 2
C8 H10 N4 O2

& %
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 13

Tutorial II.5

Run the following code and see the output for


different data.
#include <stdio.h>
int main()
{
int n ;
printf("Enter an integer: ") ;
scanf("%d", &n) ;
printf("1/%d = %d\n", n, 1/n) ;
return 0 ;
}
& %
' $
PDS Tutorial: II (CS 11001): Section 9 Dept. of CS&Engg., IIT Kharagpur 14

Tutorial II.6

Run the following code and see the output for


different data.
#include <stdio.h>
int main()
{
unsigned int n ;
printf("Enter a +ve integer: ") ;
scanf("%d", &n) ;
printf("%d << 4 = %d\n", n, n << 4) ;
return 0 ;
}
& %

Você também pode gostar