You are on page 1of 78

Language: The way of communication between computer and user known as language.

Program: The set of instruction arrange in a sequence to solve a problem known as program.

Software: The group of programs is known as software.

Programming Language: All the languages were we can design our program is known as programming language.

History of C language The C language developed in 1972 by Dennis Ritchie in AT & T Bell labs, USA. It is developed by B language to reduce its problem.

Features of C language 1. Middle Level Language: The C language is a combination of high level and low level programming. The languages where program design using 0 and 1 symbols known as low level languages. The languages where we have general English words in our program is known as high level languages. 2. Modular Programming The C language provides permission to design a complete program by dividing them in multiple parts. These parts known as module. Example: The program of calculator design using four parts or modules i.e. Addition, Subtraction, Multiply and Divide. 3. Procedural Programming

In the C language a complete program design using the multiple steps and we have to provide complete logic from top to bottom of program. 4. Case Sensitive In the C language all the instructions design in small letters that means C language is a case sensitive. 5. C provide feature to design system software. Example: UNIX operating system. 6. User Friendly It is a user friendly language because it is easy to use, understand and learn.

Elements of Program When we design a program is C language we have to use some elements the elements are follows:1. #include It is known as Pre- Possessive Directive it forms as a connector to connect pre- define instruction with our program. 2. <Header file.h> The collection of instructions available in a file known as header file. It is available in the library of C identifies by (.h). 3. Main() In our program we have lots of instructions and we have to execute them in a sequence this task can be performing by main function. The function started by {opening bracket and closed by closing bracket}. 4. In the C language every instruction or line enclosed by (;) semi colon. It represent end of statement. Working steps of program When we design a program in C we have to follow some steps from starting to the result. Design a program in C language identified by (.C). (.C) program translate into machine code by a translator known as compiler. Using ALT+ F9 key. Now the machine code must be execute using the CTRL+F9 key and then we have a result.

Diagram of working steps of a C program

program.c

compile (ALT+F9)

program.obj

Run (CTRL+F9)

program.exe

Output Function (Printf) The printf is a output function it is utilize to print our data on the output screen. The printf function is available in the stdio.h header file. Syntax: printf("Enter your message here); \n (New line character) To transfer the cursor at the new line C provides a special character known as \n. It perform with printf and transfer cursor at new line. Example:

#include<stdio.h> main() { printf("Hello \n World");

#include<stdio.h> main() { printf("Hello\n"); printf("World");

Hello World

C Tokens When we design a program we have to use some pre- define instruction that can help to develop a complete program. The smallest unit of program that are utilize to design our programs known as tokens.

Tokens

Keywords (main, #include)

Datatypes (int, float)

Operators (+,-,/,*)

Variables

Constant

Expression

1. Keywords All the pre define words in the library of C that are directly utilize in our program we need not to define their explanation known as keywords. Example: Main, include, int, float, if, switch, for, while, do etc. Note: There are 32 keywords in C library. 2. Datatypes If we have a program then we have to use various types of data in it. Basically we have 3 basic representation of data these are Integer numbers (2,5,32,-45 etc), Floating numbers (1.2, 56.32 etc) and Characters (a,c,v etc). So we have to define some basic explanation for the every data before utilization the programming elements or symbol which are utilize to explain the nature of data known as datatype. A data type provide three basic explanation for every data. i. What is the nature of data? ii. What is the minimum and maximum capacity of data? iii. How many size require by data? Name Integer Float Character Keywords Int Float Char Size 2 Byte 4 Byte 1 Byte Identifier %d %f %c Memory Limit -32768 to 32767 0 to 128

3. Constant The programming elements whos value decided at design time is known as constants. They have values which is previously decided. Syntax: datatype constant_name= value; Example: int a=10; Float b=10.25; Rules: i. They cannot declared similar name constant in our program. ii. The dissimilar members represents in seprate line but similar member represent in a single line seprate by (,). Example: int a=5,b=20;

Q- Write a program to find out the square of a constant? #include<stdio.h> Main() { Int a=2, b=0; B=a*a; Printf(Square=%d,b); } Q- Write a program to find out the multiply of 3 numbers? #include<stdio.h> Main() { Int a=1, b=2, c=3, d=0; D=a*b*c; Printf(Answer=%d,d); } 4. Variable The programming element whos value decided at the rum time of program by user known as variable. Input Function (Scanf) To accept the value at rum time by user we have scanf function. The function required name of variable with its address the address identify by & sign and scanf also required name of variable where we want to insert value. Syntax: scanf(identifier,&variable_name); Example: scanf(%d,&a); Q- Input two number by user and find out sum? #include<stdio.h> Main() { Int a,b,sum=0;

Printf(Enter the numbers); Scanf(%d%d,&a,&b); Sum=a+b; Printf(Sum=%d,sum); } Q- Take input from user quantity and price and then print amount? #include<stdio.h> Main() { Int quantity,prize,amount=0; Printf(Enter the quantity); Scanf(%d,&quantity); Printf(Enter the prize); Scanf(%d,&prize); Amount=quantity*prize; Printf(Amount=%d,amount); }

Q- Design a program to input marks in hindi, English and maths by user and find out sum and average? #include<stdio.h> #include<conio.h> Main() { Int h,e,m,sum,avg; Clrscr(); Printf(Enter the marks); Scanf(%d%d%d,&h,&e,&m); Sum=h+e+m;

Avg=sum/3; Printf(Sum=%d\nAvg=%d,sum,avg); Getch(); }

Q- Input the salary by user find out the 10% bonus and total salary? #include<stdio.h> #include<conio.h> Main() { Int sal,bon,tot; Clrscr(); Printf(Enter the salary); Scanf(%d,&sal); Bon=sal*(10/100); Tot=sal+bon; Printf(Total=%d,tot); Getch(); }

Q- Input the prize of book by user find out 10% discount and then final amount? #include<stdio.h> #include<conio.h> Main() { Int pri,dis,tot; Clrscr(); Printf(Enter the prize);

Scanf(%d,&pri); Dis=pri*(10/100); Tot=pri-dis; Printf(Final Amount=%d,tot); Getch(); }

Operator The programming element or symbols that are utilize to connect the elements with each other is known as operator. The operators are symbols that define what is our operation on the data. The members where operator execute known as operants. Categories of operators According to execution According to the execution or run of a operator we can define three basic types:a) Uniary operator b) Binary operator c) Ternary operator 1. Uniary operator If operator execute using a single value then it is called uniary operator. Example: ++,-- etc. 2. Binary operator If the operator executes using two values then it is called as binary operator. Example: +, -, *, / etc 3. Ternary operator If the operator executes using three values then it is called ternary operator. Example: ?: etc According to nature Which type of value accepted by operator known its nature according to this concept the operator are:a) Air thematic operator b) Bitwise operator c) Relational operator d) Conditional operator e) Logical operator

