[go: up one dir, main page]

0% found this document useful (0 votes)
29 views14 pages

Lecture 03 Bscs

Uploaded by

bc240222245rsh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views14 pages

Lecture 03 Bscs

Uploaded by

bc240222245rsh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR.

SYED WAQAR UL QOUNAIN

2022-08-23 LECTURE 03 – INTRODUCTION TO C PROGRAMMING

 contents
o programming
o C programming language
o C program development environment
o first C program
o datatypes and variables
o operators and expressions
o concepts discussed in the lecture
o exercises
 programming
o is to instruct and command computer to perform user’s desired task
 C programming language
o history
 in 1972 Dennis Ritchie developed C language
 C language was evolved from two earlier programming languages namely BCPL
and B
 B language was developed at Bell Telephone laboratories (currently AT&T Bell
Labs) by Ken Thompson
 till 1978, C was primarily used at Bell Labs
 in 1978 Brian Kernighan and Dennis Ritchie published a book named “The C
Programming Language”
 the book was central to the development and popularization of the C
programming language and is still widely read and used today
 C language of 1978 is called K&R C
 American National Standards Institute (ANSI) published a standard for C language
in 1989 which is call ANSI C or C89, second version of the book was published to
cover the ANSI C standard, the same standard was adopted by the International
Organization for Standards (ISO) in 1990 hence it is also called C90
 in 1995 International Organization for Standards (ISO) made few extensions in C
language standards which is called C95
 later the ANSI adopted ISO C95 standard which is called C99
 in 2011 ISO has included improved C99 and this is call C11
 current standard of C language is C17 which has improved few defects of C11
 software developers writing in C language are encouraged to conform to the
standards, as doing so helps portability between different compilers
o significance
 C language is used to develop high performance demanding systems like
operating systems, real time systems, embedded systems etc.
o language
 to program in C language a programmer should know about
 C language syntax
 keywords

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 1 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

 datatypes and variables


 operators
 control structures
 statement, block and functions
 C program development environment
 C Standard Library
o C language syntax: language syntax is a set of rules and regulations used to write a
program like
 keywords or reserved words: are words which have special meanings to
programming language for example, and programmer cannot use following
words as these words are reserved for various C language constructs
 auto, break, case, char, const, continue, default, do, double, else, enum,
extern, float, for, goto, if, int, long, register, return, short, signed, sizeof,
static, struct, switch, typedef, union, unsigned, void, volatile, while
 Keywords added in the C99 standard
o _Bool, _Complex, _Imaginary, inline, restrict
 Keywords added in the C11 standard
o _Alignas, _Alignof, _Atomic, _Generic, _Noreturn, _Static,
_assert, _Thread_local
 variables and datatypes:
 variable is named memory location which is used to store user input and
processed data
 a language syntax support datatypes which helps to define different
types of variables to hold different types of data
o integer: to hold whole numbers defined in C as int
o float: to hold a real number (having fractions) defined in C as float
o character: to a single character defined in C as char such as
defined in ASCII and UNICODE
 a language syntax defines that how a variable should be named
o in C a variable name consist of letters, digits and underscores ( _
), but may not begin with a digit
o C language is case sensitive which means that a variable name
A1 is different than a variable name a1
 operators: language syntax defines which operations could be performed on
different variables
 arithmetic operators: basic mathematical operations like addition,
subtraction, multiplication and division (+, -, *, /) could be used on
numeric data
 relational operators: relationship between two numeric data values
could be assessed using relations operators (>, ==, <, >=, <=, !=)
 logical operators: logical operations performed on numeric data results
into either true (1) or false (0) values logical operations include and, or
and not (&&, ||, !)

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 2 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

 control structures: to control the follow of a program C language supports


different control structures and nested control structures
 sequence: a default sequence of instructions execution
 selection: if, if-else, if-else if- else, switch
 repetition: for, while, do while
 statement, block and functions
 statement: smallest unit of instruction in C language is a statement
o every statement ends with a statement terminator denoted as ;
 code block: a set of statements inside two braces { } is called a code block
 function: a set of code blocks could be blocked together to form a
function/procedure
o function/procedure is a piece of code which perform a dedicated
task
o function may receive argument to work on and return a value
after performing its dedicated task
o there are two types of function
 standard library functions: is a set of functions that are
most commonly used in programming and hence built-in
a programming language like
 function for taking input from console
 giving output at console
 reading and writing data to a file at hard disk
 calculating various mathematical function etc.
 user defined function: C language allows programmers
to define new functions and re-use these functions in
different programs
 C program development environment
