ESc 101: Fundamentals of Computing
Lecture 14
Feb 1, 2010
Lecture 14 ()
ESc 101
Feb 1, 2010
1 / 20
Outline
1
Adding Large Integers
Lecture 14 ()
ESc 101
Feb 1, 2010
2 / 20
Data Structure for Negative Numbers
A number is stored, as usual, in an array of ch
ESc 101: Fundamentals of Computing
Lecture 10
Jan 21, 2010
Lecture 10 ()
ESc 101
Jan 21, 2010
1/3
File add large.c has a really bad program for computing the sum of two
numbers of a fixed size.
Lecture 10 ()
ESc 101
Jan 21, 2010
3/3
i) Familiarize yourself with the Linux environment (exploring directories, opening terminal window etc).
ii) Start working with a text editor (vim or any other available on the machine).
iii) Type in a couple of programs (from the ones done in the class),
Monday:
Write a program that takes two large positive numbers (of up to 100 digits) as input and
outputs their multiplication.
Your program must be properly commented and indented. Before writing the program, write
down the outline of your approach includ
1Compute the factorials for the numbers 0 to 20.
Print as
Number Factorial
0 1
1 1
2 2
3 6

2 Ask the user to enter 10 symbols and in its output print its binary sequence.

3 Ask the user to enter the large number and print that large number in rever
Write a program that takes one large positive number x (of up to 100 digits) and one small
number positive y (of one digit long) as input and outputs x mod y.
Your program must be properly commented and indented. Before writing the program, write
down the
Write a program to compute the complete prime factorization of the input number.
The output should be an ordered sequence of prime divisors of the input along with their multiplicity with largest divisor first.
A divisor and its multiplicity should be enc
Write a program to compute all proper factors of the input number.
The output should be an ordered sequence of divisors of the input along with an indicator if they are prime or not, with largest divisor first.
A divisor and its indicator should be enclo
Write a program to compute the complete prime factorization of the input number.
The output should be an ordered sequence of prime divisors of the input with largest divisor first.
For example,
On input 42, the output is 7 3 2.
On input 16, the output
Write a program that reads the following inputs: n (an integer), followed by n floating point numbers,
and then two additional floating point numbers a and b. It outputs the smallest number in the input sequence
bigger than a and largest number in the seq
Write a toy scanf function. Its specification are as follows:
int toy_scanf( char format_str[], int *arg1, char arg2[] )
The function has exactly three arguments with the constant string <format_str> being the format specifier. This string has the follo
1If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Similarly, Find the sum of all the multiples of 3 or 5 below 1000.
Note: Using Loop

2Each new term in the Fibonacci sequ
ESc 101: Fundamentals of Computing
Lecture 18
Feb 11, 2010
Lecture 18 ()
ESc 101
Feb 11, 2010
1 / 12
Outline
1
Strings
2
Printf and Scanf
Lecture 18 ()
ESc 101
Feb 11, 2010
2 / 12
Strings in C
Strings are represented by an array of characters in C.
The la
ESc 101: Fundamentals of Computing
Lecture 13
Jan 28, 2010
Lecture 13 ()
ESc 101
Jan 28, 2010
1 / 16
Algorithms
An algorithm is a stepwise description of operations to solve a
problem.
It is usually in a natural language, not a computer language.
It also
ESc 101: Fundamentals of Computing
Lecture 9
Jan 20, 2010
Lecture 9 ()
ESc 101
Jan 20, 2010
1 / 10
+ and 
+ and  are unary operators.
They increment and decrement the value of variable, unlike other
operators.
In addition, the operations also have a res
ESc 101: Fundamentals of Computing
Lecture 7
Jan 14, 2010
Lecture 7 ()
ESc 101
Jan 14, 2010
1 / 10
Calculating Value of
We use the series
X (1)k
=
.
4
2k + 1
k=0
Since is irrational, it can never be calculated exactly.
Take as input the truncation point
ESc 101: Fundamentals of Computing
Lecture 1
Dec 31, 2009
Lecture 1 ()
ESc 101
Dec 31, 2009
1 / 36
Instructor
Who? Manindra Agrawal
Where? Professor, Dept of CSE
Why? It is interesting to teach a large class
Lecture 1 ()
ESc 101
Dec 31, 2009
3 / 36
Conten
Write a program implementing the following modification of mergesort: split
the sequence in three roughly equal parts, recursively sort each part, and
then merge the three parts. Compare the performance of this with the
mergesort done in the class. To com
Write a program that reads one string, str, as input. The length of str is at most 10000. Place appropriate checks for the input length.
The string contains only non whitespace characters.
The program outputs 11 numbers a_1 a_2 . a_cfw_11, where a_i is t
Download the matrix files from the website.
You are required to add functionality to it.
Write the following function:
/* Takes as input n vectors in the array named vectors. Returns 1 if they are all
* linearly independent. Otherwise returns 0.
*/
int
Designing Functions
Lecture 15 (in continuation of Lec.
14)
1
Problem: Print prime factors of a
number n int print_prime_factors(int n) cfw_
int a =2;
int maxpow=0;
i*i <=n ?
i=i+1
while ( a*a <= n) cfw_
if (isprime(a) cfw_
maxpow = max_pow_div(n,a);
n =
For Loops
Lecture12 (continuation of Lecture
11)
1
Class Matters
Major Quiz 1 tomorrow. Covers topics up to and
including Lecture 11 (last Wednesday).
The slides are modified from those by Sumit
Ganguly.
2
Recap: continue; in for loop
In for loop, contin
Comma Operator execution
Commas are evaluated from left to right. That
is,
scanf(0,&m), sum=0, i=0 is executed as
(scanf(0,&m), sum=0), i=0
The comma operator has the lowest
precedence of all operators in C. So
a=a+5, sum = sum + a
is equivalent to
(a=a+
Esc 101 Semester II 201213
Lab 6
February 1112
Instruction
The problems in Section 1 are mandatory.
The problems in Section 2 are optional. You may submit them, but they are just for practice and are not
graded.
1. Mandatory Problems
1
Computing the gcd
Lab 3 Model Solutions
1
The code for computing the factorial is as follows.
#include <stdio.h>
main()
cfw_
int i=1;
int partprod= 1;
int n;
4
scanf("0",&n);
8
/* current num being multiplied */
/* (i1)! */
/* input number */
/* read number */
/* Loop inv
Lab 6 Model Solutions
1. Version A
1
We will write a function hailstone which will compute the value of the hailstone function. It
should take one input argument, of type int. Since the definition says that n/2 will be evaluated
only when n is an even int
Lab 4 Model Solutions
1
The code to evaluate the sine series up to the first n terms is as follows.
1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>
/*
* Evaluate sin(x) up to n
*/
main()
cfw_
int n;
/*
int i;
/*
float x;
/*
float term;
/*
float sinx=0.0; /*
te