1. Air thematic operator The operators that executes using the numbers or airthematic values known as Air thematic operator. Example: +, -, *, /, ++, -- etc Difference between + and ++ ++ Increment Increase value by one Uniary operator + Additon Add two numbers Binary operator

Increment operator The increment operator used to increase the value of an element by 1. It is a uniary operator and perform into two formats. a) Prefix If the operator declared before the elements these it is prefix. It have highest priority that means increase the value by 1 then perform other task. b) Postfix When operator assign after the variables then it is postfix. That means it have last priority we have to perform other tasks then increase the value by one. Decrement operator It is a uniary operator that can reduce the value of an element by one. It also available in two categories as a prefix and postfix. 2. Bitwise operator The operator that can executes using the binary data known as bitwise operator. Shift Left The shift left operator accept a number by user and convert it in binary and shift one by one bit at the left side after that we have a new answer in the binary format. Shift Right Like the shift left. It can also accept a number by user and design its binary and then shift a bit from right side. 3. Relational operator All the operators that are utilize two design a condition for the comparison known as relational operator. Symbols > < == >= Meaning Greater then Less then Exactly equal to Greater then equal to

<= !=

Less than equal to Not equals to

4. Conditional operator If we want to perform logical program then it is provided by conditional operator. The conditional operator accept a condition by user and its true or false part. The true and false part seprate by (:) colon. Syntax: Var=(condition)?true: false; Q- Write a program for finding maximum value in four number? #include<stdio.h> #include<conio.h> Main() { Int a, b, c, d, e, f, g; Clrscr(); Printf(Enter four number); Scanf(%d%d%d%d,&a,&b,&c,&d); E=(a>b)?a:b; F=(c>d)?c:d; G=(e>f)?e:f; Printf(Max is=%d,g); Getch(); }

5. Logical operator All the operators that return the answer in the true and false known as logical operators. The logical operators are utilize when we want to connect more than one conditions with each other. We have three representation of logical operators. AND (&&) The AND operator always return true if all the connected conditions are true. Condition one Condition two &&

True True False False

True False True False

True False False False

OR (||) The OR operator return true if all the conditions are true or any one condition is true. Condition one True True False False Condition two True False True False || True True True False

NOT (!) It does not connect more than one conditions. It is utilize to reverse the conditions. Condition ! True False False True Type casting The type casting is a concept or an a operator which is utilize to convert the nature of element in our program. The type casting provided facilities to find our the results of higher data type using the elements of lower data type. It is benefit because it provide memory advantages. In C language we have two representation for the type casting. 1. Implicit type casting The 1st representation of type casting where we need not to define about the nature of data known as implicit type casting. Example: #include<stdio.h> Main() { Int a=4,b; Float b; B=a/2; Printf(%d,b); } Output: 2.0 2. Explicit type casting The representation of type casting that provide permission to decided what is the new data type of result known as user define type cast. Example: #include<stdio.h>

Main() { Int a=5; Float b; B=(float)(a/2); Printf(%f,b); } In the following example we have a variable with integer datatype. Now convert the integer variable into the float at run time.

Control statement Switch case Goto label If else

1. Switch case The switch case is a first control statement. It provide facility to divide our program into multiple partitions. By using the switch case we can execute the particular module or part from our program which is divided by user. To use the switch we have to follow some keywords: Switch It is a controller that can execute the particular case which is required by user. The switch keyword accept name of case to execute. If the case is not available then transfer the cursor to the default. Case To design the partitions in our programs we have case keyword. Break To seprate the multiple case at run time we have break keyword. It exit the user from control statement. Default If we does not have any case to execute then default partition perform. Syntax: Switch(case_variable) { Case value: Statement; Break; Case value: Statement;

Break; Case value: Statement; Break; Default: Statement; }

Q- Write a program to input a number by user and print the message according to the condition? #include<stdio.h> #include<conio.h> Main() { Int ch; Clrscr(); Printf(Enter the choice); Scanf(%d,ch); Switch(ch) { Case 1: Printf(One); Break;

Case 2: Printf(Two); Break;

Case 3: Printf(Three);

Break;

Default: Printf(Invalid); } Getch(); } Disadvantages of switch case It does not provide permission to use the relational and logical operator. The name of case does not decided by user. We have a single default for the multiple cases.

2. Goto label It is a first concept where we can design a program with the multiple partitions to design the gote label we have some steps: Every partition have an identification known as label. To select the name of label for execution we have goto keyword.

Syntax: Label name: Statement; Lable name: Statement; Goto label_name; Disadvantage of Goto label It does not support relational and logical operators. The name of label with goto decided by programmer and not by the user. If user enter the name of label which is not available then we have an error in the program.

3. If else It is a 3rd control statement that provide facility to use every type of operators in our logic. The if else depends on keywords.

If The if keyword accept a condition and every condition have two answers either true or false after the if condition we always have true partition. Else The else always represent the partition which is execute when the condition is false.

Simple if If(condition) True; If(condition) True; Else False;

If else

Nested if -else If(condition) True; Else If(condition) True; Else False;

Q- write a program to input a number by user and findout the number is even or odd? #include<stdio.h> #include<conio.h> Main() { Int no; Clrscr(); Printf(Enter the Number to check); Scanf(%d,&no) If(no%2==0) Printf(Number is EVEN); Else Printf(Number is ODD); Getch(); }

Q- write a program to input marks of hindi, English and maths and findout the sum, average and print the grade? #include<stdio.h> #include<conio.h> Main() { Int h,e,m,sum=0,avg=0; Clrscr(); Printf(Enter the marks); Scanf(%d%d%d,&h,&e,&m); Sum=h+e+m; Avg=sum/3; If(avg>70) Printf(A Grade); Else Printf(B Grade); Getch(); }

Q- Write a program to input salary by user find out the total salary if salary is greater than 20,000 then bonus is 20% otherwise 10% ? #include<stdio.h> #include<conio.h> Main() { Int sal,tot,bon; Printf(Enter the salary); Scanf(%d,&sal);

If(sal>20000) Bon=sal*(20/100); Else Bon= sal*(10/100); Tot=sal+bon; Printf(Total Salary=%d,tot); Getch(); }

Q- Write a program to input salary by user if salary greater than 20,000 then bonus is 20% and pf is 10% otherwise bonus is 10% and pf is 5% ? #include<stdio.h> #include<conio.h> Main() { Int sal, tot, bon, pf; Clrscr(); Printf(Enter the salary); Scanf(%d,&sal); If(sal>20000) { bon=sal*(20/100); Pf=bon*(10/100); } Else { Bon=sal*(10/100); Pf=sal*(5/100);

} Tot=(sal+bon)-pf; Printf(Total Salary=%d,tot); Getch(); }

Q- Write a program to find out the maximum from 2 numbers? #include<stdio.h> #include<conio.h> Main() { Int a,b; Clrscr(); Printf(Enter the numbers); Scanf(%d%d,&a,&b); If(a>b) Printf(A is max); Else Printf(B is max); Getch(); }