o is a software suite used for writing till execution of a C program usually called an
integrated development environment (IDE)
o C programs typically go through six phases till its execution on a computer — edit,
preprocess, compile, link, load and execute
o a typical C program development environment provides support to perform all six tasks
o different C program development environment are available for Windows, macOS and
Linux and other operating systems
 Visual Studio Code, Eclipse, CLine, Tabnine, Codelite, Atom, NetBeans,
PlatformIO, Sublime Text, KDevelop, Apache Arrow, Brackets, EMACS, VI/VIM
Editor, Notepad++, Codenaywhere, AWS Cloud9, Koding, Geany, Lazarus IDE
 using a particular IDE is a matter of programmer’s taste and choice
o Phase 1 – creating/writing/editing:
 the process of writing a program using a text editor
 some editors help programmer in writing a program through various support
mechanism, for example
 when a programmer start typing a function name, the editor populates a list of
function names having similar prefix, this is called IntelliSense

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 3 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

 if a programmer type a wrong function name then the editor highlights it as an


expected error
o Phase 2 – preprocessing:
 text inclusion of header files in C program and formation of single program file,
 header files usually contain function declarations shared between several source
files
 a function declaration tells the compiler about a function's name, return type,
and parameters
 declaration tell how to use/call a function from a program to perform its
dedicated task
o Phase 3 – compiling:
 checking program for syntax error e.g., program is written as per C language
rules, and
 generating machine code into an object file
 if the program does not follow language rules then the compiler generates errors
called syntax or compile-time error
o Phase 4 – linking:
 combines machine language code of the program and machine code of various C
standard library functions definitions available in library files into a single
executable file,
 library file is a file that contains machine code of function definitions for the
functions declared in the header file
 a function definition tells how a function will actually perform its dedicated task
 if linker does not find function definition in library file for a function used in the
program, then the linker generates an error called linker or link-time error
o Phase 5 – loading:
 IDE requests to host operating system to load machine code (executable file) of a
C executable program into RAM for execution purpose
 if host operating system fails to load the program in RAM it generates loading
error which might be caused due to insufficient available memory in the system
o Phase 6 – executing:
 IDE requests to host operating system to starts executing the loaded C executable
program and host operating system starts executing the program from its starting
instruction
 if host operating system fails to execute the program it generates execution error
which might be caused due to lack of execution privileges of the program
available in the system
 while executing or running a program, the program may crash during its working,
such an error is called a run-time error
 while executing or running a program, the program may give wrong or
undesirable output during its working, such an error is caused due to wrong
program logic written by the programmer and called a logical error
 first C program
o L03-C01: a C program which prints Pakistan Zindabad at console

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 4 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

1 // A first program in C.
2 #include <stdio.h>
3
4 // function main begins program execution
5 int main(void) {
6 printf("Pakistan Zindabad\n");
7 } // end function main

Output: Pakistan Zindabad

o program structure
 //
 it is used for comments, compiler ignore these statements, these are
meant for programmer’s personal use to remember and recall what s/he
has done and why
 #include
 it is called preprocessor directive, which tells complier to include code
from a specified file into current program file
 <stdio.h>
 used for header file, a file that stores declarations of standard input and
output functions used for taking input form user and given output to user
at user’s console
 int main (void)
 it is called main function, which is the program entry point, all C programs
start from this function
 functions can receive a value to act upon and may return a value after
processing the code inside function,
 here main function does not receive any value which is represented by
keyword void and
 returns a value written at left of the function name which is the keyword
int
 printf(“ ”)
 it is an output function, used to display information at user’s console, this
function is declared in stdio.h header file
 function printf prints a string (set of characters) at console
 this string can have special meanings to character starting with \ which
are called escape sequences for example
o \n is called newline which moves cursor on next line at console
o \t is called horizontal tab which moves cursor to the next
horizontal table position at console
o \v is called vertical tab which moves cursor to the next vertical
tab position at console
o \a is called alert which generate an audible (bell)
o \\ is called backslash which outputs the backslash \ at console

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 5 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

o \” is called double quote which outputs the double quote “ at


console
o \’ is called single quote which outputs the single quote ‘ at
console
 ; – it is called statement terminator, every instruction in C languages need a
statement terminator at its end
 { } – braces and a set of statements inside it are called code block, main function
has code block to execute which is comprised of { and } and statements inside it,
when a program reaches
o L03-C02: a C program which takes a number form the user and prints its value at console

1 // program which takes a number form the user and prints its value at console
2 #include <stdio.h>
3
4 // function main begins program execution
5 int main(void) {
6 int a;
7 scanf(“%d”, &a);
8 printf("%d\n", a);
9 } // end function main

