Professional Documents
Culture Documents
C, C++ Language For Bio-Medical Engineering Courses PDF
C, C++ Language For Bio-Medical Engineering Courses PDF
C, C++ Language For Bio-Medical Engineering Courses PDF
Table of Contents
INTRODUCTION: ................................................................................................................................... 4 Ch-1: the turbo C programming environment ; [start here] ........................................................................ 6 Fig # 1 .................................................................................................................................................. 16 Fig # 3 .................................................................................................................................................. 25 ADDRESS-OPERATOR (AMPERSANDS)& :- .......................................................................................... 29 Diagram [ fig # 4 ] ............................................................................................................................... 30 MULTIPLE INPUT WITH SINGLE scanf(); :-.............................................................................................. 30 Fig # 5 .................................................................................................................................................. 31 HOW TO ENTER THE VALUE:- ................................................................................................................. 31 FIELD-WIDTH SPECIFIERS:- ...................................................................................................................... 35 DIGIT-PRECIDING THE DECIMAL POINT:- ................................................................................................ 36 getche(); FUNCTION: ............................................................................................................................... 39 CH-2 [ START HERE] ..................................................................................................................................... 41 VARIABLES :-................................................................................................................................................ 41 OPERATORS:- ......................................................................................................................................... 44 THE INCREMENT AND DECREMENT OPERATOR:- ................................................................................... 55 COMMENTS-OPERATORS:- ..................................................................................................................... 60 RELATIONAL-OPPERATOR:- ..................................................................................................................... 61 a. RELATIONAL OPERATORS [EQUAL-TO] [==] OPERATORS:- .......................................................... 70
PRECEDENCE, ROUND II :- ....................................................................................................................... 72 Ch-3 start here [ LOOP ] ............................................................................................................................. 74 GETCHE(); ................................................................................................................................................ 76 OPERATION-OF-FOR-LOOP:- ................................................................................................................... 80 gotoxy(c,r) FUNCTION:-........................................................................................................................... 83 CH-3: LOOP:- .......................................................................................................................................... 85 1) FOR LOOP:- ..................................................................................................................................... 86
Page 2-of-199
FOR-LOOP ...................................................................................................................................... 105 WHILE-LOOP(class-1): ................................................................................................................. 119 WHILE-LOOP(class-2): ................................................................................................................ 126 Sunday, May 3, 2009 ............................................................................................................................. 146 (CLASS-1)-DECISIONS:(IF & ELES-STATEMENTS): ............................................................. 146 STRUCTURE-OF-IF-STATEMENT:- .......................................................................................................... 148 OPERATION OF IF-STATEMENT:- ........................................................................................................... 149 WORD-COUNTING PROGRAM:- ............................................................................................................ 150 MULTIPLE-STATEMENT-WITH IF-STATEMENT:- ................................................................................... 152 STRUCTURE OF NESTED IF-STATEMENT:- ............................................................................................. 155 If-Else Statement:- ................................................................................................................................ 156 THE IF-ELSE-STATEMENT:...................................................................................................................... 156 OPERATION-OF-IF-ELES-STATEMENT:- ................................................................................................. 158 CHARACTER GRAPHICS AND THE CHECKER BOARD.............................................................................. 162 DRAW TWO DIAGONAL :-.................................................................................................................... 166 OPERATION-OF-NESTED IF-ELSE STATEMENT:- .................................................................................... 168 ELSE-IF STATEMENT:- ............................................................................................................................ 176 NESTED WHILE-LOOP:-.......................................................................................................................... 178 BREAK-STATEMENT:.............................................................................................................................. 179 CH-5 [FUNCTIONS]: ................................................................................................................................... 181 WORKING-OF-FUNCTION DECLARATION:- ........................................................................................... 184 WHAT DO FUNCTION DO :- ................................................................................................................... 187 FUNCTION THAT RETURNS A VALUE:- .................................................................................................. 193 FUNCTION THAT ACCEPT VALUE:- ........................................................................................................ 199
http://www2.its.strath.ac.uk/courses/c/tableofcontents 3_1.html http://www.cplusplus.com/doc/tutorial/ http://www.physics.drexel.edu/courses/Comp_Phys/Ge neral/C_basics/ ------------------------------------------------------------------- INTRODUCTION: With this bookand turbo C++, you will be taking an easy and effective path to mastery of the C-language and the ability to write PC applications. WHY USE C : in the last decade , the C programming language has become the overwhelming choice of serious PC programmers , why? C is unique among programming languages in that it provides tha convenience of a higher level language such as BASIC or Pascal, but at the same time allows much closer control of a computer s hardware and peripherals, as assembly language does . there are very few operations that can be performed on the PC in assembly language, that cannot be accomplished usually far more convently in C, this is probably the principle reason for Cs popularity on the PC.
Page 4-of-199
But C has other advantages as well. The better C compilers can now generate amazingly fast Code. This code is so efficient that it is often difficult to produce significant speed increases by rewriting it in assembly language . C is also a well structured language: its syntax makes it easy to write programs that are modular and therefore easy to understand & maintain . The C language includes many features that are specifically designed to help create large or complex programs. Finally, C is portable: its easier to convert a C program to run on a different Machine then it is to convert programs written in most other languages . Note : C language is used in many hardware like -> you should have access to an IBM PC, XT, AT,PS/2,or compatible. These machines use 8088,8086,80286,80386,or 80486 Micro-processors. In general, any machine that can run version 2.0 or later of MS-DOS or PC DOS is appropriate. It should have at least 640k of memory.
Page 5-of-199
Ch-1: the turbo C programming environment ; [start here] COMPUTER-LANGUAGE: In the computer, the instruction written according to set of rule and in a specific way of mannar, this set of rules or instructions is called computer-language , for example : C/C++,OOP,java,e.t.c; COMPUTER-PROGRAMMING:The set of instructions [or rules] which will given to computer by which the computer can performed specific task with the help of this instructions , and this set of instructions [or rules ] called as Computer programming . CHARASTISTIC-OF-C-LANGUAGE: Efficient-language: The C-language can directly excess on the hard-ware of a computer system and it use the fever command to compile C-programmed , its more Efficiently as its compared to the other language . CASE-SENSITIVE-LANGUAGE: C-language is a case sensitive language it means that if a character[latter] is written in lower case it will be consider as different form as same latter is written in Upper case ; LINE-SENSITIVE-LANGUAGE:
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 6-of-199
The C-language is not a line sensitive language because it mean that , you can write several command in same line by using statement-Terminator[ semi-colon = statementTerminator = ; ]. PORTABLE-LANGUAGE:The C-language can be stored on one type of computer like Pentium-4 , computer system , but it also be store on easily on other type of computer like Pentium 1 or 2 computer system, that is its require less system requirement during execution, BASIC-FOR C++ : The statements , commands and methodologies which is used in C language they are also available in C++ , thus learning CLanguage is the 1st step towards learning C++ language. INTEGRATED-DEVELOPMENT-ENVIRONMENT [IDE]: The environment of C is called as IDE, it is a screen display environment with windows and pull down menus, its similar as DOS editor . Input screen for C-language = IDE; Output screen of C-language = DOS; ----
Page 7-of-199
Q2) #include<stdio.h> #include<conio.h> Void main(void) { int event; /* we just declaring the variable here */ char heat; /* we just declaring the variable here */ float time; /* we just declaring the variable here */ event=5; /* we assigning the value of each variable here */ heat= c; /* we assigning the value of each variable here */ time= 27.25; /* we assigning the value of each variable here */ printf( The winning time in heat %c , heat ); printf( of event %d was %.2f . ,event, time); } -----------finished-here---------%c = single character . %s= string= most character. %d= signed decimal integer.
Page 8-of-199
%f= floating point (decimal notation). %e= floating point (exponential notation ). %g= floating point (% f or %e, which ever is shorter). %u=un-signed decimal integer. %x= un-signed hexa-decimal integer (uses a,b,c,d,e,f ). %o= un-signed octal integer. I=prefix used with %d, %u, %x, %o to specify long integer ( for example %Id ). ------------finished here-------Q) SOURCE-CODE: #include<stdio.h> #include<conio.h> Void main(void) { Float year, days; printf( please type your age in years: ); scanf(%f,& years);
Page 9-of-199
days=years*365; /* the star[*] used for multiplication in Clanguage */ printf ( \n you are %.1f days older \n, days); } OUT-PUT AT DOS SCREEN: please type your age in years: 23 you are 8395 days older please type your age in years: -----------Finished-here----------Q) #include<stdio.h> #include<conio.h> void main(void) { Float years,days; /* we declared variable */ printf( please type your age in years: ); scanf(%f,& yrars); days=years*365; /* here we assigning the value */
Page 10-of-199
printf(\n you are %.1f days older\n, days); getche(); } Out-put [ on DOS screen ]: please type your age in years: 14 you are 15110 days older please type your age in years: --------finished-here----#include<stdio.h> #include<conio.h> void main(void) { int joy; printf(What is yours age : ); scanf(%d,& joy); joy=14 printf(\n your age is %d\n, joy); getche();
Page 11-of-199
} OUT-PUT: What is yours age : 14 your age is 14 -----------FINISHED-HERE---Q) #include<stdio.h> #include<conio.h> void main(void) { Printf(My name is Sikander); Printf(your name is Sikander \n); Printf(OHH); Getch(); } My name is Sikander your name is Sikander OHH --------------finished-here----------
Page 12-of-199
COMPUTER-LANGUAGE:In the computer, the instruction which will write according to the specific rules, this rule is called computer language or c/c++, java, BASIC, ------------FUNCTION-DEFINITION: The main() is a basic function of C-programmed , the Cprogrammed consists of one or more functions the main() is the only function ,, to which it controlled , it pass from operating system during the programmed is executing its the 1st function which is executed. void main(void) : The word void preceding main ( void main( ) ) specified the function may not return any value, the second void in the parenthesis () specified that the function take no arguments or any value. DELIMITERS {}:
The Delimiters are the brackets which shows the beginning and end body of a function , the opening bracket
Page 13-of-199
indicated or shows the start of function and closing bracket indicate the end of function. C-STATEMENTS:STATEMENT-TERMINATOR [ ; ] :A C-statement is terminated [ or stop ] is called semi-column [;] , it mean user can write several instruction in a same line by using semi-column[;] in between them. E.g: Void main(void) { Clrscr(); printf() FUNCTION: The command in c-language is called printf(); is a function that it causes , a sentences inside the cottation ( ) to be printed on output screen. e.g: printf(first C-program); this statement [printf();] will prints [ first C-program ] on the DOS screen [ out-put screen ].
Page 14-of-199
1) COMPILER OR COMPILING: A programmed that is to be executed in micro-processor must be in a form of machine-language[1/0] form. The compiler which is a part of IDE , whose translated the source code into the another files in machine language . That is : [ 1/0 ] forms. 2) LINKING OR LINKER: The process of linking links various labourly routeins with the programmed takes the compilar and the linker both are build in turbo-C environment IDE . The text editor produces .C[sources files] by program.me which converted into .Obj [ object files] by the compiler , which is then converted into .exe [ executed files ] by the linker. .c [ source file ]
Page 15-of-199
AN EXPLORING printf() :Some useful key word are available in c-program that word lie in between coutation ( ); of printf(); command.
Page 16-of-199
Escape Sequence: Its the words that performed special key function with in the coutation of printf(); command . Example:\b = escape sequence to delete . \n = new line. \t = tab [ 8-digit gap ]. \ = single quotes . \ = double quotes. Example: void main(void) { printf( Each \t ward \t is \n tabbed \t over \t once); getch(); } DOS out put : Each tabbed ward over is once
Page 17-of-199
-----------finished-here--------void main(void) { printf(Each \t word \t is \n tabbed \t over \c \a \t once); } Output: Each tabbed word is once
over c a
--------------finished-here--3. FORMAT SPECIFIER: A formatted specifier is used to controlled what format is be used by printf(); to print out a particular variable or constant . And it also tell printf(); where to put a value in a string [ %s ]. IMPORTANT-FORMAT-SPECIFICAS-ARE: 1). %c = single character. 2). %s = string [ group of character ]. 3). %d = Integer [ number ].
Page 18-of-199
4). %f = floating point number [ Decimal number e.g : 0.01 ]. Example: printf( this is %c ,A); printf( this is %s , Book); printf( this is number %d, 2); printf( this is number %f ,4.50); ----------finished-----Q) Write a program that print the sentence? Given: A,b,c all are characters Solution: Source code: #include<stdio.h> #include<conio.h> void main(void) { clrscr(); /* clrscr(); -> this command is used for clean the screen after executing the program */
Page 19-of-199
printf( %c,%c,%c all are character , a,b,c); getch(); } DOS out put : a,b,c all are character ---finished-here-------Q) what is the output of following program ? SOURCE-CODE:#include<stdio.h> #include<conio.h> { clrscr(); printf(%s \n %s \n %s ,one,two,three ); getch(); } OUT-PUT: one two three
Page 20-of-199
---------------------finished-here-----------Q) write the table in your program? OUT-PUT: 2*1=2 2*2=4 2*3=6 SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { clrscr(); printf( 2*1=%d ,2); printf(\n 2*2=%d,4); printf(\n 2*3=%d,6); getch(); } -------------finished-----OR
Page 21-of-199
SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { clrscr(); printf(\t 2*1=%d ,2); printf(\n \t 2*2=%d,4); printf(\n \t 2*3=%d,6); getch(); } --finished---------Q) DOS OUT-PUT : Each tabbed once SOURCE-CODE: #include<stdio.h> word over c is a
Page 22-of-199
#include<conio.h> void main(void) { clrscr(); printf(\t Each\t word\t is); printf(\n\t tabbed \t over \c \t \a ); printf(\n\t once); getch(); } -----------finished-------PRINT GRAPHIC CHARACTER:1. \xdd = Hexacode of ASCII . 2. \ddd = octalcode of ASCII. Two scape sequences \ddd and \xdd are used to print ASCII code by using printf(); function. Example: Q) write a program that display box? Given: Fig # 2 :
Page 23-of-199
Solution: SOURCE-CODE: #include<stdio.h> #include<conio.h> { clrscr(); printf(\xC9 \xCD \xCD \xBB\n); printf(\xBA \xBA\n);
printf(\xC8 \xCD \xCD \xBC); getch(); } -------------finished-here-------Lecture-Date on SSUET : 29/7/2006 scanf(); Function:-
Page 24-of-199
the scanf(); is a input function that takes a input from the user and save it in to the memory location define by variable . scanf(%f,&years); Diagram: Fig # 3
User must type [enter] then function will digest what user has been type.
Page 25-of-199
If we used only variable name that is ,year ,means the contain of the variable year that is 18 . If we used & year its mean the physical address of memory location, reserve by the variable that is 1367 to 1670. Example: #include<stdio.h> #include<conio.h> void main(void) { Float year,days; printf(Enter your age in years: ); scanf(%f,&year); days=years*365; print(your age in days is %f , days); } -------finished-here--------Q)
Page 26-of-199
Write a program that take a number from user and display its square? Solution: #include<stdio.h> #include<conio.h> void main(void) { int num1,square; printf(write a program that take a number from the user and display its square); scanf(%d,& number); square=number*number; printf(The square of %d is %d,num,square); } ----finished Write a program that take a number from the user and print its table? SOURCE-CODE:#include<stdio.h>
Page 27-of-199
#include<conio.h> Void main(void) { Int num; printf(Enter a number); scanf(%d,&num); printf(%d*1=%d,num,num*1); printf(%d*2=%d,num,num*2); printf(%d*3=%d,num,num*3); printf(%d*4=%d,num,num*4); printf(%d*5=%d,num,num*5); printf(%d*6=%d,num,num*6); printf(%d*7=%d,num,num*7); printf(%d*8=%d,num,num*8); printf(%d*9=%d,num,num*9); printf(%d*10=%d,num,num*10); getch(); }
Page 28-of-199
-----finishedvoid main(void) { float num,cube; printf(Enter any number); scanf(%f,&num); cube=(num*num*num)+10; printf(The cube+10 of the number is %f); getch(); } ------------finished--ADDRESS-OPERATOR (AMPERSANDS)& :The & is a Address operator when even user write & on preceding variable name so its shown a physical address of that variable in the memory, as shown in the following example: Example : void main(void) { int a; a=2; printf( value =%d,Address=%d,a,&a);
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 29-of-199
---------answer-----finished----MULTIPLE INPUT WITH SINGLE scanf(); :Multiple input with single scanf(); is also possible but it have some limitation. SOURCE-CODE:void main(void) { int a; char b;
Page 30-of-199
float c; printf( Enter a character,integer and decimal : ); scanf(%c %d %f,&a,&b,&c); getch(); } See fig # 5 Fig # 5
Page 31-of-199
If the formatted specifies are separated with single space then at the time of entering Data user can used single space, \t [tab] or enter [any wide space character. If a formatted specifiers are separated with [, OR . ] at the time of entering Data user should used that same character other wise the garbage data will be enter. Enter any character , Integer and Floating: Letter is A Integer is 25 Float is 2.5
Page 32-of-199
float c; printf(Enter a character, integer and float); scanf(%c %d %f,&a,&b,&c); printf(leter is %c \n,a); printf(integer is %d \n,b); printf(float is %f \n,c); } OUT PUT: Enter a character, integer and float leter is A integer is 2 float is 6.2 ------finished--Write a program to calculated the doubble of number which is enter by a user? SOUCE-CODE: #include<stdio.h> #include<conio.h>
Page 33-of-199
void main(viod) { clrscr(); Int num,dubble ; printf( write a program to calculated dubble of number); scanf(%d,&num); dubble=num*2; printf(The dubble of number is %d,dubble); getch(); } _----------------finished--------Write a program , in which the user give input and he get half of it.? #include<stdio.h> #include<conio.h> void main(void) { clrscr(); int num,half; printf(wirte a program in which user give input and he get half of it );
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 34-of-199
------------FIELD-WIDTH SPECIFIERS:The field with specifier is used to controlled the width of variable which is to be printed by the printf() function . DIGITAL PROCEDING THE DECIMAL POINT:The digit proceding the decimal point determine how many digit will be printed after the decimal point [ 0.15 ] in case of printed any floating point. e.g: void main(void) { float num=35.42; printf(Number is %6.2f ,num); getch();
Page 35-of-199
} OUTPUT: Number is 35.42 ----------DIGIT-PRECIDING THE DECIMAL POINT: A digit preciding the decimal point in the field with specifier. Controlled the width of space, to be used to contain , the number , when its printed . Example: int age=33; 1. printf(Age is %6d.,age ); fig # 6(a)
Page 36-of-199
Page 37-of-199
Page 38-of-199
------------APPLICATION:Its useful when user have to display sequence of number column wise . ------------getche(); FUNCTION: the getche(); function is use to take character in-put, & save it in memory space , the main advantage of getche(); function over scanf(); is that getche(); function does not
Page 39-of-199
need to press Enter [ \r ] input to transfer the value to the variable as scanf(); function need. The Dis-Advantage Of getche(); function: the disadvantage of getche(); over scanf() is that , if user type wrong character then there is no back space option as in scanf(); function. Example: void main(void) { char ch; printf(Type any character ); ch=getche(); printf(\n you typed %c,ch); getch(); } OUTPUT: Type any character:T You typed T ---------------
Page 40-of-199
CH-2 [ START HERE] VARIABLES :Variable is a space in memory that play the same role many times but many contain a different value each time . For Example : To calculated the grade of different student. TYPES-OF-VARIABLES-AND-BYTES-OCCUPIED-BY-VARIABLES :Fig # 7
Page 41-of-199
Fig # 8 -------Example:void main(void) { int num; num=2; printf( This number is %d,num); getche();
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 42-of-199
} OUT-PUT: This number is 2 -------------Q ) write a program in which the user can put the value of voltage and resistance and find current? SOURCE CODE: #include<stdio.h> #include<conio.h> void main(void) { clrscr(); /* clrscr(); its used to clear the DOS output screen */ float resistance; float volt; float current; printf(Enter the value of voltage and resistance and press enter:\n); scanf(%f,%f,&volt,&resistance); current=volt/resistance;
Page 43-of-199
printf( \n The value of current is %f \n,current); getch(); } OUT-PUT: Enter the value of voltage and resistance and press enter: 17.5 The value of current is 0.770000 Enter the value of voltage and resistance and press enter: ------------finished---OPERATORS:Operators are word or symbols that cause a program to do something with variables. Example: The arithmetic operator (+) and (-) which cause a program to add or subtract two numbers there are many different kinds of operators are given below. 1. AIRTHMATIC-OPERATORS:The C-language can uses the fore arithmetic operators that are common in most programming languages and the another one remainder operator which is not so common.
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 44-of-199
e.g in C-program we used multiplication operator [ * ] to multiply two number together that is : 1. [+] Addition. 2. [-] Subtraction. 3. [*] multiplication. 4. [/] division. 5. [%] remainder . There is a example below where several airthmatic operator are used so this program which converted temperature in Fahrenheit to centigrade. SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { int ftemp,ctemp; printf(type temperature in degree Fahrenheit: ); scanf(%d,&ftemp); ctemp=(ftemp-32)*5/9; printf(temperature in degree centigrade is %d,ctemp);
Page 45-of-199
getch(); } OUT-PUT: type temperature in degree Fahrenheit: 32 temperature in degree centigrade is 0 type temperature in degree Fahrenheit: 70 temperature in degree centigrade is 21 type temperature in degree Fahrenheit: -------------------The c-program need to used standard formula for converting degree farenheit into degree centigrade subtract 32 from Fahrenheit temp and multiply the result by 5/9 [ ];
There are several things to note about this statement. First you will see in eq-B , we have surrounded some of the operators , the * and the [/] , with spaces but have not used spaces around the minus sign but the compiler does not care what ever you used spaces surrounding your operators or not, so, you are free to aggange your expression how ever they look best to you , if you do not like this way of spaces are
Page 46-of-199
arrange in example so, you can arrange them another way when you type in program. 2. OPERATOR-PRECEDENCE:Operator in c-language have the same precedence as in mathematics . OR Operator in c-language have a same method to solve mathematical equations as we solved in mathematics. e.g: [ [ [ [ [ ]; ]; 3. ARITHMETIC-ASSIGNMENT OPERATORS:If you compare a C-program with a program with a similar purpose written in another language. Example: ]; ]; ];
Page 47-of-199
Total=total+number; {:. Total=10,number=20 } So, in the memory location of total before execution the value of total is equal to 10 , and then when we add (total+number) then its value become total=30 in the memory location, after execution. Fig # 9
So,
Page 48-of-199
We can applied this method which produced similar result as in above by another language that is [ total+=number]. Total+=number {:. Total=10,Number=20} In this memory location the total value before execution , the value of total is equal to 10, and number=20 before execution in memory location , then when we add (total+=number) , then the value of total become [ total=30] and placed in some memory location after execution. [ [ ]; ];
So, both eq-I and ii performed some role before and after execution, in memory location and in output source. Fig # 10
Page 49-of-199
There are some following different types of arithmetic assignment operators are given below. (+=) Addition assignment operators (-=) substraction assignment operators. (*=) multiplication assignment operators. (/=) division assignment operators. (%=) remainder assignment operators. Example:
Page 50-of-199
FOR ADDITION: SOURCE-CODE:#include<stdio.h> #include<conio.h> void main(void) { int total=0; int count=10; printf(Total=%d\n,total); total+=count; printf(total=%d\n,total); total+=count; printf(total=%d,total); getch(); } OUTPUT : Total=0 total=10 Total=20
Page 51-of-199
FOR SUBSTRACTION:SOURCE-CODE: #include<stdio.h> #include<conio.h> { int total=10; int count=40; printf(Total=%d\n,total); total-=count; printf(Total=%d\n,total); total-=count; printf(Total=%d,total); getch(); } OUTPUT: Total=10 Total=-30 Total=-70 -------------
Page 52-of-199
FOR-MULTIPLICATION: SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { int total=50; int count=7; printf(Total=%d\n,total); total*=count; printf(Total=%d\n,total); total*=count; printf(Total=%d,total); getch(); } OUTPUT: Total=50 Total=350 Total=2450
Page 53-of-199
FOR DIVISION:SOURCE-CODE:#include<stdio.h> #include<conio.h> void main(void) { float total=73.52; int count=50; printf(Total=%f\n,total); total/=count; printf(Total=%f\n,total); total/=count; printf(Total=%f,total); getch(); } OUT-PUT: Total=73.52 Total=14.704 Total=0.294
Page 54-of-199
----------finished--THE INCREMENT AND DECREMENT OPERATOR:a. INCREMENT OPERATOR:The C-language used another operator that is IncrementOperator, there are the following program are given below. SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { int num=0; printf(Number=%d\n ,num); printf(Number=%d\n,num++); printf(Number=%d,num); getch(); } OUTPUT: Number=0 Number=0 Number=1
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 55-of-199
-----------SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { int num=14; printf(Number=%d\n,num); printf(Number=%d\n,num++); printf(Number=%d\n,num++); printf(Number=%d\n,num++); /* num=17(in memory)*/ printf(Number=%d\n,++num); /*num=18(in memory and display output*/ printf(Number=%d\n,++num); /*num=18+1(19)(in memory and display output*/ printf(Number=%d\n, num++); /*num=19+1(20)(in memory[20] and display[19] output*/ printf(Number=%d\n, num); /* num=20 (in display) */ getch(); }
Page 56-of-199
OUT-PUT: Number=14 Number=14 Number=15 Number=16 Number=18 Number=19 Number=19 Number=20 ------------SOURCE-CODE: #include<stdio.h> #include<conio.h> { int num=22; printf( Number=%d\n,num); /*num=22*/ printf(Number=%d\n,num++);/*num=22+1=23, num=23 in memory , and in display is 22 */
Page 57-of-199
printf(Number=%d\n, num--); \*num=23-1=22, 22in memory and 23 in display*\ printf(Number=%d\n, ++num); \*num=22+1=23, 23 in memory and also 23 in display *\ printf(Number=%d\n,num+1); \*num=23+1=24, 24 in display *\ printf( Number=%d\n,--num);\*num=24-1=23, 23 in memory and also in display*\ printf(Number=%d\n,num+1);\*num=23+1=24,24 in display ut not in memory *\ printf(Number=%d\n, num-1);\*num=23-1=22, 22in display and 23 in memory*\ printf( Number=%d\n,--num);\*num=23-1=22 , 22 in memory and also in display*\ printf(Number=%d\n,num);\*num=22,22in memory and also in display*\ printf(Number=%d\n,++num);\*num=22+1=23, 23 in memory and also in display*\ printf(Number=%d\n,num);\*num=23, 23in display *\ getch(); }
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 58-of-199
OUT-PUT: Note:Try by your self. -----finished---------DECREMENT: SOURCE-CODE:#include<stdio.h> #include<conio.h> void main(void) { int num=-18; printf(Number=%d\n,num);\* num=-18*\ printf(Number=%d\n,num--);\*num=-18-1=-19,-19 in memory but -18 in display*\ printf(Number=%d\n,--num);\*num=-19-1=-20,-20 in memory and also in display *\ printf( Numbe=%d\n,num-1); \*num=-20-1=-21 , -21 in display but not in memory *\ printf(Number=%d\n, num);\*num=-20*\ OUT-PUT:
Page 59-of-199
-18 -18 -20 -21 -20 ---------------finished here----COMMENTS-OPERATORS:The comments [ /* */ ] , is helpful to used it always used in the source code file, the main purpose of comments is the programmer can written any thing about its program any explination related to guid or own sattisfication which are written inside [ /* any thing about program */ ] and this comments is visible for a programmer but un visible for the compiler, We can also used comment by indicated the deactivated statement for debugging { removing error} in program. Example: SOURCE-CODE: #include<stdio.h> #include<conio.h>
Page 60-of-199
void main(void) {int year,days; /* integer variable */ printf( Enter age in years); /* print your age*/ scanf(%f,&years); /* take input*/ days=years*365; printf(you are %f days old, days); /* display output */ getch(); } --------RELATIONAL-OPPERATOR:In the next two chapter we will be dealing with loops and decision, these constructs require the program to ask question about the relationship between two variables. Relational operator are vocabulary the program uses to ask questions about variables . The user just typed equal to and then a space then a character that is shown in below fig # 11:
Page 61-of-199
EXAMPLE: This program is called less than.c : SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { int age; age=15;
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 62-of-199
printf(Is age less then 21?%d\n, age < 21); age=30; printf(Is age less then 21? %d \n, age<21); } OUT-PUT: Is age less then 21? 1 Is age less then 21? 0 -----In this program above the printf() statement takes the whole expression Age <21 The value of age depend on the value of age which are assigned at above printf() function. The every value depend on value the variable age that is When age is 15 [ age=15;] , /* which is less then 21*/ Than Printf(Is age less than 21? %d\n , age <21); Then this statement age =15; in which age is less than 21 this statement is true,so,
Page 63-of-199
Then , It print out 1 integer, this mean that , the above statement that is age<21 is true , so c-language shows 1 integer that is statement is true , or +5 volt, see in below fig # 12 ,
2. When age is 30, [ age=30] age=30;/* which is greater then 21*/ , then printf(Is age less than 21 ? %d \n , age < 21 );
Page 64-of-199
then in this statement where [ age= 30; ] in which age is greater then 21 this statement is false. Then it print 0 integer , this mean that , the above statement that is age < 21 is false because age = 30; So, c-language , shows 0 integer that is statement is false or 0 volt , 0 integer , In c-language : True: In the C-language the true is represented by the integer 1 or 5 volts or statement is true. False:In the c-language the False is represent by the integer [0 ] , or 0-volt, [ zero integer, or zero-volt], or the statement is false. Also, IN SOME OTHER LANGUAGE:There are some other language such as Pascal, true and false value are presented by a special variable type called Boolean.
Page 65-of-199
THE RELATIONAL OPERATOR IN C-LANGUAGE LOOK MUCH LIKE THOSE IN OTHER LANGUAGE THERE ARE SIX OF THEM :< Less than > Greater than <= Less or equal to >= Greater than or equal to == Equal to != Not equal to -----------DIAGRAM: FIG # 14 If age =15; then Fig # 14 (a)
Page 66-of-199
Page 67-of-199
2. Diagram [ fig # 15 ]
INPUT-SOURCE:Fig # 15 (a)
Page 68-of-199
Page 69-of-199
----------a. RELATIONAL OPERATORS [EQUAL-TO] [==] OPERATORS:In the relational-Operator we used another thing is that equal to which is represented by two equal signs. That is . [ == equal to ] But we do a simple mistake is that is we usually put single equal to sign that is wrong for relational operators .
Page 70-of-199
But the compiler does not notice as an error, when we put single equal-to sign that is which is wrong for relational operators . So, when we using equal to [ ==] operator (some time called Equal-equal Operators). FOR EXAMPLE : Input-source:#include<stdio.h> #include<conio.h> Void main(void) { int speed = 75; printf(Is speed equal to 55? %d\n,speed==55); speed=55; printf(Is speed equal to 55?%d\n, speed==55); getch(); } OUT-PUT : Is speed equal to 55? 0 Is speed equal to 55? 1
Page 71-of-199
---------finished Q) When C-language generated either false [0] or true [1] value ? Answer: An interesting point to notice about true and false value is that , althose c-language will generated a 1 when it observed that the statement is true. Also c-language will generated a 0 when it observed that the statement is false. I will recognize any non-zero value as true . that is there are a lot of integers that c-language thinks of as true , but only one0- it thinks of as false, we will make use of this fact in letter programs. ------------finished----------PRECEDENCE, ROUND II :Q ) What will be printed out if you execute the following program? {:. Remember that True is the integer [1] or 5 volt [ statement is right] , when false is the integer [0] or 0 volt [or statement is false]} These values can be used just like any other integer values as shown below?
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 72-of-199
Example: INPUT-SOURCE CODE: #include<stdio.h> #include<conio.h> void main(void) { printf(Answer is %d, 2+1 < 4 ); getch(); } ------------- if you think Answer is 1 so you right , in this first 2+1 is evaluated to yield 3 , that is 2+1=3 , then this compared with 4, its less then 4, [ 3<4 ] , so then expression becomes true or statement is true that is 1. OUTPUT: Answer is 1 This mean the statement is true. ------finished-here---------#include<stdio.h> #include<conio.h>
Page 73-of-199
void main(void) { clrscr(); printf(Answer is %d, 2+1<4); printf(\n answer is %d, (1<2)+4); getch(); } OUTPUT: Answer is 1 Answer is 5 ------------finished----------Ch-3 start here [ LOOP ] #include<stdio.h> #include<conio.h> void main(void) { int i ; for(i=1;i<11;i++) {
Page 74-of-199
printf( 2*%d=%d \n,i,i*2); } getch(); } OUTPUT: 2*1=2 2*2=4 .. . . 2*10=20 ----FHINISHED FOR-LOOP:Input-source-code:#include<stdio.h> #include<conio.h> void main(void) { int a;
Page 75-of-199
for(a=1;a<13;a++) { printf(2*%d=%d \n,a,a*2); } for(a=1;a<13;a++) { printf( \n 3*%d=%d,a,a*3); } getch(); } OUTPUT: TABLE OF 2 UP TO 12 TABLE OF 3 UP TO 12 ----FINISHED--GETCHE(); #include<stdio.h> #include<conio.h> viod main(void)
Page 76-of-199
{ char n; printf( Enter the 1st ch of your name: ); n=getche(); printf(\n Hellow Mr. %c , n ); getch(); } OUT-PUT: Enter the 1st ch of your name: S Hellow Mr. S Enter the 1st ch of your name: ------finished----------Write a program that take a number from the user and display its table using For loop? SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { int a,i;
Page 77-of-199
printf(Insert any number to get the table of it); scanf(%d,&a); for(i=1,i<=10,i++) { printf( %d*%d=%d ,a,i,i*a); } getch(); } OUT-PUT: --------------finishd----Q write a program that take a number from the user and display its table up to 15 times by using For Loop? ANSWER: SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { int a,s,p;
Page 78-of-199
for(a=1;a<=15;a++) { printf(Enter a number of your choice :); scanf(%d,&s); p=s*a; printf(%d*%d=%d,s,a,p); printf(\n); } getch(); } ------------finished----------Q ) Write a program that display the following series using for for-loop ?
];
Page 79-of-199
void main(void) { int i,j; for(i=1;i<=7;i++) { j=20+(2*i); printf(%d/%d ,i,j); } getch(); } -----------------finished-here-----------OPERATION-OF-FOR-LOOP:First of all the initialize expression is expected then the text condition is examined. If the test condition is false to being then the body of loop is not be executed at all . If the test condition is true , then body of loop is executed and then the following that the increment expression is executed. This is why the 1st Number is printed out by program, [ example 1 ] is 0 not 1, Printed taking place before count is incremented by [++] operators .
Page 80-of-199
Finally the loop re-cycles, and the text expression , examined again it will continuous , until text expression is false. Example 1: void main(void) { Int count; for(count=0;count<=10;count++) { printf(%d\n,count); } getch(); } OUT-PUT: 0 1 2 3 4
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 81-of-199
5 6 7 8 9 10 --------finished---------Example 2: void main(void) { int count,total; for(count=0;count<=10;count++) { total=total+count; printf(count=%d,total=%d\n, count,total); } getch(); } OUT-PUT:-
Page 82-of-199
Count=0 , total=0 Count=1, total=1 Count=2, total=3 . . . Count=9 , total=45 -------------finished--gotoxy(c,r) FUNCTION:its used to controlled the curser position on the screen [DOS screen ]: Example :#include<stdio.h> #include<conio.h> void main(void) { int i; for(i=20;i<=40;i++) { gotoxy(i,5);
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 83-of-199
----finished----EXAMPLE : #include<stdio.h>
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 84-of-199
#include<conio.h> void main(void) { int i , j ; for(i=20;i<=40;i++) { gotoxy(i,5); printf(\n DB); } for(j=70;j<=80;j++) { gotoxy(j,20); printf(\nDB); } getch(); } ------------finished----------CH-3: LOOP:The loop has the ability to performed a set of instruction , many times.
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 85-of-199
Its used for repeating some portion of program either 1. Specific number of time . 2. Or until particular condition has been satisfied. There are three types of LOOPs:1. For loop [ its used for fixed number of times ]. 2. While-Loop [ we used while loop to re execute a program but we donot know how many times we executed this program] 3. Do While Loop [ or Do-Loop].
1) FOR LOOP:Its often the specific case in programming , that you want to do some thing with a fixed number of time. ADVANTAGE OF FOR-LOOP:The advantage of for-loop is that : 1. If you want to calculated the paychecks for 120 employes in any organization, you should to calculated with the help of For-Loop by fixed number of time. 2. If you are too hurry, so you should calculated the square of each integer form 1-to-50 , in the order of , then you
Page 86-of-199
used for-loop , to egt the square value of each integers form 1-to-50, Example : #include<stdio.h> #include<conio.h> void main(void) { int count; for(count=0;count<10;count++) { printf(count=%d\n,count); } getch(); } OUT PUT:Count=0 Count=1 .
Page 87-of-199
. Count=9 --------finished---------STRUCTURE-OF-THE-FOR-LOOP:The way of following patterns, in which the key word for plays an important role in the For-Loop , this key-word [for] Used to drive the for loop expression, that is [ (count=1;count<10;count++)] its called as Loop expression: Now The hole For-Loop-Expression divided by the semicolon[;] into three separated individual expression, which are given below, (count=1;count<10;count++) 1. Initialize Expression [ count=1 ]. 2. Test-Expression [ count<10 ]. 3. Increment [Or Decrement ] Expression [ Count++ (or Count--)].
Expression 1 Count=0
2 Count<10
Purpose Its used for initialized loop expression /* for assigning value of count variable*/ For test loop variable /* for
Page 88-of-199
Expression
fixed number of time or to check either variable count is less than or equal to 10 or not or this statement is true or false. Its used for increment or decrement loop variables.
Page 89-of-199
LOOP-EXPRESSION:There are three types of loop expression. 1. INITIALIZE-EXPRESSION:a. The first expression is the initialize expression (count=0) ,after written this expression we placed a semi-colon [ ; ] this expression is used to initialize the count variables or its used to assigning the value of variable count as 0 [ count=0] in its memory location. b. This initialized expression [ count=0] is always executed as soon as the loop [ or compiler] entered in this initialize expression. c. We can assigning initialize expression with any number let, suppose ( count=1 ) in this above case the variable count is equal to 1 . d. But if is not necessary , the for-loop can be printed out by started with as [ count=1 ], in the output source. e. But its also be possible that , it should be printed out variable count as equal to 2 [ count=2 ] or [ count= -1 ] its depend upon the increment or decrement expression. 2. TEST-EXPRESSION: a. The second expression is the test expression ( count<10 ), this test expression used to test [ check] the cariable count in each time via the loop , either variable count is less than [< ] integer 10 or not that is [ count<10 ].
Page 90-of-199
b. In this test expression where [count<10 ] this expression is used the any relational operators, but in [count<10 ], test expression , it used less then [<] relational operator. c. Suppose, if the test expression is true that is : when variable Count is less than 10 in this test expression [count<10], the body of loop will be executed again and again , till then this test expression will become false, because the reason of this false test expression statement is that variable count is equal or greater than 10, that is [count 10 , or ,count !< 10]. 3. INCREMENT/DECREMENT-EXPRESSION:a. The third expression is the increment expression, that is [count++] this increment expression is used for increment [ or increase ] the value of variable count by adding one integer each time , after , when loop will executed , it increase by adding in the initialize value of variable count with integer [1]. On each turn of the loop cycle. b. Also the third expression is the decrement expression, that is [ count-- ] this decrement expression is used for decrement [ or decrease ] the value of variable count by subtracting one integer each time , after , when loop will executed , it decrease by subtracting in the initialize value of variable count with integer [1]. On each turn of the loop cycle.
Page 91-of-199
------------finished---------LAB # 6 ON SSUET IN BIO-MEDICAL COMPUTING : Q) Write a program that produce the sound of different frequency? SOURCE-CODE: #include<dos.h> void main(void) { int i ; for(i=1925;i>=300;i-=25) { sound(i); /* frequency i=1925-300 */ delay(50); /* delay of 50 micro second */ no sound(); /* its cause to stop sound*/ } } OUT-PUT [ AT DOS SCREEN ]: You heard the SOUND of different frequencies from the internal speaker of your computer . -------------finished-------Lab 5 Objective Write a program that display ASCII code table on out-put screen?
Page 92-of-199
SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { int i ; for( i=1; i<=256;i++) { printf(%d=%c,i,i); } getch(); } OUT-PUT: -------finished----------Q ) write a program that display the following given output by using nested for Loop? See fig # 19 , below. Given fig # 19 :
Page 93-of-199
SOLUTION: Fig # 37
Page 94-of-199
The fig # 37 , show the best diagram to understand the function of c-language , as you can see the direction of x and y ordinate moving from top left corner [ where x=1, and y=1 ] to adjacent position , like y-ordinate move from top left corner of DOS output screen to the bottom left corner of the DOS output screen, similarly the x-ordinate move from top-left corner [ where both ordinate are 1 , x=1, and y=1 ] of the DOS output screen to the top-Right corner of the DOS output screen.
Page 95-of-199
So , if you understand the mechanism of above point then the c-language become much easy for you in terms of analysis point of view . Now we write a required program of given figure # 37 which is in focus for analysis the program. #include<stdio.h> #include<conio.h> void main(void) { int x,y; for(y=1;y<=11;y++) { for(x=1;x<=y;x++) { printf(\xDB); } printf(\n); } getch(); } -------------------------finished------------Q write a Program which display the following given output? Given:
Page 96-of-199
Fig # 38 SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { int x,y; for(y=1;y<=9;y++) { for(x=1;x<=(10-y);x++) { printf(\xDB); } printf(\n); } ------------finished------------Q calculate the simple interest for 3 set of p,n and r ? Using formula: Given [ ];
Page 97-of-199
SOLUTION: SOURCE-CODE: #include<stdio.h> #include<conio.h> void maim(void) { int p,n,r,cal; /* calculated of simple intrest for 3 set of p,n and r */ float ni; for(cal=1;cal<=3;cal++) { printf(Enter the value of p,n and r : ); scanf(%d %d %d, &p,&n,&r); ni=p*n*r/100; printf(\n The value of Rupeise= Rs. %f, ni); } getch(); } OUTPUT SOURCE-CODE: Enter the value of p,n and r : 2 4 2
Page 98-of-199
------finished-here----------
Page 99-of-199
NESTED-FOR-LOOP:If we have to implement a program in which row and columns of out put screen both are involved or change during execution for such type of task we used Nested For loop [ loop inside the another loop]. Example #include<stdio.h> #include<conio.h> void main(void) { int col,row; for(row=1;row<=10;row++) { for (col=1;col<=10;col++) { printf(%d,col*row); } printf(\n); } getch(); } OUT-PUT : 1 2 3 .10 2 4 6 20
Page 100-of-199
3 4 5 6 7 8 9 10 20 30 .100 --------FINISHED---
Page 101-of-199
Page 102-of-199
Page 103-of-199
Page 104-of-199
FOR-LOOP
Q) Using the Getche(); commands in your program? sol: SOURCE CODE: #include<(stdio.h)> #include<(conio.h)> void main(void) {char s; printf("Enter the first character of your name: "); s=getche(); printf("\n hellow Mr. %c",s); getch();
Page 105-of-199
} OUT-PUT: Enter the first character of your name: A hellow Mr. A ______________(FINISHED)___________________ ____ QUESTION) write a program that take a number from the user & display its table by using "FOR-LOOP"? SOURCE-CODE: #include<(stdio.h)> #include<(conio.h)> #include<(dos.h)> void main(void) {clrscr();int s; printf("Enter a Number for using its as a table: "); printf("\n"); scanf("%d",&s); for(i=1;i<=12;i++) {printf("%d*%d=%d",s,i,s*i); delay(50); }getch(); } OUT-PUT: Enter a Number for using its as a table: 3 3*1=3 3*2=6 . . 3*10=30 _______________(finished-here)________________[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 106-of-199
Q) Write a program that take a number from user & display its table up to 15 times by using for-loop? SOURCE-CODE: #include<(stdio.h)> #include<(conio.h)> #include<(dos.h)> void main(void) {int s,i,k; for(s=1;s<=15;s++) {printf("Enter a number of your choice:"); scanf("%d",& i); k=s*i;gotoxy(40,12); printf("%d*%d=%d\n",i,s,k); delay(59); }getch(); } _________________(finished)__________________ Q) Write a program that display ASCII CODE table on output screen?
SOURCE-CODE:
#include<(stdio.h)>
#include<(conio.h)>
Page 107-of-199
#include<(dos.h)>
void main(void)
{int i;
for(i=1;i<=256;i++)
{printf("%d=%c",i,i);
delay(50);
}getch();
________________________________ Q)
Page 108-of-199
SOURCE-CODE:
#include<(stdio.h)>
#include<(conio.h)>
#include<(dos.h)>
void main(void)
{int i;
for(i=1;i<=12;i++)
{gotoxy(1,i);printf("*******");
for(i=12;i<=24;i++)
Page 109-of-199
{gotoxy(45,i);
printf("*******");
}getch();
____________(finished)_________
solution:
SOURCE-CODE:
#include<(stdio.h)>
Page 110-of-199
#include<(conio.h)>
void main(void)
{ int c,r;
for(r=1;r<=10;r++)
for(c=1;c<=10;c++)
printf("%d",c*r);
delay(50);
} printf("\n");
Page 111-of-199
getch();
OUT-PUT:
SOLUTION:
SOURCE-CODE:
#include<(stdio.h)>
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 112-of-199
#include<(conio.h)>
void main(void)
{ int c,r;
for(r=1;r<=24;r++)
{ for(c=1;c<=80;c++)
{ printf("\xDB"); /*printf("*");*/
delay(1002);
} printf("\n");
Page 113-of-199
getch();
OUT-PUT:
________________________________
Q) Write a program which cause to display the table of the user define any single number UPTO 15?
solution:
SOURCE-CODE:
#include<(stdio.h)>
#include<(conio.h)>
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 114-of-199
void main(void)
{int s,i,k;
scanf("%d",& i);
for(s=1;s<=15;s++)
{ k=s*i;
printf("%d*%d=%d \n",i,s,k);
delay(50);
} getch();
Page 115-of-199
OUT-PUT:
__________________________________________ ___
Q)
SOURCE-CODE:
#include<(stdio.h)>
#include<(conio.h)>
void main(void)
{ int s,i,k;
for(s=1;s<=15;s++)
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 116-of-199
scanf("%d",& i);
delay(59);
getch();
OUT-PUT:
Page 117-of-199
12*1=12
15*2=30
______________________________________ Q)
SOURCE-CODE:
#include<(stdio.h)>
#include<(conio.h)>
#include<(dos.h)>
void main(void)
Page 118-of-199
{ int count=2,i;
the above fig show the operation of While-loop: SOURCE-CODE: #include<(stdio.h)> #include<(conio.h)> void main(void)
Page 119-of-199
{ int count=o,total=0; /*INITIALIZED-EXPRESSION*/ while(count<10)/*test-expression*/ { total=total+count;printf("count=%d,total=%d \n",count++,total); /*BODY OF LOOP */ } getch(); } OUT-PUT: _________________________ Q) write a program that takes i/p from the user & print the table of that number ? (using While-loop)? SOURCE-CODE: #include<(stdio.h)> #include<(conio.h)> void main(void) { int s,i=0,k; printf("enter the value of that number to used in table:"); scanf("%d",& k); /*getche();==siv*/ while(i<=15) /* while(i != '\r') where => \r=enter */ { s=k*i; printf(" %d*%d=%d \n ",k,i,s,i++); } getch(); } OUT-PUT: ________________________________
OPERATION-OF-WHILE-LOOP:
#include<(stdio.h)> #include<(conio.h)>
Page 120-of-199
void main(void) { int i=1; while(i<11) { printf("sik"); i++; } getch(); } _____________________________ Q) Write a program that prints a line of * on the corner's of screen by using the while-loop? SOURCE-CODE: #include<(stdio.h)> #include<(conio.h)> #include<(dos.h)> void main(void) { clrscr(); int s=1; while(s<=80) {gotoxy(s,1);
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 121-of-199
printf("*");delay(10); s++; } s=1; while(s<=24) {gotoxy(80,s);printf("*");delay(10);s++; } s=80;while(s>=1) {gotoxy(s,24);printf("*");delay(50);s--;} s=24;while(s>=1); {gotoxy(1,s);printf("*");delay(50);s--;} getch(); } OUT-PUT: ___________________________________ WHILE-LOOP: UN-EXPECTED-CONDITION: SOURCE-CODE: #include<(stdio.h)> #include<(conio.h)>
Page 122-of-199
void main(void) { clrscr(); char ch; while(ch != '\r' ) { printf("Enter a character:\n"); ch=getche(); /* scanf("%c", & ch); */ printf("\n the code of %c is %d",ch,ch);}getch(); } OUT-PUT: Enter a character: A the code of A is 65 Enter a character: ____________________________
GETCHE(); :
--->This commands is always used to take the character i/p by the user, --->this commands only take the character i/p by the user ; ---->this command dont used any integer-type i/p by the user; --->the main difference b/w getche(); & scanf(); commands is that , in scanf(); we have number of some chance to
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 123-of-199
change the given value of i/p by eresing the previously given i/p , but the getche(); commands has the variety in it as soon we enter a value in it then its will save (stored) in it; ___________________________________ Q) write a program which ask by the user any sentence then its give the total amount of character in that sentance ? SOURCE-CODE: #include<(stdio.h)> #include<(conio.h)> void main(void) { clrscr(); int count=0; printf("type a sentance \n"); while(getche() != '\r') /* test-expression */ { count++; }printf("this sentence have %d character",count); getch(); } OUT-PUT: Type a sentance
Page 124-of-199
Cat this sentance have 3 character ____________________________________ WHILE-LOOP: UN-EXCEPTED-CONDITION: SOURCE-CODE: void main(void) { int sik=0; printf("Type any thing:\n"); while(getche() != '\r' ) { sik++; }printf("\n character count is %d ", sik); }getch(); } OUT-PUT: Type any thing: 1,2,3,4,5,6,7,8,9 Type any thing: character count is 9
Page 125-of-199
Q) SOURCE-CODE: #include<(stdio.h)> #include<(conio.h)> void main(void) { int count=0; int total=0; while(count<=10) { total=total+count; printf("count=%d,total=%d \n",count++,total); } getch(); } OUT-PUT: count=o,total=0 count=1,total=1 count=2,total=3 count=3,total=6 . . . count=9,total=45 ________________________________________ Q) Write a program that takes i/p from the user & prints a table of any number? used while-loop?
Page 126-of-199
solution: SOURCE-CODE: #include<(stdio.h)> #include<(conio.h)> void main(void) { int a,s=1; /*int a,s=1,k*/ printf("Enter any number:"); scanf("%d",& a); while(s<=15) { /* k=s*a; */ printf("\n %d*%d=%d",a,s,s*a); /* printf("\n %d*%d=%d",a,s++,k);*/ s++; /* its not necessary for another */ } getch(); } OUT-PUT: Enter any number:2 2*1=2 2*2=4 2*3=6 . . 2*15=30 __________________________________________ Q) Write a program that take a i/p from the user of any pharase(sentance) , & calculated the number of each character word which contained by the pharase ? used while-loop? solution:
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 127-of-199
SOURCE-CODE: #include<(stdio.h)> #include<(conio.h)> void main(void) { int count=0; /* initialization of loop-variable */ printf("type in a pharase:\n"); while(getche() != '\r' ) count++; /* this semicolon terminated loop */ printf("\n character count is %d ",count); getch(); } OUT-PUT: Type in a pharase: john character count is 4 _____________________________________ DIFFERENCE B/W scanf() & getche() is that the scanf() take character,integer, float , but --->getche() take only character as i/p; __________________________________________ _________ UN-EXPECTED-CONDITION:
SOURCE-CODE:
#include<(stdio.h)>
Page 128-of-199
#include<(conio.h)>
void main(void)
{ char ch;
while(ch != '\r' )
{ char ch;
ch=getche();
} getch();
Page 129-of-199
OUT-PUT:
Enter a character:
the code of A is 65
Enter a character:
_____________________________________ Q) Write a program that ask a sentance from the user & tells no of character which contains in sentance?
SOURCE-CODE:
#include<(stdio.h)>
Page 130-of-199
#include<(conio.h)>
void main(void)
printf("Write a sentance:\n");
while(getche() != '\r' )
{ count++;
getch();
OUT-PUT:
Page 131-of-199
Write a sentance:
CAT
__________________________________________ _ Q) Write a program that ask a character from the user & tells whether the character is true or not? used Nested while-loop?
solution:
SOURCE-CODE:
#include<(stdio.h)>
#include<(conio.h)>
Page 132-of-199
void main(void)
for(s=1;s<3;s++)
printf("\n");
while((ch=getche()) != 'd')
Page 133-of-199
printf("\n Game-Over");
getch();
OUT-PUT:
Try again
Page 134-of-199
Try again
Try again
Page 135-of-199
Game Over
______________________________________ Q) Write a program which takes any number from user & display its factorial, using while-loop?
solution:
SOURCE-CODE:
#include<(stdio.h)>
#include<(conio.h)>
void main(void)
scanf("%d",& i);
while(i>0)
{ k=k*i--;
getch();
OUT-PUT:
Page 137-of-199
factorial of 3 is 6
______________________________
Q) Write a program which takes more then 1 number (about 5-times) from user, & display each of this Number factorial ? using Nested-while-loop?
solution:
SOURCE-CODE:
#include<(stdio.h)>
#include<(conio.h)>
void main(void)
Page 138-of-199
{ int s,i,k,a;s=0;
while(s<5)
scanf("%d",& i);
k=1;a=i;
while(i>0)
{ k=k*i--;
s++;
Page 139-of-199
getch();
OUT-PUT:
____________________________-
Page 140-of-199
Q) Write a program that tells how many character b\w 2 character's untill user exits? SOURCE-CODE;
#include<(stdio.h)>
#include<(conio.h)>
void main(void)
{ char ch1,ch2;
while(ch1 != '\r' ) { printf("Type 1th character:\n"); ch1=getche(); printf("\n Type 2th character:\n"); ch2=getche(); printf("\n there are %d character b\w both character.", (ch2-ch1)-1); }
Page 141-of-199
getch(); } OUT-PUT: Type 1th character: a Type 2th character: b there are 0 character b\w both character. __________________________________________ ______
DO-WHILE-LOOP-(CLASS-1)
-->Above
__________________________________________ __________
Page 142-of-199
Q) Write a program which take a character from the user & tell what ever its true or not used "do-while-loop"?
solution:
SOURCE-CODE: #include<(stdio.h)> #include<(conio.h)> void main(void) {char ch; do { printf("\n\n Type in a character from 'a' to 'e' :\n"); while((ch=getche()) != 'c') { printf("\n sorry, %c is incorrect. \n ",ch); printf("Try again.\n"); }
Page 143-of-199
printf("\n That is it! \n"); printf("\n play-again? (Type 'y') or to exist (Type 'c'):\n"); } while(getche() == 'y'); printf("\n Thanks for playing!\n"); getch(); }
OUT-PUT: Type in a character from 'a' to 'e': b sorry,b is incorrect. Try again. c That is it! play again?(Type 'y') or to exist(Type 'n'): y
Page 144-of-199
Type in a character from 'a' to 'e': d sorry, d is incorrect. Try again. c That is it! play again?(type 'y') or to exist (Type 'n'): n Thanks for playing! __________________________________________ ___ Q)
SOURCE-CODE:
Page 145-of-199
{ clrscr(); char ch1,ch2; while(ch1 != '\r') { printf("\n Type 1st character:\n"); ch1=getche(); printf("\n Type 2th character:\n"); ch2=getche(); printf("\n The ASCII-code of ch1=%c is %d",ch1,ch1); printf("\n The ASCII-code of ch2=%c is %d",ch2,ch2); printf("\n There are %d character b/w both character",(ch2-ch1)-1); } getch(); } OUT-PUT: Type 1st character: a Type 2th character: b The ASCII-code of ch1=a is 24930 The ASCII-code of ch2=b is 24930 There are 0 character b/w both character __________________________________________ _
Sunday, May 3, 2009
(CLASS-1)-DECISIONS:(IF & ELES-STATEMENTS):
DECISIONS:
Page 146-of-199
--->The structure of If-statements is approximately simillar to while-statement,but function of both statements are different with each other, the difference in b/w both if-statements & whilestatements are as following; (i-e) 1.)--->In while-statements, the body will be executed again & again untill the condition in while-loop test-expression become's false; 2.)---->On the other hand , If-statement,in the Ifstatements, the body will be executed only at once because its does not have increment-expression; ____________________________________ Q) SOURCE-CODE: void main(void)
Page 147-of-199
{char ch; printf("\n Type "y" for executed:\n"); ch=getche(); if(ch=='y') {printf("\n you typed y."); } getch(); }
-------------------STRUCTURE-OF-IF-STATEMENT:Fig # 24
Page 148-of-199
OPERATION OF IF-STATEMENT:FIG # 25
Page 149-of-199
---WORD-COUNTING PROGRAM:EXAMPLE:Write a program that not count only the number of character but it also counted the number of word which lie in the pharase typed by user? It takes input a pharase by user and count number of character and word containing in the pharase ? Used if statement? SOURCE CODE:
Page 150-of-199
#include<stdio.h> #include<conio.h> void main(void) { int countchar=0; int countword=0; char cha; printf(Type a pharase below: \n); while(cha=getche() != \r ) {countchar++; if(cha== ) /* (cha== ) = does ch is equal to space */ { countword++; } } printf(\n character count is %d,countchar); printf(\n word count is %d,countword+1); getch(); } OUT-PUT:
Page 151-of-199
Type a pharase below: Cat and dog Character count is 11 Word count is 3 ------------In the above example we know that how this example can calculated the number of character is presentin the given word , but , how it calculated the number of word in a pharase so, assume that it calculated the number of word in a pharase by calculated the space between the each word in the pharase and we assume that we added (* one more space in this pharase at the starting point of the pharase so, it calculated word in the pharase by calculating the space between each word and also adding one space at the starting point of the pharase that is [ Cat and dogs ] ---------------finished----------MULTIPLE-STATEMENT-WITH IF-STATEMENT:We can write single statement in the body of if-statement by terminated it by semicolon, we also used multiple statement with in the body of if-statement by using the braces [ {} ] to enclosed the compound statements in the body of the loop that is :
Page 152-of-199
Example-2: #include<stdio.h> #include<conio.h> void main(void) {char ch; printf(Enter any character :\n ); ch=getche(); if(ch==y) { printf(\n youtyped y. ); printf(\n Not some other latter. ); } getch(); } OUT-PUT: Enter any character: Y You Typed y. Not some other latter.
Page 153-of-199
-----------finished-------The above example #2 will also be written in this way that is void main(void) { char ch; printf(enter any character:\n); if(getche()==y) {printf(\n you typed y. ); printf(\n Not some other latter.); } getch(); } OUTPUT: ------------FINISHED-------Nested If-Statement: #include<stdio.h> #include<conio.h> void main(void) { clrscr();
Page 154-of-199
printf(Type any pharase to exit or type no to executed it: ); if(getche()== n ) { if(getche()== o ) { printf(\n you type no. ); } } getch(); } OUT-PUT: Type any pharase to exit or type no and no to executed it: no You type no -----------finished---------STRUCTURE OF NESTED IF-STATEMENT:Fig # 26
Page 155-of-199
----------finished---------If-Else Statement:THE IF-ELSE-STATEMENT: As we see in the single if-statement, so a single if-statement will executed a single statement of a compound [ group] statements with in the body of single if-statement, But , if-statement do not do nothing when Test-expression will be become false. ,
Page 156-of-199
There is any possibility by which we can execute a group of statement if when Test-Expressionin the if-statement expression is not true? Yes, there is a possibility by which we can executed a group of statements. That is Else-statements: We formed if-else statement to combine both together . EXAMPLE-OF-IF-ELES STATEMENT:void main(void) { char ch; printf(Type a character : \n ); ch=getche(); if(ch== y ) { printf(\n you typed y.); } else { printf(\n you did not typed y. ); }getch(); }
Page 157-of-199
OUT-PUT:Type a character: y You typed y. Type a character: n you did not types y --------------------finished----------OPERATION-OF-IF-ELES-STATEMENT:Fig # 27
Page 158-of-199
Fig # 28
Page 159-of-199
---finished---Q write a program which draw following out put in fig # 29? Fig # 29
Page 160-of-199
SOURCE CODE: #include<stdio.h> #include<conio.h> void main(void) { int x,y; for(y=1;y<9;y++) { for(x=1;x<9;x++) {if(x==y)
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 161-of-199
printf(\xDB);} else {printf(\xBO); } printf(\n); getch(); } -----------FINISHED-HERE------------CHARACTER GRAPHICS AND THE CHECKER BOARD Q write a program which shows a checker bord on monochrome screen , used if-eles statement? #include<stdio.h> #include<conio.h> void main(void) {int x,y; for(y=1;y<=10;y++) /* stepping down*/ { for(x=1;x<=10;x++) /*stepping across*/ { if((x+y)%2==0) {printf(\xDB\xDB); }else {printf( ); /* two space character */
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 162-of-199
---------finished---Q
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 163-of-199
void main(void) {int x,y; for(y=1;y<9;y++) /*stepping down along y-axis*/ { for(x=1;x<9;x++)/* steping across along x-axis*/ { if((x+y)%2 !=0) /*print odd number*/ {printf(\xDB\xDB); }else {printf( ); } }printf(\n); } getch(); } OUTPUT: FIG # 31 AND 32
Page 164-of-199
Page 165-of-199
------------finished---------DRAW TWO DIAGONAL :SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { int x,y; for(y=0;y<=24;y++)
Page 166-of-199
{ for(x=0;x<=24;x++) { if(x==y) {printf(\xDB); }else {printf(\xBO); } }printf(\n); } for(y=24;y>=0;y--) { for(x=1;x<=24;x++) { if(x==y) {printf(\xDB); }else {printf(\xBO); } }printf(\n); } }
Page 167-of-199
Fig # 33
We get two diagonal like in fig # 33 like a cross shape. -----------finished-------OPERATION-OF-NESTED IF-ELSE STATEMENT:Fig # 35
Page 168-of-199
------------finished---WHICH IF GETS THE ELSE:SOURCE-CODE: #include<stdio.h> #include<conio.h> void main(void) { int temp; printf(Please type temp:);
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 169-of-199
scanf(%d,&temp); if(temp<80) { if(temp>60) { printf(nice day!); } } else printf(sure is hot); getch(); } OUT-PUT: please type temp: 32 sure is hot please type temp: 84 ------------finished--------#include<stdio.h>
Page 170-of-199
#include<conio.h> void main(void) {int temp; printf(please type in temp:); scanf(%d,&temp); if(temp<80) if(temp>60) printf(\n Nice day!); else printf(sure is shilly!); elsef(sure is hot!); getch(); } OUTPUT: Please type in temperature:62 Nice day! -----------finished---------------#include<stdio.h>
Page 171-of-199
#include<conio.h> void main(void) { int temp; printf(type in temp:\n); scanf(%d),&temp); if(temp<80) { if(temp>60) printf(nice day! ); } else printf(sure is hot); getch(); } OUT-PUT: type in temp: 82 sure is hot -------------finished-----
Page 172-of-199
Q ) SOURCE CODE: #include<stdio.h> #include<conio.h> void main(void) {int x,y; for(y=1;y<24;y++) {for(x=1;x<24;x++) {if(x==y || x==24-y) {printf(\xDB); } Else {printf(\xBO); } } printf(\n); }getch(); } OUT-PUT: Fig # 36
Page 173-of-199
----------finished-----------Q) write a program which counts character and numerical digits in a pharases which taken as a input by the user? Used if-else statement? SOURCE-CODE: Void main(void) /* you must know where I am making mistake now */ { intchar count=0;
Page 174-of-199
Int digitcount=0; Char ch; Printf(type a pharase:\n); While((ch=getche())!= \r ) /* \r => Enter */ {charcount++; If(ch>47 && ch<58 ) { digitcount++; } }printf(\n character count is %d.,charcount); Printf(\n digit count is %d, digitcount); Getch(); } OUT-PUT: Type a pharase: He got 65 marks out off 100 marks. Character count is 34. Digit count is 5. ------------finished--------
Page 175-of-199
ELSE-IF STATEMENT:Q write a program [a calculator] which performed four function calculation? SOLUTION:SOURCE-CODE:#include<stdio.h> #include<conio.h> void main(void) {float num1=1.0,num2=1.0; char op; while( !(num1==0.0 && num2==0.0)) {printf(Type number,operator,number\n); scanf(%f,%c,%f,&num1,&op,&num2); if(op== +) printf(\n num1+num2=%f,num1+num2); else if(op== -) printf(\n =%f,num1-num2); else
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 176-of-199
if(op== * ) printf(\n =%f,num1*num2); else if(op== / ) printf(\n =%f, num1/num2); printf(\n\n); } getch(); } OUT-PUT: Type number,operator,number 3+3 =6.000000 Type number,operator,number 1/3 =0.333333 Type number,operator,number 1000*1000
Page 177-of-199
=1000000.000000 -----------------finished-------NESTED WHILE-LOOP:Q) write a program which take a number by the user and print its factorial and it will be executed by when the user press any key ? used nested while loop? SOURCE-CODE:#include<stdio.h> #include<conio.h> void main(void) { int I,k=1;charch; While(ch!= b ) {printf(Enter a number or a character : ); Scanf(%d,%c,&I,&ch); While(i !=0 ||ch!=b) {k=k*i--;
Page 178-of-199
} ------------finished-----------BREAK-STATEMENT: SOURCE-CODE: /* nested while loop*/ void main(void) {int I,k=1; char ch; While(ch!= b) {printf(Enter a number); Scanf(%d,&i); While(i!=0) { k=k*i--; }printf(factorial is %d,k); Printf(Typed a b to exist or any other latter to contineou: ); Ch=getche(); }printf( Game-Over); Getch(); }
Page 179-of-199
---------finished----------#include<stdio.h> #include<conio.h> void twobeep(void); void main(void) { twobeep(); printf(Enter a character :); getche(); /* wait for key press*/ twobeep(); getch(); }void two beep(void) {long j; printf(\x7);/*beep*/ for(j=1;j<=10000;j++) printf(\x7); } ----------finished------
Page 180-of-199
CH-5 [FUNCTIONS]: NOTE: some percent theory on function from ch-5 are here. SIMPLE-FUNCTION: #include<stdio.h> #include<conio.h> #include<dos.h> Void line(void); /* function prototype*/ Void main(void) /* main Function */ { Line(); /*call to function*/ Printf(\xDB TiTUS ANDRONICUS \x DB \n); Line(); /*call to function*/ delay(50); /* delay for time interval */ getch(); } Void line(void)/* no semi-colon here , Tc-cause , definition*/ { intj; For(j=1;j<=20;j++)
Page 181-of-199
{ printf(\xDB); Printf(\n); } -------------The main function is always executed first if either we placed other function that is [ void line(void)] before the main() function, but main() function is always executed first In this example the [ main()] function calls the function line(). { calls mean the Tc-cause to be executed} to draw the two lines of box , main (); Calls line() function twice times. There are only three program element which involved for using a function . thatis 1. Function Prototype [ Function Declaration]:2. Calling the function /* to executes a function*/ . 3. The Function Definition /* its function itself*/ 1) FUNCTION PROTOTYPE [FUNCTION DECLARATIONS]:We know that we used in our example line() function we know that the main() function al always executed at first if when ever we placed line() function before or after the main() function.
Page 182-of-199
E.g Fig # 39
This function prototype lies before the beginning of main() function. WHAT IS THE PURPOSE OF FUNCTION PROTOTYPE:{:. you have already seen many examples of variable in c programs. That all the variable were defined by name character and data type integer before they were used }
Page 183-of-199
The line() function in our example is declared in a similar way at the beginning of a program that is void line(void); before its called for execute. WORKING-OF-FUNCTION DECLARATION:Fig # 40
The function declaration tells compiler the name of the function that is line(), the data type of the function returns [ if any] and the number and data types of the functions takes arguments [ if any ] ,
Page 184-of-199
fig # 41
Notice that the prototype is written before the main() function this action cause the prototype function will be visible to all the functions in a file. (in the source code). A prototype declares a function A function all executes a function A function definition is the function itself. SOUND EXAMPLE:
Page 185-of-199
#include<stdio.h> #include<conio.h> void twobeep(void); void main(void) {two beep(); printf(Type any character: ); getche(); twobeep(); getch(); } void twobeep(void) {long j; printf(\x7); for(j=1;j<=100000;j++) printf(\x7); } ------------FINISHED-------FUNCTION:
Page 186-of-199
WHAT DO FUNCTION DO :The function can used to avoid to hide the same repetition of code again and again in the same program. Q) write a program in which put box around the text . ? SOURCE-CODE: #include<stdio.h> #include<conio.h> void line(void); /* prototype for line()*/ void main(void)/*main function*/ { line(); /* call to function */ printf(\xDB titus Androicus \xDB \n); line(); getch(); } /* function definition*/ void line(void)/*function declaration*/ { int s;
for(s=1;s<=20;s++) {printf(\xDB);
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 187-of-199
Q) write a program which performed two beepseperately by a short interval? SOURCE-CODE: /* \x7 is the ASCII code for Bell */ Void two beep(void); Void main(void) {twobeep(); /* function calling */ Printf(Type a character : ); Getche(); /* wait for key press*/ Twobeep(); /*function call*/ Getch(); }void twobeep(void)} {long j; /* long is integer */ Printf (\x7); /*1st beep*/ For(j=1;j<10000;j++) /* delay*/ ; /* null statement*/
Printf(\x7);/*2nd beep */
Page 189-of-199
OUTPUT two beep by short interval, -----------FINISHED----Q write a program that prints the following output uned function? Diagram:Fig # 43
Page 190-of-199
SOURCE-CODE: #include<stdio.h> #include<conio.h> Void line(void); Void main(void) { line(); Printf(\n Bio-medical\n); Line(); getch(); } /* Function definition is given below*/ Void line(void) /*function declaration*/ { int j; For(j=1;j<=20;j++) {printf(\xDB); } } ----------finished---------
Page 191-of-199
Q) write a program that prints the following output? Using function? Given diagram:- fig # 44
Page 192-of-199
{lineo(); /*function calling*/ Printf(\n \xDB Bio-Medical \xDB\n); Lineo();/*function calling */ Getch90; } /* function definition is given below */ Void lineo(void) {int s; For(s=1;s<=20;s++) {printf(\xDB);} } ------------finished----------FUNCTION THAT RETURNS A VALUE: In this case , in which the function that returns a value , the general theam of this is that , . In this type of function when you call ,when the function calling is similar to that when a person whose want to examine the time by the telephone , so, he first diale a number , that is PH# No : XXXX-XXX, then on other side the computer [ or a person] whose are assigning for that job
Page 193-of-199
to tell you the exact time then , so that computer tell you that time with out taking any information from you that , In this similarly way as we just analysis [look] the given below function examples as when the void main(void) [ main(); ] function will be executed always 1st then it cause to executed the calling function [ call to function] .when this [call to function ] will be executed then it cause to executed the [ function definition] which is already itself function , When call to function call the function definition then this function definition contains a certain peace of information which will be process, [mathematically or some other method] , then this result of that transfer will be returned to where the function will called at Call to the function. EXAMPLE: char small letter (void); void main(void) {char ch; Printf(Enter any a capacital letter: ); Ch=smallletter(); /* cal to function*/ Printf(\n in small letter its %c ,ch); Getch(); }
Page 194-of-199
Char small letter (void) {char a,b; a=getche(); b=a+32; /*(a+32) makes a capital letter into a small letter*/ return(b);/*its the return operator like delay(50);*/ } OUT-PUT: Enter any a capital letter:A In small letter its a . --------finished--Q write a program that converted any capital letter which will be taken from the input by user into its smallletter? SOURCE-CODE#include<stdio.h> #include<conio.h> Char small letter(void); Void main (void) {char ch; Printf(Enter any a capital letter:\n ); Ch=smallletter90; Printf(\n In smallletter its %c .,ch); Getch(); }
Page 195-of-199
char smallletter(void) {char a,b; a=getche(); b=a+32; /* (a+32) this form makes capital letter into small letter */ return(b); } OUT-PUT: Enter any a capital letter: B In small letter its b. ------------finished--------{:. If we add 32 in any upper case letter ,so its converted into its lower case?} Q) write a program that convert any small leter which will be taken from user as a input and converted it into Capital-letter? SOURCE-CODE: #include<stdio.h> #include<conio.h> Char smallletter(void);/*prototype*/ Void main(void) {char ch; Printf(Enter any small letter : \n ); Ch=smallletter(); /*call to function */
Page 196-of-199
printf(\n in capital letter is %c .,ch); getch(); } Char smallletter(void) {char a,b; a=getche(); b=a-32; /* (a-32) this make any lower case letter into the upper case leter or it converted any small letter into capital letter*/ return(b); } OUT-PUT Enter any smallletter: a in capitalletter is A . ------finished-----------Q write a program which takes some numerical value by the user and calculated and give its calculated value in output:? SOURCE-CODE: #include<stdio.h>
Page 197-of-199
#include<conio.h> Void calculator(int,char,int); Void main(void) { int num1,num2; char op; Printf(Enter:1st number , operator, 2nd number : ); Scanf(%d,%c,%d,&num1,&op,&num2); Calculator(num1,op,num2); Getch(); } Void calculator(int x,char op,int y) {switch(op) { Case +: Printf(\n sum is =%d, x+y); Break; Case -: Printf(sum is =%d,x-y); break;
Page 198-of-199
case *: printf(product is = %d,x*y); break; case / : printf( division is =%d,x/y); break; default: printf(Unknown operator : ); }} OUT-PUT: Enter: 1st number,operator,2nd Number of your choice : 2+3 Sum is = 5 ------------finished-------FUNCTION THAT ACCEPT VALUE:The any function at accept and as well as return value is called a function that accept and returns value Fig # 45
Page 199-of-199
Example: Int greater(int,int); Void main(void) { int num1,num2,num3; Printf(Enter 1st and 2nd value : ); Scanf(%d,%d,&num1,&nem2); If(num1==num2) {printf(Both are equal);
[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 200-of-199
}else {num3=greater(num1,num2); /* in above the part in yellow is return and the part in light green are accepted*/ Printf(Greater away line is %d,num3); Getch(); } Int greater(int a,int b) { If(a>b) {return (a); } Else {return(b); } } -----------finished-----------------ch1 to ch-5 in c-language , on bio-medical engineering Finished-here----------[BIO-MEDICAL-ENGINEERING GUIDE.INC BY SIKANDAR LODHI] Page 201-of-199
X
MUHAMMAD-SIKANDAR-KHAN-LODHI OWNER OF MY PERSONAL UNIVERSITY NOTES.
Page 202-of-199