If with logical operators

Q- Write the program to find out the maximum from 3 numbers? #include<stdio.h> #include<conio.h> Main()

{ Int a,b,c; Clrscr(); Printf(Enter the numbers); Scanf(%d%d%d,&a,&b,&c); If((a>b)&&(a>c)) Printf(A is max); Else If(b>c) Printf(B is max); Else Printf(C is max); Getch(); }

Q- Write a program to input time by user if the time is between 0 to 12 then print good morning otherwise good afternoon? #include<stdio.h> #include<conio.h> Main() { Int t; Clrscr(); Printf(Enter the time); Scanf(%d,&t); If((t>0)&&(t<12)) Printf(Good Morning); Else

Printf(Good Afternoon); Getch(); }

Q- Write a program to input marks of hindi, English and maths. Find out the average and print the grade according to the condition? 95-80=A Grade 80-65= B Grade 0-65= C Grade #include<stdio.h> #include<conio.h> Main() { Int h,e,m,avg; Clrscr(); Printf(Enter the marks); Scanf(%d%d%d,&h,&e,&m); Avg=(h+e+m)/3; If((avg>80)&&(avg<=95)) Printf(A Grade); Else If((avg>65)&&(avg<=80)) Printf(B Grade); Else Printf(C Grade); Getch(); }

Q- Write a program to input a number and check the number is even or odd and positive or negative? #include<stdio.h> #include<conio.h> Main() { Int no; Clrscr(); Printf(Enter the number); Scanf(%d,&no); If((no%2==0)&&(no>0)) Printf(Even, Positive); Else If((no%2==0)&&(no<0)) Printf(Even, Negative); Else If((no%2==1)&&(no>0)) Printf(Odd, Positive); Else printf(Odd, Negative); getch(); }

Decision making and looping If we have a program and we wants to repeat a single line multiple time than C language provide a concept known as looping. The looping provide permission to ignore the size of program. Every loop depends on three basic components: Counter variable It is the first variable for the loop which is utilize to decide how many times we have to repeat the statement and it is utilize to count the repetation.

Condition It is responsible to decide that we have to stop or run the loop. If the condition is true than we have to perform repetation otherwise stop the repetation. Increment or Decrement operator To modify the value of counter variable we have to use increment and decrement operators. They provide permission to update the value of the counter variable from starting to the ending.

Categories of looping (Types of looping)

Top tested loop It is the first caregory of loop where we have to check the condition at first priority and then perform other task.

Bottom tested (Post tested loop) It is another type of looping where the condition have last priority that means we can execute all the instructions than check condition. 1. FOR loop It is the first type of looping where we have to define three elements inside the for. The elements are a counter variable, a condition and increment or decrement. Syntax: For(counter_variable=value; condition; increment/Decrement) { Statement one; Statement two; }

2. WHILE loop It is second type of looping and it is top tested looping. It provide permission to represent all the element of a loop. In three basic steps. The while always represent a condition which we wants to execute. Syntax: Counter_variable= counter_value; While(condition) { Statement one; Statement two; Increment\\Decrement; }

3. DO WHILE loop The do while is a bottom tested loop that is utilize two important keywords. Do It always represent that we have some repetitive statements. While It represent the condition to run the loop.

Some examples of looping

Q- Write a program to print Hello message 10 times? FOR #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); For(i=1;i<=10;i++) { Printf(Hello\n); } Getch(); } WHILE #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); I=1; While(i<=10) { Printf(Hello\n); I++; } Getch(); } DO WHILE #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); I=1; do { Printf(Hello\n); I++; }while(i<10); Getch(); }

Q- Write a program to print the series from 1 to 10? FOR #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); For(i=1;i<=10;i++) { Printf(%d,i); } Getch(); } WHILE #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); I=1; While(i<=10) { Printf(%d,i); I++; } Getch(); } DO WHILE #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); I=1; do { Printf(%d,i); I++; }while(i<10); Getch(); }

Q- Write the program to print the series 10 to 1? FOR #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); For(i=10;i>=1;i--) { Printf(%d,i); } Getch(); } WHILE #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); I=10; While(i>=1) { Printf(%d,i); I--; } Getch(); } DO WHILE #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); I=10; do { Printf(%d,i); I--; }while(i>=1); Getch(); }

Q- Write a program to the series 1, 4, 9, 16, 25, 100 square of each? FOR #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); For(i=1;i<=10;i++) { Printf(%d,i*i); } Getch(); } WHILE #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); I=1; While(i<=10) { Printf(%d,i*i); I++; } Getch(); } DO WHILE #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); I=1; do { Printf(%d,i*i); I++; }while(i<=10); Getch(); }

Q- Write a program to print the series 100, 81, 64,? FOR #include<stdio.h> #include<conio.h> Main() { WHILE #include<stdio.h> #include<conio.h> Main() { DO WHILE #include<stdio.h> #include<conio.h> Main() {

Int i; Clrscr(); For(i=10;i>=1;i--) { Printf(%d,i*i); } Getch(); }

Int i; Clrscr(); I=10; While(i>=1) { Printf(%d,i*i); I--; } Getch(); }

Int i; Clrscr(); I=10; do { Printf(%d,i*i); I--; }while(i>=1); Getch(); }

Q- Write a program to print only even numbers from 1 to 10? FOR #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); For(i=1;i<=10;i++) { If(i%2==0) Printf(%d,i); } Getch(); } WHILE #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); I=1; While(i<=10) { If(i%2==0) Printf(%d,i); I++; } Getch(); } DO WHILE #include<stdio.h> #include<conio.h> Main() { Int i; Clrscr(); I=1; do { If(i%2==0) Printf(%d,i*i); I++; }while(i<=10); Getch(); }

Q- Write a program to print series -1, 2, -3, 4, -5? #include<stdio.h> #include<conio.h> Main() { Int I; Clrscr(); For(i=1;i<=10;i++) { If(i%2==0) Printf(%d,i); Else

Q- Write a program to print series 1, -2, 3, -4, 5? #include<stdio.h> #include<conio.h> Main() { Int I; Clrscr(); For(i=1;i<=10;i++) { If(i%2==0) Printf(%d,-i); Else

Printf(%d,-i); } } } }

Printf(%d,i);

Q- Write a program to print the series from 1 to N? (Where N is input by user) #include<stdio.h> #include<conio.h> Main() { Int i,n; Clrscr(); Printf(Enter the Number); Scanf(%d,&n); For(i=1;i<=n;i++) { Printf(%d,i); } Getch(); }

Q- Write a program to find out the sum from 1 to N numbers ? #include<stdio.h> #include<conio.h> Main() { Int i,n,sum=0; Clrscr(); Printf(Enter the Number);