Input: 10
Output: 10
 line 6 - int a – this statement defines a variable named a in memory having type
integer, which can store a whole number inside it
 line 7 – scanf(”%d”, &a) – this is a C standard library function named scanf which
will take a value from the keyboard and store that value as a whole number in
variable a in decimal format
 line 8 – printf(”%d”, a) – this is a C standard library function named printf which
will print the value of variable a stored in the memory at console as a whole
number in decimal format
 datatypes and variables
o datatypes
 is a set of possible values and a set of possible operation that could be performed
on it.
 It tells the compiler how the programmer intends to use the data.
 basic data types include
 integer numbers (which can store whole number), represented with
keyword int in C language
 floating-point numbers (which approximate real numbers), represented
with keyword float in C language
 characters (which store alphabets, punctuations, etc.), represented with
keyword char in C language
 datatype defines which possible values that a variable might take and the
operations that can be done on the variable

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 6 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

 variable
 a named memory location of a particular datatype which can store data
 a variable could be named as a language identifier
o identifier: consist of letters, digits and underscores ( _ ), but may
not begin with a digit
o case sensitivity: a1 and A1 are different identifiers
 definition: variable could be defined by simply writing datatype and
then a variable name
o it is necessary to define a variable before it is used in the
program
o int a;
o float b;
o char c;
o above statements define three variables namely a, f and c of
datatypes int, float and char which can store whole number real
number and a character respectively
o when a programmer define a variable, the program reserve a
specified location of a particular size in the RAM
o the program reserve one byte for a char type variable and four
bytes each for an int and float types variable each
o range of a datatype is minimum and maximum value that a
datatype can hold
 a char type variable can store values from -128 to 127
 an int type variable can store values from -2147483648
to 2147483647
 an float type variable can store values from -3.4e+38 to
-3.4e+38, here e+38 means 1038
o memory occupied by each datatype can be found be using
sizeof operator in a program as follows
sizeof (int)
o when a variable is define without giving it any value, then it
holds a garbage (unknown random) value
 initialization: it good to assign a value to a variable at the time of its
definition this called variable initialization
 int a = 12;
 float b = 13.51;
 char c = ‘A’;
o after definition of initialization of a variable, programmer can
assign a permissible value to a variable using assignment
operator =
 a = 100;
 b = 26.75;
 c = ‘Z’;
 output statement for variables

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 7 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

o format specifer of %c, %d and %f are used to print and value


inside a character, integer and float variables using printf library
function
 printf(“%d”, a);
 printf(“%f”, b);
 printf(“%c”, c);
 input statement for variables
o format specifer of %c, %d and %f are used to take input of a
character, integer and float variables using scanf library function
 scanf(“%d”, &a);
 scanf(“%f”, &b);
 scanf(“%c”, &c);
 overflow and underflow
o if a value less than the rang of the datatype is stored in its variable
then the program store it in an incorrect manner which is called
variable underflow
o if a value greater than the rang of the datatype is stored in its
variable then the program store it in an incorrect manner which
is called variable overflow
 promotions and demotions
o if a value in an integer variable is assigned to a float variable the
value is promoted to float
o if a value in an float variable is assigned to an integer variable the
value is demoted to an integer
// L03-C03
1. int a=10;
2. float b=20.5;
3. printf(“%d\t”, a);
4. printf(“%f\t”, b);
5. a = b;
6. printf(“%d\t”, a);
7. b = a;
8. printf(“%f\t”, b);
9. output: 10 20.500000 20 20.000000

o line 5: value of float variable b which is 20.5 demotes to 20 when


assigned to a variable of type integer.
o line 7: value of int variable a which is 20 promotes to 20.000000
when assigned to a variable of type float.
 operators and expressions
o operator
 is a symbol that tells the compiler to perform specific mathematical or logical
operation on constants and variables
 there are different types of operators

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 8 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

 arithmetic operators:
o these operators perform arithmetic including addition,
subtraction, multiplication, division, and modulus operations on
their operands represented by +, - , *, / and %
// L03-C04
1. int a, b, c;
2. a = 10;
3. b = 20;
4. c = a + b;
5. printf(“%d”, c);

o output: 30
o line 1: above code defines three integer type variables namely a,
b and c, each variable occupies four bytes each in the RAM
o line 2&3: assign value 10 to variable a and value 20 to variable b
o line 4: an arithmetic operation of addition + is performed on
variable a and b which results value 30 and this value is stored in
variable c
o line 5: prints the value stored in variable c at console
o statements at line 2, 3 and 4 are called expression
 an expression is a combination of variables, constants
and operators
 relational operators:
o these operators are used to check the relationship between two
operands. For example >, <, ==, !=, >=, <=
o checks if a is greater than b a > b; here, > is a relational operator.
It checks if a is greater than b or not
o after operating on two operands relational operator return
either of two values which are 1 (true) or 0 (false)
// L03-C05
1. int a, b, c;
2. a = 10;
3. b = 20;
4. c = a > b;
5. printf(“%d”, c);
o output: 0

o line 4:
 contains a relation operator having two operands a > b
 this relational expression a > b will result 0 (false), which
will be stored in variable c, and subsequently printed at
console
 logical operator:

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 9 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

o are designed for operations with the true (1) or false (0) values
within the logical expressions
o there are three logical operators namely and, or and not
operators represented by &&, ||, ! symbols respectively
o after operating on two operands logical operator return either of
two values which are 1 (true) or 0 (false)
o and operator represented by && symbols will return 1 (true) if
both operands are non-zero (both are true) otherwise it returns
0 (false)
o or operator represented by || symbols will return 1 (true) if any
of the operands is non-zero (any one is true) otherwise it returns
0 (false)
o not operator represented by ! symbols will return 1 (true) its
operand 0 (false) otherwise it returns 1 (true), note that not
operator has only on operand
o please note that logical operators consider all non-zero values
as true (1)
o logical operators are commonly used with relational operators to
form an meaningful expression
// L03-C06
1. int a, b, c, d;
2. a = 10;
3. b = 20;
4. c = 30;
5. d = (a > b) && (b > c)
6. printf(“%d”, d);
o output: 0

o line 5:
 contains a logical and operator having two operands first
is (a > b) and second is (b > c)
 the first relational expression a > b will result 0 (false)
 the second relational expression b > c will also result 0
(false)
 hence both operands of and logical operator would be 0
 so the result of 0 && 0 would be 0 (false), which would
be printed at console
o integer division
 when an integer is divided by an integer it results into an integer value which is
called integer division, it is important to note that such division truncate
remainder part of the division process
// L03-C07
1. int a, b, c;
2. a = 10;

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 10 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

3. b = 3;
4. c = a / b;
5. printf(“%d”, c);
 output: 3

 line 4:
 please note that here the result should be 3.33333 which is truncated due
to integer division and only 3 is stored in variable c
 if we use c as a float variable it will still not resolve issue because the
operand of division operator are both integers the result of a / b would
be 3 and stored in c as 3.000000
 to resolve this issue we should use float division instead of integer
division
 if either of a or b as a float variable then the division process return a float
value
// L03-C08
1. int a;
2. float b, c;
3. a = 10;
4. b = 3;
5. c = a / b;
6. printf(“%f”, c);
 output: 3.333333

 line 5:
 an integer 10 is divided by a float value 3.000000, hence the result would
be promoted to a float value which would be 3.333333
 as this resultant value is stored in another float variable hence the
variable c will store 3.333333, which would be printed at console
 note if we will use c as an integer variable it will again print 3 at console
due to truncation of value after decimal places
o converting mathematical expressions into programming expressions
 a mathematical expression should be converted into a straight-line form while
writing a program code
 expressions like “a divided by b” must be written as a / b with all operators and
operands in a straight line. The mathematical or algebraic notation for this
𝑎
expression is
𝑏
 parentheses are used in C expressions in the same manner as in algebraic
expressions, for example, to multiply variable a times the quantity b + c, it is
written as a * (b + c)
o operator precedence
 determines the grouping of terms in an expression and decides how an
expression is evaluated or which part of the expression is evaluated prior to other

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 11 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

 operators in arithmetic expressions are applied in a precise sequence determined


by the following rules of operator precedence, which are generally the same as
those in algebra:
 Rule 1.
o expressions grouped in parentheses evaluate first.
o parentheses are said to be at the “highest level of precedence.”
o in nested parentheses, such as ((a + b) + c) the operators in the
innermost pair of parentheses are applied first.
 Rule 2.
o *, / and % are applied next
o these three operators are said to be on the same level of
precedence
o if an expression contains several *, / and % operators, evaluation
proceeds from left direction to right direction, this is called
associativity of operators
 Rule 3.
o + and - are evaluated next
o if an expression contains + and - operators, evaluation proceeds
from left direction to right direction
o these two operators have the same level of precedence, which is
lower than that of *, / and %.
 Rule 4.
o assignment operator (=) is evaluated last
 order of precedence of various operators is as follows
 !, logical NOT operator is a unary operator which has right to left