Scanf(%d,&n); For(i=1;i<=n;i++) { Sum=sum+I; } Printf(Sum=%d,sum); Getch(); } Q- Write a program to input a number and find out its reverse? (Number=123, Number=321) #include<stdio.h> #include<conio.h> Main() { Int no,r; Clrscr(); Printf(Enter the Number); Scanf(%d,&no); While(no!=0) { R=no%10; No=no/10; Printf(Reverse=%d,r); } Getch(); }

Q- Write a program to input a number by user and find out its sum? (1521+5+2=8)

#include<stdio.h> #include<conio.h> Main() { Int no,r,sum=0; Clrscr(); Printf(Enter the Number); Scanf(%d,&no); While(no!=0) { R=no%10; No=no/10; Sum=sum+r; } Printf(Sum=%d,sum); Getch(); }

Armstong If we have an number with n digits and the sum of each digit with power n is always equals to number than it is called armstong.

Q- Write a program to input a number by user and find out is it armstong or not?

#include<stdio.h> #include<conio.h> Main()

{ Int no,r,a,sum=0; Clrscr(); Printf(Enter the Number); Scanf(%d,&no); A=no; While(no!=0) { R=no%10; No=no/10; Sum=sum+(r*r*r); } If(a==s) Printf(Number is Armstong); Else Printf(Number is not Armstong); Getch(); } Fibonacci series Sequence of numbers in which 1 appears twice as the first two numbers, and every subsequent number is the sum of two preceding numbers: 1, 1, 2, 3, 5, 8, 13 ... and so on.

Q- Write a program to design a febonacci series? #include<stdio.h> #include<conio.h> Main() { Int a=0,b=1,c,I;

Printf(%d%d,a,b); For(i=1;i<=10;i++) { C=a+b; Printf(%d,c); A=b; B=c; } Getch(); }

Debugging If we have a program with set of statements than program may be provide incorrect result these are known as errors. All the illegal statements or representation in our program that cannot execute the program and provide incorrect result known as bugg or error. And the method to remove these errors known as debugging. The errors are divided in three categories: Syntax error Logical errors Runtime errors

1. Syntax errors If we does not use the complete grammer and syntax of statement that it is a syntax error. The syntax errors find out by compiler and program does not executes successfully. Example: Printf(Hello) semi colon missing 2. Logical errors If our program successfully compile by compiler and we have a final result but the result does not match according to our requirement than it is called logical error. The logical errors does not identify by compiler it is understand by user by the answer. Example: We have to find out the sum of two numbers but the result shows subtraction of two number. 3. Runtime errors

All the types of errors that are not identify by compiler or user known as unknown errors or runtime errors. In these types of error the program terminate from runtime without any description. Example: The divide by 0 Data in the variable out of the limitation of data types.

Nested looping (Branching) The loop inside another loop known as nested looping. Syntax: For(counter_variable=counter_value; condition; Inc//dec) { For(counter_variable=counter_value; condition; Inc//dec) { For(counter_variable=counter_value; condition; Inc//dec) { } } }

Q-Write a program to print numbers as follows? 1 12 123 1234 #include<stdio.h> Main() { Int I,j; For(i=1;i<=4;i++) { For(j=1;j<=I;j++)

{ Printf(%d,j); } Printf(\n); } }

Program Documentation If we have a software or program for the development then we have to perform some squencial steps to create the complete program or software. It will be possible if we have some steps which are known as documentation life cycle. 1. Requirement analysis It is the first step where we accept the requirement from user if the requirement is valid then check the environment of program and decide the software desiging is possible or not. If it is possible then discuss the next step. 2. Feasibility (Possibility) In this step we have to analysis the possibility of software for that we have three points: We have to know about the financial position of software that is financially possible or not. If the financially possible then confirm that we have all the technical components and logic or not. If we have technical resources then we have to decide about the operational staff. If staff is not available then it is not possible.

3. Input/Output design Finally when we have to design the software we have to decide the designing of input/output screen. 4. Coding After the complete designing we have to write program or logic for every input and output. 5. Testing After complete set of coding we have to confirm that our code is correct or not. It is possible with the help of testing. 6. Output After complete successful testing we can show our program for the customer.

Array A variable can store single value at a time to store multiple values we have to create multiple variables. Every variable have its separate memory address so when we search the variables we have to waste out time this problem can be solved using the concept of array. The continue memory allocation of same type data identified by a common name known as array. They provide permission to store multiple data in the continue memory and we need not to waste out time during working on it. All the datas identify by a common name but separate according to the index. Types of array Single array (one dimensional array) Two dimensional array Multi- dimensional array

1. Single array (one dimensional array) The continue memory allocation of the same type data in the format of row or column known as single array. Syntax: Datatype array_name[size]

Rules to create a single array To design a single array in the program we have to define data type with the name and size of array. Every data have common name but seprated using indexs. from 0 to n-1 where n= size. To perform any task on the array we have to use name of array with its index.

Constant array Q- Write a program to create a constant array and then print its data? Constant array without looping #include<stdio.h> Main() { Int a[3]= {10,25,50}; Printf(%d,a*0+); Printf(%d,a*1+); Printf(%d,a*2+); } Constant array with looping #include<stdio.h> Main() { Int a[3]= {10,25,50},I; For(i=0;i<3;i++) { Printf(%d,a*i+); } } Array in memory A 10 25 50

Get data in array by user Q- Write a program to input an array then print its data?

#include<stdio.h> Main() { Int a[10],I; For(i=0;i<5;i++) { Printf(Enter the data in array); Scanf(%d,&a*i+); } For(i=0;i<5;i++) { Printf(%d,a*i+); } }

Q- Write a program to input N elements in the array then print it? #include<stdio.h> Main() { Int a[10],I,n; Printf(Enter the size of array); Scanf(%d,&n); For(i=0;i<n;i++) { Printf(Enter the data in array); Scanf(%d,&a*i+); } For(i=0;i<n;i++)

{ Printf(%d,a*i+); } }

Disadvantages of array When we use an array we have a disadvantage that if we does not use the complete size of data or memory which we declare then it is memory wastage. Q- Write a program to input N elements in the array and print in reverse order? #include<stdio.h> Main() { Int a[10],I,totno; Printf(Enter the size of array); Scanf(%d,&totno); For(i=0;i<totno;i++) { Printf(Enter the data in array); Scanf(%d,&a*i+); } For(i=totno-1;i>=0;i--) { Printf(%d,a*i+); } }

Q- Write a program to input N element in the array and find out its sum? #include<stdio.h>

Main() { Int a[10],I,totno,sum=0; Printf(Enter the size of array); Scanf(%d,&totno); For(i=0;i<totno;i++) { Printf(Enter the data in array); Scanf(%d,&a*i+); } For(i=totno-1;i>=0;i--) { Sum=sum+a[i]; } Printf(Sum=%d,sum); }

Q- Write a program to input N element in the array and find out maximum number from it? #include<stdio.h> Main() { Int a[10],I,totno,m=-32768; Printf(Enter the size of array); Scanf(%d,&totno); For(i=0;i<totno;i++) { Printf(Enter the data in array); Scanf(%d,&a*i+);

} For(i=0;i<totno;i++) { If(a[i]>m) M=a[i]; } Printf(Max=%d,m); }