associativity
 *, /, %, arithmetic multiplication, division and remainder operators are
binary operators which have left to right associativity
 +, -, arithmetic addition and subtraction operators are binary operators
which have left to right associativity
 <, <, =>, >=, relational less than, less than equal to, greater than, and
greater than equal to, are binary operators which have left to right
associativity
 ==, !=, relational equal to, and not equal to, are binary operators which
have left to right associativity
 &&, logical AND operator is a binary operator which have left to right
associativity
 ||, logical OR operator is a binary operator which have left to right
associativity
 =, assignment operator is a binary operator which have right to left
associativity
 please note that parenthesis are used to override precedence of operators and
create clarity for programmer and the compiler
 concepts discussed in the lecture

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 12 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

o C language, BCPL, B, Standard, ANSI, ISO, K&R C, ANSI C, C89, C95, C99, C11, C17,
operating systems, real time systems, embedded systems,
o development environment, C language syntax, preprocessor directive, comments, header
file, program entry point, output function, statement terminator, keywords, reserved
word, void, int, char, float, case sensitive, braces, parenthesis, statement, code block,
function, standard library function, user defined function, argument, return value,
function declaration, function definition, control structure, sequence, selection,
repetition,
o edit, preprocess, compile, link, load, execute, c/program file, header file, object file,
library file, executable file, syntax error, compile-time-error, linker error or link-time-
error, loading error, execution error, runtime error, logical error
o Standard Library, standard input and standard output, printf, scanf, %d, format specifier,
escape sequences, statement terminator, datatype, variable, identifier, rang of datatype,
size of datatype, sizeof, garbage value, variable definition, variable initialization, variable
assignment, variable overflow and underflow, promotion and demotion,
o operator, assignment operator, binary operator, arithmetic operator, relational operator,
logical operator, operator precedence, operator associativity, expression, AND, OR, NOT,
integer division, straight-line form
 exercises
o L03.E01: write a C program that
 reads in the radius (r) of a circle and
 displays its diameter (2*r), circumference (2πr) and area (πr2 )
Sample Input / Output
 Input: 2
 Output:diameter is 4
 Output:diameter is 12.571428571428
 Output:diameter is 12.571428571428
o L03.E02: write a C program that
 takes temperature in Fahrenheit and converts it into Celsius using formula C = (F
– 32) * 5/9
 and displays temperature in Celsius
Sample Input / Output
 Input: 98
 Output:36.666666666667
o L03.E03: write a C program that
 takes age of the user in years and
 displays user’s age in months, days and hours.
Sample Input / Output
 Input: 30
 Output:it is 360 months
 Output:it is 10950 days
 Output:it is 262800 hours
o L03.E04: write a C program that
 takes age of the user in years and

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 13 of 14


LECTURE NOTES - CC-112 PROGRAMMING FUNDAMENTALS PROF. DR. SYED WAQAR UL QOUNAIN

 displays the number of times her/his heart beats.


 (hint: assume a human heart beats on the average of once a second)
Sample Input / Output
 Input: 30
 Output:it beat 946080000 times
o L03.E05: write a C program that
 takes the length and width of a rectangular yard and
 the length and width of a rectangular house situated in the yard.
 compute the time required to cut the grass if the grass cutting machine cuts at
rate of two square feet a second
 display the time required
Sample Input / Output
 Output:enter length and width of rectangular yard
 Input: 20
 Input: 20
 Output:enter length and width of rectangular house inside yard
 Input: 10
 Input: 10
 Output:it will take 150 seconds
o L03.E06: write a C program that
 takes rate of growth of an insect population expressed in percentage per week
and the initial size of the population
 then compute and display the size of population for next three weeks, assuming
that growth continues at the same rate.
Sample Input / Output
 Output: enter rate of growth of an insect expressed in percentage per week
 Input: 1.5
 Output: enter initial size of the populations
 Input: 1000
 Output: 1015
 Output: 1030.225000
 Output: 1045.678375
o L03.E07: write a C program that
 displays Raheem’s gross pay, net pay, and taxes
 Raheem the Worker always works 52 hours a week.
 he earns Rs. 900 for the first 40 hours he works.
 he gets one and a half times (1.5 times) of his regular hourly pay for the first 10
hours over 40.
 he gets double time for all hours over 50.
 he pays 8 percent tax on his gross earning.
Sample Input / Output
 Output:gross pay is 53100
 Output:net pay is 48852
 Output:taxes are 4248

DEPARTMENT OF INFORMATION TECHNOLOGY UNIVERSITY OF THE PUNJAB, LAHORE Page 14 of 14

You might also like