Q- Write a program to input N numbers by user then find out the maximum and its position in array? #include<stdio.h> Main() { Int a[10],I,totno,m=-32768,p=0; Printf(Enter the size of array); Scanf(%d,&totno); For(i=0;i<totno;i++) { Printf(Enter the data in array); Scanf(%d,&a*i+); } For(i=0;i<totno;i++) { If(a[i]>m) { M=a[i]; P=i+1; }

} Printf(Max=%d,m); Printf(Position=%d,p); }

Q- Write a program to input N number in array then find out the maximum and its repetation? #include<stdio.h> Main() { Int a[10],I,totno,m=-32768,count=0; Printf(Enter the size of array); Scanf(%d,&totno); For(i=0;i<totno;i++) { Printf(Enter the data in array); Scanf(%d,&a*i+); } For(i=0;i<totno;i++) { If(a[i]>m) M=a[i]; count=1; else if(a[i]==m) count= count+1; } Printf(Max=%d,m); Printf(Repeat=%d,count);

Searching in array Q- Write a program to input N element in the array and search a number on it? #include<stdio.h> Main() { Int a[10],I,totno,sno; Printf(Enter the size of array); Scanf(%d,&totno); For(i=0;i<totno;i++) { Printf(Enter the data in array); Scanf(%d,&a*i+); } Printf(Enter the search number); Scanf(%d,&sno); For(i=0;i<totno;i++) { If(a[i]>sno) Break; } If(i<totno) Printf(Number Found); else Printf(Number is Not Found); }

Palindrome array Q- Write the program to input data by user and check the array is palindrome or not? #include<stdio.h> Main() { Int a[10]; Int totno,I,j; Printf(Enter the size of array); Scanf(%d,&totno); For(i=0; i<totno; i++) { Printf(Enter the data in array); Scanf(%d,&a*i+); } For(i=0, j=totno-1; i<=j; i++, j--) { If(a[i]!=a[j]) Break; } If(I >j) Printf(Array is Palindrome); Else Printf(Array is not palindrome); }

2. 2D Array (two dimension array) It is another type of array where we can maintain our data in the row and column. It is also known as matrix representation of array. To declare the 2D array we have to define its datatpe name and size of row and columns. Syntax: datatype array_name[row][column]; In the 2D array the row and columns started from 0 to N-1. If we want to insert or retrieve data. We have to define name of array with index of row and column.

Constant 2D array Int a[2][2]= {{10,20},{20,30}}

Q- Design a 2D array of 2 row and 2 column and perform input output? #include<stdio.h> Main() { Int a[2][2]; Int I,j; For(i=0; i<2; i++) { For(j=0; j<2; j++) { Printf(Enter the Data in array); Scanf(%d,&a*i+*j+); } } For(i=0; i<2; i++) { For(j=0; j<2; j++) { printf(%d,a*i+*j+); } } }

Q- Write a program to input a 2D array of m*n size the find out its addition? #include<stdio.h> Main() { Int a[2][2]; Int I,j,m,n,sum=0; Printf(Enter the row and column m*n); Scanf(%d%d,&m,&n); For(i=0; i<m; i++) { For(j=0; j<n; j++) { Printf(Enter the Data in array); Scanf(%d,&a*i+*j+); } } For(i=0; i<m; i++) { For(j=0; j<n; j++) { Sum=sum+a [i] [j]; } } Printf(Addition=%d,sum); }

Q- Write a program to input a 2D array of M*N size and find out the sum of straight line? #include<stdio.h> Main() { Int a[2][2]; Int I,j,m,n,sum=0; Printf(Enter the row and column m*n); Scanf(%d%d,&m,&n); For(i=0; i<m; i++) { For(j=0; j<n; j++) { Printf(Enter the Data in array); Scanf(%d,&a*i+*j+); } } For(i=0; i<m; i++) { For(j=0; j<n; j++) { If(i==j) Sum=sum+a [i] [j]; } } Printf(Sum=%d,sum); }

Q- Write a program to input a 2D array of M*N size and find out the sum of upper triangle? #include<stdio.h> Main() { Int a[2][2]; Int I,j,m,n,sum=0; Printf(Enter the row and column m*n); Scanf(%d%d,&m,&n); For(i=0; i<m; i++) { For(j=0; j<n; j++) { Printf(Enter the Data in array); Scanf(%d,&a*i+*j+); } } For(i=0; i<m; i++) { For(j=0; j<n; j++) { If(i<=j) Sum=sum+a [i] [j]; } } Printf(Sum=%d,sum); }

Q- Write a program to input a 2D array of M*N size and find out the sum of Lower triangle? #include<stdio.h> Main() { Int a[2][2]; Int I,j,m,n,sum=0; Printf(Enter the row and column m*n); Scanf(%d%d,&m,&n); For(i=0; i<m; i++) { For(j=0; j<n; j++) { Printf(Enter the Data in array); Scanf(%d,&a*i+*j+); } } For(i=0; i<m; i++) { For(j=0; j<n; j++) { If(i>=j) Sum=sum+a [i] [j]; } } Printf(Sum=%d,sum); }

Q- Write a program to input two 2D array by user and find out their sum in 3rd array? #include<stdio.h> Main() { Int a[5][5], b[5][5], c[5][5]; Int I,j,m,n,sum=0; Printf(Enter the row and column m*n); Scanf(%d%d,&m,&n); //INPUT START For(i=0; i<m; i++) { For(j=0; j<n; j++) { Printf(Enter the Data in array); Scanf(%d%d,&a*i+*j+, b*i+ *j+); } } //SUM START For(i=0; i<m; i++) { For(j=0; j<n; j++) { C[i] [j]= a[i] [j] + b[i] [j]; } } //OUTPUT START For(i=0; i<m; i++) {

For(j=0; j<n; j++) { Printf(%d,c *i+ *j+); } } }

Character A single alphaber known as character it provide facility to store a single character in the character type variable. A character type variable have 1 byte of memory for a single character. To perform characters datatype we have %C as an identifier. Character type constant Syntax: Datatype variable_name= data; Char ch= a;

Pre- define function of character data type To process the character type data C language provide a character data type with some new functions in the ctype.h header file. Some of the functions are follows:1. Gerchar(); To accept a character at run time by user C provide getchar() function in the place of scanf but it can use with a single variable at a time. Syntax: Variable_name= getchar(); 2. Putchar(); It is an output function which is utilize to print the data of character type variable. It can also print a variable at a time. Syntax: putchar(variable_name); Example: Q- Write a program to input a character by user and print it using getchar() and putchar() functions? #include<stdio.h> #include<ctype.h> Main() { Char ch; Printf(Enter the character); Ch= gerchar(); Putchar(ch);

} 3. Toupper(); If we wants to convert character of small letter into the capital letter then we have to use toupper(); function. The function accept character type variable. Syntax: toupper(variable_name);

4. Tolower(); It is also a pre- define function that can convert a capital letters or data into small letters it is also accept character type variable. Syntax: tolower(variable_name);

5. Isupper(); If we wants to find out that data is capital or not then we have isupper(); function. It return the answer in true or false. Syntax: isupper(variable_name);

6. Islower(); To find out that our data is small letters or not we have islower function. Syntax: islower(variable_name);

Character type array (Strings) A string is a sequence of characters that is treated as a single data item. %S It is an identifier which is utilize when we perform on a character type array. The %s has some rules: It is utilize just with string. It does not provide permission to call the Ampercent (&) with scanf. With the %s we just use the name of array we does not provide index. After inserting string in the array we have a special character known as null character \0 that represent end of string.

Q- Write a program to input a string by user print data in one by one character? #include<stdio.h> Main()

{ Int I; Char a[5]; Printf(Enter the string); Scanf(%s,a); For(i=0; a*i+!=\0; i++) { Printf(%c,a*i+); } }

Q- Write a program to input a string by user and find out its length? #include<stdio.h> Main() { Int I,len=0; Char a[5]; Printf(Enter the string); Scanf(%s,a); For(i=0; a*i+!=\0; i++) { Len=len+1; } Printf(Length=%d,len); }

Q- Write a program to input a string by user and print in reverse order? #include<stdio.h> Main() { Int I,len=0; Char a[5]; Printf(Enter the string); Scanf(%s,a); For(i=0; a*i+!=\0; i++) { Len=len+1; } For(i=<-1; i>=0; i--) { Printf(%c,a*i+); } } Q- Write a program to input a string by user and and copy it in another string? #include<stdio.h> Main() { Int I,len=0; Char a[5],b[5]; Printf(Enter the string); Scanf(%s,a); For(i=0; a*i+!=\0; i++)

{ B[i]= a[i]; } Printf(%s,b); } String concate If we have two strings and we wants to connect the first string at the last of second string then it is known as string concate.

Q- Write a program to input two strings by user and transfer the first string at the last of second string? #include<stdio.h> Main() { Char a[20], b[20]; Int I,j,len=0; Printf(Enter the strings); Scanf(%s%s,a,b); For(i=0; b*i+!=\0; i++) { Len=len+1; } For(i=0, j=len; a*i+!=\0; i++, j++) { B[j]= a[i]; } B*j+= \0;

Printf(%s,b); } String.h If we are working on character type array or string then we have a pre- define header file known as string.h. String.h header file have some pre- define function which are follows:1. Strlen(); It is a pre- define function in the string.h that accept name of array and return length as integer. Syntax: strlen(array_name); Example: Q- Write a program to input a string by user and find out its length using pre- define function strlen(); ? #include<stdio.h> #include<string.h> Main() { Char a[20]; Int len=0; Printf(Enter the string); Scanf(%s,a); Len=strlen(a); Printf(Length=%d,len); } 2. Strcpy(); It is string copy function that is utilize to copy the data of a string into another string. The function accept two arguments name of source array and name of destination array. Syntax: Strcpy(destination_array, source_array); Example:

Q- Write a program to input a string by user and copy it in another string using pre- define function? #include<stdio.h> #include<string.h> Main() { Char a[20], b[20]; Printf(Enter the string); Scanf(%s,a); Strcpy(b,a); Printf(%d,b); } 3. Strcat(); It is concate function which is utilize to copy one string at the end of another string. Syntax: strcat(destination_array, source_array); Example: Q- Write a program to input a string by user and copy it in end of another string using pre- define function? #include<stdio.h> #include<string.h> Main() { Char a[20], b[20]; Int len=0; Printf(Enter the string); Scanf(%s,a); Strcat(b,a);

Printf(%d,b); } Q- Write a program to input a string by user and print it capital letters? #include<stdio.h> #include<string.h> Main() { Char a[20]; Int i; Printf(Enter the string); Scanf(%s,a); For(i=0; a*i+!= \0; i++) { Printf(%c,toupper(a*i+)); } } Q- Write a program to input a string by user and print it small letters? #include<stdio.h> #include<string.h> Main() { Char a[20]; Int i; Printf(Enter the string); Scanf(%s,a); For(i=0; a*i+!= \0; i++) {

Printf(%c,tolower(a*i+)); } }

2D character type array (2D string)

Q- Write a program to input a string in the 2D array and print one by one character? #include<stdio.h> Main() { Int I,j; Char a[3] [3]; Printf(Enter the string); Scanf(%s,a); For(i=0; i<3; i++) { For(j=0; j<3; j++) { Printf(%c,a*i+ *j+); } } } Q- Write a program to input a string in the 2D array and print in capital letters? #include<stdio.h> Main() { Int I,j; Char a[3] [3];

Printf(Enter the string); Scanf(%s,a); For(i=0; i<3; i++) { For(j=0; j<3; j++) { Printf(%c,toupper(a*i+ *j+)); } } }

Pointers The pointer is a variable which is also known as reference variable it is utilize to store the address of other variable without the use of pointer we have to search variable by its name and then search its address and then perform input and output which is a complicated procedure. By using the pointer we can directly request to the variable without its name because we have its address. Syntax: pointer_name= &variable_name; Q- Write a program to input two number by user and find out sum using pointer? #include<stdio.h> Main() { Int a,b,sum=0; Int *p,*q; Printf(Enter two numbers); Scanf(%d%d,&a,&b); P=&a; Q=&b; Sum=(*p)+(*q);

Printf(%d,sum); } Pointer with if- else Q- Write a program to input 3 numbers by user and find out maximum? #include<stdio.h> Main() { Int a,b,c; Int *p, *q, *r; Printf(Enter the numbers); Scanf(%d%d%d,&a,&b,&c); P= &a; Q= &b; R= &c; If((*p > *q )&&( *p > *r )) Printf(A is max); Else If(*q > *r) Printf(B is max); Else Printf(C is max); }

Pointer with looping

Q- Write a program to design a febonacci series using pointer?

#include<stdio.h> Main() { Int a=0,b=1,c,I; Int *p, *q, *r; P= &a; Q= &b; R= &c; Printf(%d%d,*p,*q); For(i=1;i<=10;i++) { *r=*p+*q; Printf(%d,*r); *p=*q; *q=*r; } }

Pointer with array When we use the pointer with the array we have to use new syntax that is: The declaration of pointer is in the previous format. Syntax: datatype * pointer_name; We have to use the name of array with the pointer name without (&) sign that is the pointer have 0 location of array. Syntax: pointer_name= array_name;

Q- Write a program to find out the maximum number from array using pointer? #include<stdio.h> Main() { Int a[10], totno, I, m= -32768, *p; Printf(Enter the size of array); Scanf(%d,&totno); For(i=0; i<totno; i++) { Printf(Enter the data in array); Scanf(%d,&a*i+); } P=a; For(i=0; i<totno; i++) { If(*p > m) M=*p; P++; } Printf(Max=%d,m); }

Datatype In C language we have two basic datatypes:1. Pre- define datatype All the dataypes that are available in the library of C language known as pre- define datatypes. We just use them without their description. Example: int, float, double etc.

2. User define datatypes The datatypes that are design by the user to solve some particular problem known as user define datatype or derive datatype. To create the user define data type we have two representation the structure and union.

Structure To create a derive data type we have the first representation known as structure. It is design to solve the problems of array that we can mention similar or dissimilar type of data in continue memory which is not possible in the array. It is utilze to create the group of data which we wants to ude in our program multiple times. Rules: The structure always create before the main function because after creating a data type we can use it. To create the structure we have to use struct keyword. Syntax: Struct structure_name{ Data type member1; Data type member2; }; To change the name of structure we have typedef keyword that accept the old name of structure and new name of structure. Syntax: Typedef struct_old_name new_name; To use the structure in the program. Create the variable of structure type. To use the member of structure by the structure type variable we have (.) operator. Syntax: Structure_variable.member_name; The size of structure datatype always equals to total size of structure member.

Q- Write a program to design a structure to maintain a details of student the details are: 3 subjects Roll number Name

#include<stdio.h> Struct sub{ Int h,e,m; Int rno; Char na[10]; }; typedef struct sub sub; Main() { Sub b; Printf(Enter the Roll number); Scanf(%d,&b.rno); Printf(Enter the Name); Scanf(%s,b.na); Printf(Enter the Marks of 3 subjects); Scanf(%d%d%d,&h,&e,&m); Printf(Roll no=%d\nName=%s,b.rno,b.na); Printf(\nHindi=%d\nEnglish=%d\nMaths=%d,b.h, b.e, b.m); }

Nested structure If a structure is utilize in side another structure then it is known as nested structure. Q- Write a program to maintain the details of student where we have its roll no, name and date of birth in day, month and year format? #include<stdio.h> Struct date{ Int d,m,y; }; typedef struct date date; Struct stu{ Int rno; Char na[10]; Date t; }; typedef struct stu stu; Main() { Stu s; Printf(Enter the name and roll number); Scanf(%s%d, s.na, &s.rno); Printf(Enter the date of birth); Scanf(%d%d%d, &s.t.d, &s.t.m, &s.t.y); printf(%s%d, s.na, s.rno); printf(%d%d%d, s.t.d, s.t.m, s.t.y); }

Union To create a user define data type or derive data type it is also follow similar syntaxs and rule that are provided by structure but we have two basic difference between the structure and union that are follows:1. To create the union we have to use union keyword but in the structure we have struct keyword.

2. The size of union always represent by the maximum size of member so it is an advantage to protect our memory. But in the structure the size always represent by total size of members.

Function The group of instructions arrange in a sequence and identify by a name known as function. The function is based on write ones use many features. If we have to use a logic in our program multiple times then we have to write the complete description but by using the fuctions whenever we require the logic just call the fuction. Types of functions 1. Pre- define function All the set of function that are previously available in the library of C language is known as pre- define functions. Example: Scanf, printf, getchar, putchar etc. 2. User define function The functions that are design by user to solve some particular problems known as user define functions. In the user define function the name, logic and working decided by user these function can be design in three basic steps that are follows:a) Function declaration (Function prototype) To create a new function in our program we have to declare it in the main function for that we have the written type of function (Which type of value return by function or not). Syntax: Void function_name(argument_datatype1, argument_datatype2 ) b) Function body It is second part of function where we have to define the complete logic of function. It also have written type function name and argument with data type. They are design out side the main function. c) Function calling To call our user define function we have to use function calling that can transfer the cursor from main function to the user define function in the calling we have to use name of function with data. Return keyword

To transfer the data from the user define function to the function calling we have return(); keyword. Q- What do you mean by function define the differences and similarities berween return or non- return type function using common example? Return type #include<stdio.h> Main() { Int sum(int,int); Int a,b,c; Printf(Enter the number); Scanf(%d%d,&a,&b); C=sum(a,b); Printf(%d,c); } Int sum(int a,int b) { Int s; S=a+b; Return(s); } Non Return type #include<stdio.h> Main() { void sum(int,int); Int a,b; Printf(Enter the number); Scanf(%d%d,&a,&b); sum(a,b); } void sum(int a,int b) { Int s; S=a+b; Printf(%d,s); }

Q- Write the program to input a number by used and print its square using return and non return type function? Return type #include<stdio.h> Main() { Int sqr(int); Int no,c; Printf(Print the number); Scanf(%d,&no); C=sq(no); Printf(%d,c); } Int sqr(int no) { Return(no*no); } Non Return type #include<stdio.h> Main() { void sqr(int); Int no; Printf(Print the number); Scanf(%d,&no); sq(no); } Int sqr(int no) { Int s; S=no*no; Printf(%d,s); }

Q- Write a program to input two no by user and design a function the find out the maximum from two numbers? #include<stdio.h> main() { Int max(int, int); Int a,b,c; Printf(Enter the number); Scanf(%d%d,&a,&b); C=max(a,b); Printf(%d,c); } Int max(int a, int b) { If(a>b) Return(a); Else Return(b); } Q- Design a function to find out even or odd from a given number ?

#include<stdio.h> Main() { Void even(int); Int no; Printf(Enter the number); Scanf(%d,&no); Even(no); } Void even(int no)

#include<stdio.h> Main() { int even(int); Int no; Printf(Enter the number); Scanf(%d,&no); C= Even(no); If(c==1) Printf(Number is Even);

{ If(no%2==0) Printf(Number is Even); Else Printf(Number is Odd); }

Else Printf(Odd); } int even(int no) { If(no%2==0) Return(1); Else Return(0); }

Function with looping Q- Design a function to find out series from 1 to n? #include<stdio.h> Main() { Void series(int); Int totno; Printf(Print the Total number); Scanf(%d,&totno); Series(totno); } Void series(int totno) { For(int i=1; i<= totno; i++) { Printf(%d,i); } } Q- Write a program to input a number by user and find out its factorial? Using function?

Non Return type #include<stdio.h> Main() { Void fact(int); Int no; Printf(Enter the number); Scanf(%d,&no); Fact(no); } Void fact(int no) { Int I, f=1; For(i=1; i<=no; i++) { F=f*I; } Printf(%d,f); }

Return type #include<stdio.h> Main() { int fact(int); Int no,c; Printf(Enter the number); Scanf(%d,&no); C= Fact(no); Printf(%d,c); } int fact(int no) { Int I, f=1; For(i=1; i<=no; i++) { F=f*I; } Return(f); }

According to execution The functions can be execute in two different formats recursive and non- recursive. 1. Recurrsive function (Cyclic function) If the function call itself in it known as recursive function otherwise the function does not call multiple times. Syntax: Main() { Func(); } Func() { Func(); } 2. Non- Recurrsive All the function that does not call themselves known as non- recursive function. #include<stdio.h> Main() { Int fact(int); Int no,c;

Printf(Enter the number); Scanf(%d,&no); C=fact(no); Printf(%d,c); } Int fact(int no) { Int f=1; If(no==1) Return(f); Else F=no* fact(no-1); } Function with Array When we use the array in the function then we have some changes in the declaration of fuction that we have to define data type with symbol of array and when we call the fuction we just use the name of array without index or size. #include<stdio.h> Main() { Void print(int[ ], int) Int a[10],I,totno; Printf(Enter the total number); Scanf(%d,&no); For(i=0; i<totno; i++) { Printf(Enter the number); Scanf(%d,&a*i+); } Print(a, totno); } Void print(int a[10], int totno) { Int I; For(i=0; i<totno; i++) { Printf(%d,a*i+); } } Q- Design a function to copy the data of a string into new string without the help of pre- define function?

#include<stdio.h> Main() { Void copy(char[],char[]); Char a[10], b[10]; Printf(Enter the copy string); Scanf(%s,a); Copy(a,b); } Void copy(char a[10], char b[10]) { Int I; For(i=0; a*i+!\0; i++) { B[i]=a[i]; } B*i+=\0; Printf(%s,b); } According to calling According to calling of function we have two representation call by value and call by reference. 1. Call by value If we call the function by the name of variable then it is call by value fuction. Example: #include<stdio.h> Main() { Void sum(int, int); Int a,b;

Printf(Enter the number); Scanf(%d%d,&a,&b); Sum(a,b); } Void sum(int a, int b) { Int c=a+b; Printf(%d,c); } 2. Call by reference The call by reference is the representation where function can be call by the address of variable to solve this problem we have to use pointer with the function. In this types of functions the calling always perform with (&) sign. Example: #include<stdio.h> Main() { Void sum(int *, int*); Int a,b; Printf(Enter the numbers); Scanf(%d%d,&a,&b); Sum(&a, &b); } Void sum(int *p, int *q) { Int c= (*p)+(*q); Printf(%d,c); } Q- Write the program to input 3 number by user and design a function to find out the maximum using call by reference? #include<stdio.h> Main() { Void max(int *, int*, int *) Int a,b,c; Printf(Enter the number);

Scanf(%d%d%d,&a,&b,&c); Max(&a,&b,&c) } Void max(int *p, int *q, int *r) { If((*p>*q)&&(*p>*r)) Printf(%d,*q); Else Printf(%d,*r); }

File handling When we design a program all our data and information does not save permanently in the memory that means all our output are useless. Because we cannot view them in next programs. To solve this problem we have a concept known as file handling. The procedure to transfer the data of RAM into the memory and retrieve data from memory to again RAM known as file handling. The file handling performs into different partitions: Input the data by user in the RAM and transfer this data into the secondary memory. When we wants to retive data than transfer the data of secondary memory into the RAM and RAM data into output. Types of fie According to the concept there are two types of files random files and squencial files. The representation of file where input perform in a sequence but output can be random known as random file organization. The representation of file where input and output both perform in a sequence known as sequencial organization. Rules for file handling 1. To represent the address of file we have to use a file pointer. 2. To open the file at run time we have to use fopen method the method required to arguments name of file and mode. The modes are small characters that provide different type of permission on the file.

a) W mode W stands for write if we provide a new file name than create it otherwise overwrite the previous data of that file. b) r mode It accept the name of available file. If file found than open for reading otherwise error. c) a mode It accept the name of file and open the file by transfer the cursor at the bottom of file for the new data otherwise an error. 3. To perform data input operation in the file from the RAM we have purc function. The function transfer one by one character in the file. 4. To retrieve one by one character from the file we have getc method. The method required address of file. 5. To control the data in the file we have end of file (eof) character. It is helpful to execute or terminate our program when input data and retrieve data. 6. After complete working on the file we have to close it using the fclose method. The method accept name of file pointer.

Q- Write a program to create a text file by the name decided by user? #include<stdio.h> Main() { FILE *fp; Char na[10], ch; Printf(Enter the file name); Scanf(%s,na); Fp= Fopen(na,w); Printf(Press F6 to exit); Do{ Ch= getchar(); Putc(ch,fp);

}while(ch!=EOF ); Fclose(fp); } Reading a file #include<stdio.h> Main() { FILE *fp; Char ch, fna[10]; Printf(Enter the file name); Scanf(%s,fna); Fp= fopen(fna,r); Do{ Ch=getc(fp); Printf(%c,ch); }while(ch!==EOF); Fclose(fp); } Q- Write a program to open a file and find out how many vowels, space, character and coma(,)? #include<stdio.h> Main() { FILE *fp; Int v,co,sp,c; Char ch, fna[10];

Printf(Enter the file name); Scanf(%s,fna); Fp= fopen(fna,r); Do{ Ch=getc(fp); If((ch==a)||(ch==e)||(ch==i)||(ch==o)||(ch==u)) V=v+1; Else If(ch==,) Co=co+1; Else If(ch== ) Sp=sp+1; Else C=c+1; }while(ch!==EOF); Printf(%d%d%d%d,v,co,sp,c); Fclose(fp);

} Working on numerical file If we wants to create a file with numeric data then we have some different kind of input output function. Putw(); The function is utilize to transfer numeric data from ram to the file. Syntax: putw(Number, file pointer) The function accept two arguments a number and file pointer. Getw();

The function is utilize to return a number from the file into the RAM function accept file pointer. Syntax: getw(file pointer); Q- Design a program to create a file with numberic data? #include<stdio.h> Main() { FILE *fp; Char fna[10]; Int no; Printf(Enter the file name); Scanf(%s,fna); Fna= fopen(fna,w); Printf(Enter zero to exit); Do{ Scanf(%d,&fna); Putw(no, fp); }while(no!=0); Fclose(fp); } Symbolic constant All the constant that are design with the pre- define symbol or representative known as symbolic constant. They can be design with the character or string we have some pre- define symbolic constant. Example: Null character \0= Represent end of string. End of file EOF = Represent end of file. Expression

The group of variables, constants and data types to design an equation known as expression. The Airthematics expressions are based on Airthematic operator. Scope When we declare variable in our program then known as scope that means how a variable can be use by others. Types of Scope 1. Local (internal variable) All those variables that are design inside a function known as internal or local variable. They cannot use by out sider. 2. Global (external variable) The variables that are design at the top of program window outside the functions known as global variables. They can be call by everyone or every module of our program.

Register variable When we design a variable to perform input output of data we have some set of temporary storage area known as register that can hold small bit of data for small time duration every variable also known as register variable. Bit field It is the first genetation of data storage that provide permission to store users data in the predecided length of field. At the starting we have character data type that stores its data in one byte of memory that means its length of bit field is 8 bit.

You might also like