SlideShare a Scribd company logo
SONU KUMAR
M.Sc.(Mathematics)
Prpgraming and problem solving
through 'C' language
COMPUTER LANGUAGE
Language is the source of communication. In order to
communicate with computer, we also required a
language.
Computer
Language
1. Machine language
2. Assembly language
3. High livel language
1. Machine language is
also known as "low
level languag" or
"Binary language".
2. In this language we
can use only "0 &1".
3. Modification is very
difficult.
4. No. Translation is
required
5. It is a machine
dependent language
MACHINE
LANGUAGE
ASSEMBLY
LANGUAGE
HIGH LEVEL LANGUAGE
1. It is also known as
''symbolic language"
2. In this language we
can use only (0-9)(a-
z) but we cannot use
any special
characters (@,#,+,%).
length of the word
should not be more
than 5 characters.
3. Modification is easy
4. Translator is requi-
red (Assembler).
5. It is also machine
dependent language.
1. C is one of the most popular language designed and deceloped by Dennis
Ritchie in year 1992 at "AT &Y T" lab, US.
2. The concepts of C language are taken from B language BPCL (Basic
combined Programming Language).
3. It is machine independent.
4. C language follows the concept of structured programming.
OVER VIEW OF C LANGUAGE :-
PROPERTIES OF C LANGUAGE :-
1. C language supports newly 30 header files.
2. C language provides the facility to add any new function in
the header file.
3. C language supports 32 keywords.
4. C language has a rich set operation and data type.
5. C language also supports graphical programming.
1. Every program should have main function.
2. Every statement should be properly terminated.
3. It is a case sensitive language.
4. No. of opening & closing bracket must be equal.
PROGRAMMING RULES :
Keywords :
1. Reserved words which we cannot use as a variable name
/ function name / array names are known as keywords.
2. C language supports 32 keywords.
auto
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
go to
if
int
long
register
return
short
signed
size of
static
struct
switch
typed of
union
while
unsigne
d
void
IDENTIFIERS
:-
Array word/character which a user may use name as a variable name
/ function name / array name is called idetifiers.
Delimete
r :
Any symbol which a user may use in C programming language is
known as delimeter.
NAME SYMBOL WORK
Semicollon ; Used as a terminator to show the
end of statement.
Hash # Used as a pre
precessor.
Comma
parenthesis
Braces
Square Brackets
,
( )
{ }
[ ]
Used as a variable seperaor.
Used with every function.
Used to show the scope of function /
statement.
Used with Array.
TOKEN
Smallest unit of C programming language known as token.
Token
• Variables
• Constant
• Delimeter
• Keyword
• Indetifier
HEADER FILES :
• Header files are used at the top of program.
• Header files are collection of different function where
each function performs a unique task.
• C language supports 30 Header files
Example:-
1. <stdio.h>
• Standard Input / output Header files.
Function defined under <stdio.h.>
1. gets()
2. get c()
3. putc()
4. puts()
5. printf()
6.scanf()
2. <conio.h>
• Ful form of <conio.h> is console input /output Header file.
• Function defined under <conio.h>
are -
1. clrscr()
2. getch()
3.<string.h>
• Functions defined <string.h> are -
1. strcpu()
2. strcat()
3. strlur()
4. strupr()
4. <Math.h>
Functions defined under <math.h> are -
1. pow()
2. sqrt()
3. abs()
4. sin()
5. fmod()
5. <alloc.h>
1. calloc()
2. malloc()
3. realloc()
4. frec()
STRUCTURES OF A C PROGRAM :
Software Editor
Pre - Processor
Source code
compiler
Linker
Loader
Output
Execution of a C program : Source code in Editor
Pre processor
Compile Source Code
Syntax /
Editior
linking editior
Runtime
/logical error
Output
Input again
yes
yes
yes (logical
Error)
Data types
• It tells us nature of the data.
1. Primary Datatype
2. Secondary Datatype
3. User defined Datatype
char int float
double void function
Array pointer enum
structure union
Primary Datatypes
: FSTSTYPES RAMGE MEMORY
REQUIREMENT
FORMAT
SPECIFIER
Signed int -32768 to +32767 2 Bytes %d
unsigned int 0 to 65535 2 Bytes %u
short int -32768 to +32761 2 Bytes %d
long int -2147483648 to
+2147483647
4 Bytes %ld
signed char -128 to+127 1 Byte %c
float 3.4e^-38 to 3.4e^38 4 Byte %f
double 1.7e^-308 to 1.7e^38 8 Bytes %lf
void no return ___ ___
COMPUTER
"The oxford defines a computer as an automatic eletronic
operator for making calculation or controling operators that
are expressible in numerical or logical terms."
• Programs
Program is a set of instruction.
• Software
Software is a set of Programmes.
• System Software
System software is a software interface between system and
user. eg: All operating system (Window, linux.)
• Application
software
Other than system software all software are application software.
eg : Mcrosoft office, Whatsapp, Twitter, Oracle, Google
chrome.
• Basic Structure or design of computer
CPU
ALU MEMORY C.U
Memory or brain of computer
Input Output
• Input devices
keyword, mouse, joystic, lightpen, scanner
• Output device
monitor, printer, hard disk.
• CPU actually performs the 3C's :
1. Calcutate
2. compare
3. copy
Memory
On cheap memory (cache)
RAM/ROM
Primary memory
Secondary Memory
ALGORITHMS AND FLOWCHARTS
Program = Algorithms + Data
"An algorithim is an effective procedure for solving a problems in a
finite number of steps".
• Key features of an Algo :-
Algo having basically three features :-
1. Sequence ( also known as process )
2. Decision ( also known as selection )
3. Repeatation (also known as iteration or loop )
eg . for making a part of tea
VARIABLES : -
In previous Example tea making algo the level of water in a kettle
is variable. The temperature of water is a variable and quantity of
tea leaves is also a variable.
• Tea leaves -
quantity
• Water -
temperature
• Different ways of starting algo :-
1. Pseudo - code
2. flow - chart
Data Type
The data used to algo can be of different
types.
2. Alphabetic or Character data : R, A, V, I,
3. Logical Data : True, False
Write an algo for finding the sum of any two numbers.
1. START
2. PRINT "ENTER TWO NUMBERS".
3. INPUT "A & B"
4. C = A + B
5. PRINT C
6. STOP
Write an algo to print the
longest number among three
numbers.
1. START
2. PRINT "ENTER THREE
NUMBER"
3. INTPUT
4. IF A > B & A > C THEN,
PRINT A
5. ELSE B > A & B > C THEN ,
PRINT B.
6. PRINT C
7. STOP
FLOWCHART
Flowchart is appropriate step to be followed in order to arrive at
the solution to a problem.
Flowchart are generally developed in early stage of formulating
computer solution.
GUIDLINES FOR DRAWING OF FLOW CHART:-
Symbol are following :-
Symbol are following :-
Computational Step or Processing
Step
Input /Output
Decision making Step
For connection
Srart / End
Draw a flow chart to find the sum of first 10 numbers.
Start
Sum = 0
N =0
N =N+1
n =10
PRINT
STOP
1. N =0+1 = 1
SUM = 0+1 =1
2. N = 1+1 =2
SUM = 1+2 =3
3. N = 2+1 = 3
SUM = 3+3 = 6
4. N = 3+1 = 4
SUM = 6+4 = 10
.....................................
............................. so on
n=10
1. sum =0+1= 1
2. sum =1+2= 3
3. sum =3+3=6
4. sum =6+4 =10
5. sum= 10+5=15
6. sum =15+6=21
7. sum =21+7 =28
8. sum =28+8 =36
9. sum =36+9 =45
10. sum= 45+10
=55
Write a flowchart to find the largest among three numbers A, B, &
C.
start
Input A,B,C
Is B > C
?
Is A > B
?
Is A > C
?
Print B Print C Print A
Stop
yes yes yes
no
no no
Special Characters :-
, comma
. period or dot
; semicolumn
: colon
' apostrophe
" quotation mark
! exclamaton
| vertical bar
/ slash
 back slash
~ tilde
_ under score
$ dollar
? question mark
& ampersand
^ caret
* asterisk
- minus
+ plus
< less than
> greater than
( ) parenthesis ;eft /right
[ ] bracket left /right
{} braces left /right
% percent
# number sign or hash
@ at the rate
• Printf :-
printf( ) is a function that is used to print any data on the
video monitor screen.
• It has the following form
printf(" control - string", list of variables)
• Control strings used for different data
types -- %c char
%d int
%u unsigned
%hd or %hi short int
%ld long int
%f float
%lf long float
%ld long double
Types of operator Operator symbol with meaning
• Arithmetical uniary : +, - ,++(increment), - -(decrement)
binary : + (Addition), - (substraction),
*(multiplication), /(division), %(modulus)
• Assignment simple assignment : =
compund assignment : +=, -+, *=, /=, %=, ^=, |=
expressinon assignment : 5 + (b=8+(c=2))-4
• Relational < , > , >=, <=
• Equality == (equal to), ! = (not equal to)
• Logical
&& (logical and)
|| (logical or)
! (logical not)
Bitwise & (bitwise and)
! (bitwise or)
~ (complement)
^ (exclusive or)
>> (right shift)
<< (left shift)
• Others , (comma)
* (indirection)
. (membership operation)
-> (relationship operation)
Write a program of Arithmetic operation
#include<stdio.h>
#include<conio.h>
void main()
{
int a=100;
int b=2;
int c=25;
int d=4;
result=a+b;
printf("a+b=%dn", result);
result=a-b;
printf("a-b=%d n", result);
result=a*b;
printf("a*b=%d n", result);
result=a/b;
printf("a/b=%d n", result);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
float A, r;
printf("Enter the value of radius r =");
scanf("%f", &r);
A=3.14*r*r;
printf("The area of given circle is %f" , A);
getch();
}
Write a program to calculate area of
circle
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c;
priintf("n enter two numbers");
scanf("%d %d", &a,&b);
c=a;
a=b;
b=c;
printf("The answer is %d n",a,b);
getch();
}
Write a Program inc to swap the two integers
using third variable.
Write a program in c to swapping two numbers without using
third variables or without temporary variables.
#include<stsio.h>
#include<conio.h>
void main()
{
int a, b ;
printf("enter two numbers");
scanf("%d %d , &a,&b);
if(a>b)
printf("%d", a);
else,
printf("%d", b);
getch();
}
Write a program to read two numbers and then display the
larger out of these two numbers,
A statement is a systamtic construction that
performs a action when a program is executed.
IF - else :-
If r==0
printf|("r having no value");
else
priintf("r having same values");
Write a program in to check whether a number given by the
user is even or odd.
#include<stdio.h>
#include<conio.h>
void main ()
{
int n, r4, r100, r400;
printf("enter a number n");
scanf("%d", &n);
r4=n%4;
r100=n%100;
r400=n%400
if(r4==0 && r100!==0 || r400)
printf("year is leap year");
else
prinitf("It is not a leap year");
getch();
}
Write a program to determine a year is a
leap year.
Write a program to find largest number among three
numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int x, y, z;
printf ("Enter three numbers");
scanf("%d%d%d", &x,&y,&z);
if(x<y)
if(x<z)
printf("x is the smallest");
else printf("z is smallest");
if(y<z)
printf("y is smallest);
else
printf("z is smallest");
getych();
}
Write a program to find the smallest number among three
numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c, d;
printf("Enter four numbers");
scanf(%d%d%d%d", &a,&b,&c,&d);
if(a>b);
if(a>c);
if(a>d);
printf("a is the largest number);
else
printf("d is the largest number");
if(b>c)
If(b>d)
printf("b is the largest number");
else
printf("d is the largest number");
if(c>d)
printf("c is the largest number");
else
printf("d is the largest number");
Write a program to find largest number among four numbers.
A loop formed by using for statement is generally called definite loop because
the programmer knows exactly how many time it will repeat
FOR LOOP
The general form of statement is
as follows-
{
statement(s)
}
eg;
for(i=0; i<=n; i++)
#include<stdio.h>
#include<conio.h>
void main()
{
int i, sum=0, n.
printf("Enter the value of n");
scanf("%dn" &n);
for(i=0; i<=n; i++)
{
sum=sum+i;
}
printf("The value of sum", sum);
getch():
}
Write a program in c to find the sum of n numbers.
n=10
1. sum =0+1= 1
2. sum =1+2= 3
3. sum =3+3=6
4. sum =6+4 =10
5. sum= 10+5=15
6. sum =15+6=21
7. sum =21+7 =28
8. sum =28+8 =36
9. sum =36+9 =45
10. sum= 45+10 =55
Write a program to find factorial.
n =5
1. fact = 1*1
2. fact = 1*2
3. fact = 2*3
4. fact = 6*4
5. fact = 24*5 =120
Another construct that is very closely related to the
while construct is do-while constuct.
DO WHILE CONSTRUCTS
The form of this loop constuct is as follows :
{
//Body of statement
placed
}
while(condition)
#include<stdio.h>
#include<conio.h>
void main()
{
init i ;
i=1;
do
{
printf("RADHE RADHE ")
while(i<=7)
}
}
Write a program to print RADHE RADHE using do-while loop.
When there are a number of else alternative, another way of
representing this multi way selection is by the switch statement.
SWITCH CASE SATEMENT :-
1. The switch structures is multi selection structure has allows the
handling of even more complicated decision statement, other than a
two way if-else statement. It chooses one of the cases depending on
the result of the expression.
2. One variable with int or char data type may be used in the expression,
sometime called the controlling expression of switch statement.
switch(expression)
{
case value 1:
program statement
--------------------------;
break;
case value 2:
program statement
-----------------------------;
break;
......
case value n:
program statement;
break;
default:
printf("Entry is invalid");
break;
}
The general format of switch statement is as follows -
Write a program to display the names of the days of a
week.
case 3:
printf("Day is tuesday");
break;
case 4:
printf("Day is wednesday")
break;
case 5:
printf("Day is thursday");
break;
case 6:
printf("Day is friday")
break;
case 7:
printf("Day is saturday");
break;
case 8:
printf("Entry is invalid");
break;
}
getch();
}
C is used the keyword if to execute the set of command lines
when the logical condittion is true.
The set of command lines are executed only one when
the logical condition is true.
IF STATEMENT
Write a program to check whether entered number is less
than 10 ? If yes, display the same.
#include<stdio.h>
#include<conio.h>
void main()
{
int i ;
clrscr();
printf("Enter the value you want to check :");
scanf("%d n", &i);
if(i<10)
printf("Entered value is <10");
getch();
}
Write a program to find Area of triangle using base and height.
#include<stdio.h>
#include<conio.h>
void main()
{
float base, height, area ;
printf("n Enter the base of a triangle ");
scanf("%f" , &base);
printf("n Enter the height of a triangle ");
sscanf"("%f", &height);
area=(base*height)/2;
printf("n The area of given triangle = %2fn" , area);
getch();
}
Write a c program to generate first n-prime numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i=3, count, c ;
printf("How many prime numbers you want to
print :");
scanf("%d", &n);
printf('first n prime numbers are")
for(count=2; count<=n; count++)
{
for(c=2; c<=i-1; c++)
{
if(i%c==0)
break;
}
if(c==i)
printf("%dn", i);
count++;
}
i++;
}
return 0;
}
Write a program to find roots of quadratic
equation.
if(discriminant>0)
{
root1=(-b+sqrt(discriminant))/(2*a);
root2=(-b-sqrt(discriminant))/(2*a);
printf("root1=%f and root2=%f", root1, root2);
}
//Condition for Real and different Root :-
//Condition for real and Equal root
if(discriminant==0)
{
root1=root=-b/2*a);
printf("root1=root2=%f", root1);
}
else
{
real part==-b/(2*a);
image part=squrt(-discriminant)/(2*a);
printf("root1=%f %f i and root2=%f %f i", real part, image part,
real part, image part);
}
return 0;
}
//If roots are not Real
#include<stdio.h>
#include<math.h>
int is perfect (unsigned long log int n)
{
unsigned long long int dsum=0 ;
unsigned long long int i ;
for(i=1; i<=sqrt(n); ++i)
{
if(n%i==0)
{
if(i==n/i)
}
else
{
dsum=dsum+i;
Write a program to generate first n perfect number.
dsum=dsum+n/i;
}
}
}
dsum=dsum-n;
if(dsum==n)
return 1;
else
return 0;
}
int main()
{
unsigned long long int n, i,temp;
printf("Enter n ");
scanf("%llu", &n);
i=1;
while(n>0)
{
if(is perfect(i)==1)
printf("%llu", i);
n=n-1;
}
i=i+1;
return 0;
}
Write a c program to evaluate sinx and cosx up to n terms
using Taylor's series.
#include<stdio.h>
#include<sonio.h>
void main()
{
int i, n;
float x, sum_cos=1, sum_sin, t=1;
printf("Enter the value of x");
scanf("%f, &x);
printf("Enter the llimit t /term to which series should be
evaluated);
scanf("%d", &n);
x=x*8.14159/180;
/*loop to calculate value of cos in series */
t=(t*(-1)*x*x)/2*i*(2*i-1));
sum_cos=sum_cos+t;
}
t=x;
sum_sin=x;
/*loop to calculate value of sin series */
for(i=1; i<=n; i++)
{
t=(t*(-1)*x*x/(2*i*(2+t+1));
sum_sin=sum_sin+t;
}
printf("The value of cos(7.f) is : %0.4 f/n", x,
sum_cos);
printf("The value of sin (%f) is %0.4f",
x, sum_sin);
getch();
Write a Program in c to print addition & multiplication of two
matrices of order m*n.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10], b[10][10], c[10][10], m, n, i, j ;
printf("Enter the value of row m and column n of matrices");
scanf("%d%d", &m,&n);
printf("Enter the element of matrix a");
for(i=0; i<=(m-1); i=i+1)
{
for(j=0; j<=(n-1); j++)
{
scanf("%d", &a[i][j]);
}}
printf("Enter the element of matrix b");
for(i=0; i<=(m-1); i++)
{
for(j=0; j<=(m-10); j=j+1)
{
scanf("%a", &b[i][j]);
}}
printf("matrix a is n");
for(i=0; i<=(m-1); i+1)
{
for(j=0; j<=(n-1); j+1)
{
printf("dt", a[i][j]);
}
printf("n");
}
printf("matrix b is n");
for(i=0; i<=(m-1); j=j+1)
{
for(j=0; j<=(n-1); j=j+1)
{
printf("%dt", b[i][j]);
}
printf("n");
}
for(i=0; i<=(m-1); i=i+1)
{
for(j=0; j<=(n-1); j=j+1)
{
c[i][j]=a[i][j]+b[i][j];
}}
printf("rrsulted matrix after
addition");
for(i=0; i<=(m-1); i=I=1)
{
for(j=0; j<=(n-1); j=j+1)
{
printf(%dt", c[i][j])
}
printf("n);
}
int k;
for(i=0; i<m; i++)
{
for(k=0; k<=(n-1); k=k+1)
{
c[i][j]=c[i][j] + a[i][j]*b[k][j];
}}
priintf("matrix after multipllication is
n");
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
printf("%dt", c[i][j]);
}
printf(''n");
}
getch();
}
Write a program in c to print Transpose of a matrix of order
n*n.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10], n, m,i, j ;
printf("Emter value of row m & colum n : ");
scanf("%d%d", &m, &n);
printf("Enter the element of matrix a : ");
for(i=0; i<=(m+1); i++)
{
for(j=0; j<=(n-1); j=j+1
{
scanf("%d", &a[i][j]);
}}
#include<stdio.h>
main()
{
int i, j;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
printf(%d", i);
}
printf("n");
}
}
1
22
333
4444
55555
Write a prigramme to print :
for((i=0; i<=(m-1); i=i++)
{
for(j=0; j<=(n-1); j=j++)
{
printf(%dt", a[i][j]);
}
printf("n")
}
printf("Transpose is : n ");
for(i=0; i<=(n-1); i=i+1)
{
for(j=0; j<=(m-1); j=j+1)
{
printf("%dt", a[j][i]);
}
printf("n");
}
jgetch();
#include<stdio.h>
main()
{
int i, j;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
print("%d", j);
}
printf("n");
}
}
Write a programe to print
1
12
123
1234
12345
QUESTION BANK QUESTIONS
Write a program to take a five digits number and find the sum
of the digit of the number.
#include<stdioi.h>
#inclulde<conio.h>
void main()
{
int n, r, sum=0 ;
priintf("Enter the number of five digits");
scanf("%d", &n);
while(n>0)
{
r=n%10;
sum=sum+r;
n=n=n/10;
}
printf("sum of digits = %d", sum);
getch();
}
Write a program to find the product of two
matrices.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[2][2], b[2][2], c[2][2], i, j, k, sum;
printf("Enter four values for 1st matrix'');
for(i=0; i<2; i++)
{
for(j=0; f<2; j++)
scanf("%d", &a[i][j]);
}
printf("Enter four values for 2nd matrix'');
for(i=0; i<2; i++)
{
for(j=0; j<2; j++)
{
scanf("%d", &b[i][j]);
}}
for(i=0; i<2; i++0)
{
for(j=0; j<2; j++)
{
sum=0;
}
for(k=0; k<2; k++)
{
sum=sum+a[i[]k]*b[k][i];
c[i][j] = sum;
}}
printf("product of matrix is ");
for(i=0; i<2; i++)
{
for("j=0; j<2; j++);
printf("%dt", c[i][j]);
printf("n");
}
getch();
}
What is union? How it differs from structure?
Definition of union
A union is a user defined type in which all members share the same memory location,
this means that at any given time a union can contain no more than one object from
its list of members. It also means that no matter how many members a union has. It
always uses only enouygh memory to share the largest member.
Differnnce between union and structure
Strucfture
1. The keyword struct is used to defined
a structure.
2. When a variable is associate with a
structure the compiler allocates the
memory for each member. The size of
structure is greater than or equal to
sum of sizes ofits member.
3. Each member with a structure is
assigned uniquestrange area of
location
Union
1. The keyword union is used to defined union.
2. When a variable is associated with a union the
compiler allocates the memory by
considering size of the largest memory. So
size of union is equal to size of largest
member.
3. Memory allocation is shared by individuals a
member if union.
4. Altering the values of any of the member will
alter other member values.
4. Altering the value of a member will not
alter other members of the structre.
5. Individual member can be accessed at
a time.
6. Several members of a structure can
initialize at once.
5. Only one member can be accessed at
a time.
6. Only the first member of a union can
be initialize.
Write the difference between logical operator and Bitwise
operator.
Bitwise operator
1. Its symbol is '&'.
2. It evaluates both left and right
side of expression.
3. It operates on "Boolean data
type " as well as operates on
"bits".
4. It use to check logical condition
and also used to mask offcertain
bits such as parity bits.
Logical operators
1. Its symbol is '&&'.
2. Its only evaluates the left side of
the expression.
3. It operates only on "Boolean
datatypes".
4. It uses to only check.
What is recursion? What are its advantages? How it is excuted.
Explain with the help of an example.
A recursive function is a function that calls itself to perform a
specific operation. The process of a function calling itself is
known as recursion.
In other word, A function is called recursive when it
calls itself there is always if statement in recursive function
to force the function to return without recursive call being
exacated otherwise the function goes in indefinite loop.
Advantages of recursion:-
Through recursion we can solve the problem in easy way
while its interative solution is very big and complex. It is
useful to step through the function observing what value
gets returned with each call.
Execution with example :-
Recursion in C for factorial -
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n; int res;
priintf("Enter a numner");
scanf("%d", &n);
res=fact(n);
printf("factorial is =%d", res);
}
int fact(int x)
{
int f:
if(x==1)
return(1);
else
f=x*fact(x-1);
return(f);
}
What is looping ? Explain the syntax of while loop by taking an
example.
Looping :-
Looping is a concept that is applied in programming in general. It
is the way to execute a set of instructions any number of times.
In C the loopiing concept can be applied using -
1. While loop
2. Do - while loop
3. Go to sattement.
While loop is also known as entry controlled loop as the condition
to be checked is given before the statements that are to be
iterated.
Syntax for a while loop is -
for example :-
#include<stdio.h>
#Include<conio.h>
void Main()
{
int i=0;
while (i<5)
{
printf("%d", i);
i++;
getch();
}
01234
Programming in C by SONU KUMAR.pptx

More Related Content

Similar to Programming in C by SONU KUMAR.pptx

C prog ppt
C prog pptC prog ppt
C prog ppt
xinoe
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
Rohit Shrivastava
 
c++
c++c++
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
eteaching
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
JAYA
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
Dr.Florence Dayana
 
C++
C++C++
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
C Programming Introduction
C Programming IntroductionC Programming Introduction
C Programming Introduction
Honey Sharma
 
Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variablesTony Apreku
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
Vikram Nandini
 
C material
C materialC material
C material
tarique472
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
INTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓNINTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓN
BenjaminAnilema
 
introductory concepts
introductory conceptsintroductory concepts
introductory conceptsWalepak Ubi
 
java or oops class not in kerala polytechnic 4rth semester nots j
java or oops class not in kerala polytechnic  4rth semester nots jjava or oops class not in kerala polytechnic  4rth semester nots j
java or oops class not in kerala polytechnic 4rth semester nots j
ishorishore
 

Similar to Programming in C by SONU KUMAR.pptx (20)

C prog ppt
C prog pptC prog ppt
C prog ppt
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
c++
c++c++
c++
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 
C++
C++C++
C++
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
C Programming Introduction
C Programming IntroductionC Programming Introduction
C Programming Introduction
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variables
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C material
C materialC material
C material
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
INTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓNINTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓN
 
introductory concepts
introductory conceptsintroductory concepts
introductory concepts
 
java or oops class not in kerala polytechnic 4rth semester nots j
java or oops class not in kerala polytechnic  4rth semester nots jjava or oops class not in kerala polytechnic  4rth semester nots j
java or oops class not in kerala polytechnic 4rth semester nots j
 

More from SONU KUMAR

GROUP AND SUBGROUP PPT 20By SONU KUMAR.pptx
GROUP AND SUBGROUP PPT 20By SONU KUMAR.pptxGROUP AND SUBGROUP PPT 20By SONU KUMAR.pptx
GROUP AND SUBGROUP PPT 20By SONU KUMAR.pptx
SONU KUMAR
 
SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN by Sonukumar .pptx
SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN by Sonukumar .pptx SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN by Sonukumar .pptx
SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN by Sonukumar .pptx
SONU KUMAR
 
Application of C language by Sonu kumar.pptx
Application of C language  by Sonu kumar.pptxApplication of C language  by Sonu kumar.pptx
Application of C language by Sonu kumar.pptx
SONU KUMAR
 
SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN-1.pptx
SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN-1.pptxSOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN-1.pptx
SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN-1.pptx
SONU KUMAR
 
NUMBER THEORY BY SONU KUMAR.pptx
NUMBER THEORY  BY SONU KUMAR.pptxNUMBER THEORY  BY SONU KUMAR.pptx
NUMBER THEORY BY SONU KUMAR.pptx
SONU KUMAR
 
NATIONAL MATHEMATICS DAY BY SONU KUMAR.pptx 123.pptx
NATIONAL MATHEMATICS DAY BY SONU KUMAR.pptx 123.pptxNATIONAL MATHEMATICS DAY BY SONU KUMAR.pptx 123.pptx
NATIONAL MATHEMATICS DAY BY SONU KUMAR.pptx 123.pptx
SONU KUMAR
 
GROUP THEORY PPT,SUBGROUP, ABELIAN GROUP,
GROUP THEORY PPT,SUBGROUP, ABELIAN GROUP, GROUP THEORY PPT,SUBGROUP, ABELIAN GROUP,
GROUP THEORY PPT,SUBGROUP, ABELIAN GROUP,
SONU KUMAR
 
SET THEORY AND THEIR APLICATION
SET THEORY AND THEIR APLICATIONSET THEORY AND THEIR APLICATION
SET THEORY AND THEIR APLICATION
SONU KUMAR
 
PROGRAMMING IN C.pptx
PROGRAMMING IN C.pptxPROGRAMMING IN C.pptx
PROGRAMMING IN C.pptx
SONU KUMAR
 
GROUP, SUBGROUP, ABELIAN GROUP, NORMAL SUBGROUP, CONJUGATE NUMBER,NORMALIZER ...
GROUP, SUBGROUP, ABELIAN GROUP, NORMAL SUBGROUP, CONJUGATE NUMBER,NORMALIZER ...GROUP, SUBGROUP, ABELIAN GROUP, NORMAL SUBGROUP, CONJUGATE NUMBER,NORMALIZER ...
GROUP, SUBGROUP, ABELIAN GROUP, NORMAL SUBGROUP, CONJUGATE NUMBER,NORMALIZER ...
SONU KUMAR
 

More from SONU KUMAR (10)

GROUP AND SUBGROUP PPT 20By SONU KUMAR.pptx
GROUP AND SUBGROUP PPT 20By SONU KUMAR.pptxGROUP AND SUBGROUP PPT 20By SONU KUMAR.pptx
GROUP AND SUBGROUP PPT 20By SONU KUMAR.pptx
 
SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN by Sonukumar .pptx
SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN by Sonukumar .pptx SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN by Sonukumar .pptx
SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN by Sonukumar .pptx
 
Application of C language by Sonu kumar.pptx
Application of C language  by Sonu kumar.pptxApplication of C language  by Sonu kumar.pptx
Application of C language by Sonu kumar.pptx
 
SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN-1.pptx
SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN-1.pptxSOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN-1.pptx
SOME IMPORTANT TOPICS OF GROUP THEORY IN MODERN-1.pptx
 
NUMBER THEORY BY SONU KUMAR.pptx
NUMBER THEORY  BY SONU KUMAR.pptxNUMBER THEORY  BY SONU KUMAR.pptx
NUMBER THEORY BY SONU KUMAR.pptx
 
NATIONAL MATHEMATICS DAY BY SONU KUMAR.pptx 123.pptx
NATIONAL MATHEMATICS DAY BY SONU KUMAR.pptx 123.pptxNATIONAL MATHEMATICS DAY BY SONU KUMAR.pptx 123.pptx
NATIONAL MATHEMATICS DAY BY SONU KUMAR.pptx 123.pptx
 
GROUP THEORY PPT,SUBGROUP, ABELIAN GROUP,
GROUP THEORY PPT,SUBGROUP, ABELIAN GROUP, GROUP THEORY PPT,SUBGROUP, ABELIAN GROUP,
GROUP THEORY PPT,SUBGROUP, ABELIAN GROUP,
 
SET THEORY AND THEIR APLICATION
SET THEORY AND THEIR APLICATIONSET THEORY AND THEIR APLICATION
SET THEORY AND THEIR APLICATION
 
PROGRAMMING IN C.pptx
PROGRAMMING IN C.pptxPROGRAMMING IN C.pptx
PROGRAMMING IN C.pptx
 
GROUP, SUBGROUP, ABELIAN GROUP, NORMAL SUBGROUP, CONJUGATE NUMBER,NORMALIZER ...
GROUP, SUBGROUP, ABELIAN GROUP, NORMAL SUBGROUP, CONJUGATE NUMBER,NORMALIZER ...GROUP, SUBGROUP, ABELIAN GROUP, NORMAL SUBGROUP, CONJUGATE NUMBER,NORMALIZER ...
GROUP, SUBGROUP, ABELIAN GROUP, NORMAL SUBGROUP, CONJUGATE NUMBER,NORMALIZER ...
 

Recently uploaded

Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Sebastiano Panichella
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
OWASP Beja
 
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
OECD Directorate for Financial and Enterprise Affairs
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
khadija278284
 
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptxsomanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
Howard Spence
 
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Matjaž Lipuš
 
Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
IP ServerOne
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
Vladimir Samoylov
 
Obesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditionsObesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditions
Faculty of Medicine And Health Sciences
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Orkestra
 
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Sebastiano Panichella
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
Access Innovations, Inc.
 
International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
Sebastiano Panichella
 

Recently uploaded (13)

Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
 
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
 
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptxsomanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
 
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
 
Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
 
Obesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditionsObesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditions
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
 
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
 
International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
 

Programming in C by SONU KUMAR.pptx

  • 1. SONU KUMAR M.Sc.(Mathematics) Prpgraming and problem solving through 'C' language
  • 2. COMPUTER LANGUAGE Language is the source of communication. In order to communicate with computer, we also required a language. Computer Language 1. Machine language 2. Assembly language 3. High livel language
  • 3. 1. Machine language is also known as "low level languag" or "Binary language". 2. In this language we can use only "0 &1". 3. Modification is very difficult. 4. No. Translation is required 5. It is a machine dependent language MACHINE LANGUAGE ASSEMBLY LANGUAGE HIGH LEVEL LANGUAGE 1. It is also known as ''symbolic language" 2. In this language we can use only (0-9)(a- z) but we cannot use any special characters (@,#,+,%). length of the word should not be more than 5 characters. 3. Modification is easy 4. Translator is requi- red (Assembler). 5. It is also machine dependent language.
  • 4. 1. C is one of the most popular language designed and deceloped by Dennis Ritchie in year 1992 at "AT &Y T" lab, US. 2. The concepts of C language are taken from B language BPCL (Basic combined Programming Language). 3. It is machine independent. 4. C language follows the concept of structured programming. OVER VIEW OF C LANGUAGE :- PROPERTIES OF C LANGUAGE :- 1. C language supports newly 30 header files. 2. C language provides the facility to add any new function in the header file. 3. C language supports 32 keywords. 4. C language has a rich set operation and data type. 5. C language also supports graphical programming.
  • 5. 1. Every program should have main function. 2. Every statement should be properly terminated. 3. It is a case sensitive language. 4. No. of opening & closing bracket must be equal. PROGRAMMING RULES : Keywords : 1. Reserved words which we cannot use as a variable name / function name / array names are known as keywords. 2. C language supports 32 keywords. auto break case char const continue default do double else enum extern float for go to if int long register return short signed size of static struct switch typed of union while unsigne d void
  • 6. IDENTIFIERS :- Array word/character which a user may use name as a variable name / function name / array name is called idetifiers. Delimete r : Any symbol which a user may use in C programming language is known as delimeter. NAME SYMBOL WORK Semicollon ; Used as a terminator to show the end of statement. Hash # Used as a pre precessor. Comma parenthesis Braces Square Brackets , ( ) { } [ ] Used as a variable seperaor. Used with every function. Used to show the scope of function / statement. Used with Array.
  • 7. TOKEN Smallest unit of C programming language known as token. Token • Variables • Constant • Delimeter • Keyword • Indetifier
  • 8. HEADER FILES : • Header files are used at the top of program. • Header files are collection of different function where each function performs a unique task. • C language supports 30 Header files Example:- 1. <stdio.h> • Standard Input / output Header files. Function defined under <stdio.h.> 1. gets() 2. get c() 3. putc() 4. puts() 5. printf() 6.scanf()
  • 9. 2. <conio.h> • Ful form of <conio.h> is console input /output Header file. • Function defined under <conio.h> are - 1. clrscr() 2. getch() 3.<string.h> • Functions defined <string.h> are - 1. strcpu() 2. strcat() 3. strlur() 4. strupr()
  • 10. 4. <Math.h> Functions defined under <math.h> are - 1. pow() 2. sqrt() 3. abs() 4. sin() 5. fmod() 5. <alloc.h> 1. calloc() 2. malloc() 3. realloc() 4. frec()
  • 11. STRUCTURES OF A C PROGRAM : Software Editor Pre - Processor Source code compiler Linker Loader Output
  • 12. Execution of a C program : Source code in Editor Pre processor Compile Source Code Syntax / Editior linking editior Runtime /logical error Output Input again yes yes yes (logical Error)
  • 13. Data types • It tells us nature of the data. 1. Primary Datatype 2. Secondary Datatype 3. User defined Datatype char int float double void function Array pointer enum structure union
  • 14. Primary Datatypes : FSTSTYPES RAMGE MEMORY REQUIREMENT FORMAT SPECIFIER Signed int -32768 to +32767 2 Bytes %d unsigned int 0 to 65535 2 Bytes %u short int -32768 to +32761 2 Bytes %d long int -2147483648 to +2147483647 4 Bytes %ld signed char -128 to+127 1 Byte %c float 3.4e^-38 to 3.4e^38 4 Byte %f double 1.7e^-308 to 1.7e^38 8 Bytes %lf void no return ___ ___
  • 15. COMPUTER "The oxford defines a computer as an automatic eletronic operator for making calculation or controling operators that are expressible in numerical or logical terms." • Programs Program is a set of instruction. • Software Software is a set of Programmes. • System Software System software is a software interface between system and user. eg: All operating system (Window, linux.)
  • 16. • Application software Other than system software all software are application software. eg : Mcrosoft office, Whatsapp, Twitter, Oracle, Google chrome. • Basic Structure or design of computer CPU ALU MEMORY C.U Memory or brain of computer Input Output • Input devices keyword, mouse, joystic, lightpen, scanner • Output device monitor, printer, hard disk.
  • 17. • CPU actually performs the 3C's : 1. Calcutate 2. compare 3. copy Memory On cheap memory (cache) RAM/ROM Primary memory Secondary Memory
  • 18. ALGORITHMS AND FLOWCHARTS Program = Algorithms + Data "An algorithim is an effective procedure for solving a problems in a finite number of steps". • Key features of an Algo :- Algo having basically three features :- 1. Sequence ( also known as process ) 2. Decision ( also known as selection ) 3. Repeatation (also known as iteration or loop ) eg . for making a part of tea
  • 19. VARIABLES : - In previous Example tea making algo the level of water in a kettle is variable. The temperature of water is a variable and quantity of tea leaves is also a variable. • Tea leaves - quantity • Water - temperature • Different ways of starting algo :- 1. Pseudo - code 2. flow - chart Data Type The data used to algo can be of different types. 2. Alphabetic or Character data : R, A, V, I, 3. Logical Data : True, False
  • 20. Write an algo for finding the sum of any two numbers. 1. START 2. PRINT "ENTER TWO NUMBERS". 3. INPUT "A & B" 4. C = A + B 5. PRINT C 6. STOP Write an algo to print the longest number among three numbers. 1. START 2. PRINT "ENTER THREE NUMBER" 3. INTPUT 4. IF A > B & A > C THEN, PRINT A 5. ELSE B > A & B > C THEN , PRINT B. 6. PRINT C 7. STOP
  • 21. FLOWCHART Flowchart is appropriate step to be followed in order to arrive at the solution to a problem. Flowchart are generally developed in early stage of formulating computer solution. GUIDLINES FOR DRAWING OF FLOW CHART:- Symbol are following :-
  • 22. Symbol are following :- Computational Step or Processing Step Input /Output Decision making Step For connection Srart / End
  • 23. Draw a flow chart to find the sum of first 10 numbers. Start Sum = 0 N =0 N =N+1 n =10 PRINT STOP 1. N =0+1 = 1 SUM = 0+1 =1 2. N = 1+1 =2 SUM = 1+2 =3 3. N = 2+1 = 3 SUM = 3+3 = 6 4. N = 3+1 = 4 SUM = 6+4 = 10 ..................................... ............................. so on n=10 1. sum =0+1= 1 2. sum =1+2= 3 3. sum =3+3=6 4. sum =6+4 =10 5. sum= 10+5=15 6. sum =15+6=21 7. sum =21+7 =28 8. sum =28+8 =36 9. sum =36+9 =45 10. sum= 45+10 =55
  • 24. Write a flowchart to find the largest among three numbers A, B, & C. start Input A,B,C Is B > C ? Is A > B ? Is A > C ? Print B Print C Print A Stop yes yes yes no no no
  • 25. Special Characters :- , comma . period or dot ; semicolumn : colon ' apostrophe " quotation mark ! exclamaton | vertical bar / slash back slash ~ tilde _ under score $ dollar ? question mark & ampersand ^ caret * asterisk - minus + plus < less than > greater than ( ) parenthesis ;eft /right [ ] bracket left /right {} braces left /right % percent # number sign or hash @ at the rate
  • 26. • Printf :- printf( ) is a function that is used to print any data on the video monitor screen. • It has the following form printf(" control - string", list of variables) • Control strings used for different data types -- %c char %d int %u unsigned %hd or %hi short int %ld long int %f float %lf long float %ld long double
  • 27. Types of operator Operator symbol with meaning • Arithmetical uniary : +, - ,++(increment), - -(decrement) binary : + (Addition), - (substraction), *(multiplication), /(division), %(modulus) • Assignment simple assignment : = compund assignment : +=, -+, *=, /=, %=, ^=, |= expressinon assignment : 5 + (b=8+(c=2))-4 • Relational < , > , >=, <= • Equality == (equal to), ! = (not equal to) • Logical && (logical and) || (logical or) ! (logical not)
  • 28. Bitwise & (bitwise and) ! (bitwise or) ~ (complement) ^ (exclusive or) >> (right shift) << (left shift) • Others , (comma) * (indirection) . (membership operation) -> (relationship operation)
  • 29. Write a program of Arithmetic operation #include<stdio.h> #include<conio.h> void main() { int a=100; int b=2; int c=25; int d=4; result=a+b; printf("a+b=%dn", result); result=a-b; printf("a-b=%d n", result); result=a*b; printf("a*b=%d n", result); result=a/b; printf("a/b=%d n", result); getch(); }
  • 30.
  • 31. #include<stdio.h> #include<conio.h> void main() { float A, r; printf("Enter the value of radius r ="); scanf("%f", &r); A=3.14*r*r; printf("The area of given circle is %f" , A); getch(); } Write a program to calculate area of circle
  • 32. #include<stdio.h> #include<conio.h> void main() { int a, b, c; priintf("n enter two numbers"); scanf("%d %d", &a,&b); c=a; a=b; b=c; printf("The answer is %d n",a,b); getch(); } Write a Program inc to swap the two integers using third variable.
  • 33. Write a program in c to swapping two numbers without using third variables or without temporary variables.
  • 34. #include<stsio.h> #include<conio.h> void main() { int a, b ; printf("enter two numbers"); scanf("%d %d , &a,&b); if(a>b) printf("%d", a); else, printf("%d", b); getch(); } Write a program to read two numbers and then display the larger out of these two numbers,
  • 35. A statement is a systamtic construction that performs a action when a program is executed. IF - else :- If r==0 printf|("r having no value"); else priintf("r having same values");
  • 36. Write a program in to check whether a number given by the user is even or odd.
  • 37. #include<stdio.h> #include<conio.h> void main () { int n, r4, r100, r400; printf("enter a number n"); scanf("%d", &n); r4=n%4; r100=n%100; r400=n%400 if(r4==0 && r100!==0 || r400) printf("year is leap year"); else prinitf("It is not a leap year"); getch(); } Write a program to determine a year is a leap year.
  • 38. Write a program to find largest number among three numbers.
  • 39. #include<stdio.h> #include<conio.h> void main() { int x, y, z; printf ("Enter three numbers"); scanf("%d%d%d", &x,&y,&z); if(x<y) if(x<z) printf("x is the smallest"); else printf("z is smallest"); if(y<z) printf("y is smallest); else printf("z is smallest"); getych(); } Write a program to find the smallest number among three numbers.
  • 40. #include<stdio.h> #include<conio.h> void main() { int a, b, c, d; printf("Enter four numbers"); scanf(%d%d%d%d", &a,&b,&c,&d); if(a>b); if(a>c); if(a>d); printf("a is the largest number); else printf("d is the largest number"); if(b>c) If(b>d) printf("b is the largest number"); else printf("d is the largest number"); if(c>d) printf("c is the largest number"); else printf("d is the largest number"); Write a program to find largest number among four numbers.
  • 41. A loop formed by using for statement is generally called definite loop because the programmer knows exactly how many time it will repeat FOR LOOP The general form of statement is as follows- { statement(s) } eg; for(i=0; i<=n; i++)
  • 42. #include<stdio.h> #include<conio.h> void main() { int i, sum=0, n. printf("Enter the value of n"); scanf("%dn" &n); for(i=0; i<=n; i++) { sum=sum+i; } printf("The value of sum", sum); getch(): } Write a program in c to find the sum of n numbers. n=10 1. sum =0+1= 1 2. sum =1+2= 3 3. sum =3+3=6 4. sum =6+4 =10 5. sum= 10+5=15 6. sum =15+6=21 7. sum =21+7 =28 8. sum =28+8 =36 9. sum =36+9 =45 10. sum= 45+10 =55
  • 43. Write a program to find factorial. n =5 1. fact = 1*1 2. fact = 1*2 3. fact = 2*3 4. fact = 6*4 5. fact = 24*5 =120
  • 44. Another construct that is very closely related to the while construct is do-while constuct. DO WHILE CONSTRUCTS The form of this loop constuct is as follows : { //Body of statement placed } while(condition)
  • 45. #include<stdio.h> #include<conio.h> void main() { init i ; i=1; do { printf("RADHE RADHE ") while(i<=7) } } Write a program to print RADHE RADHE using do-while loop.
  • 46. When there are a number of else alternative, another way of representing this multi way selection is by the switch statement. SWITCH CASE SATEMENT :- 1. The switch structures is multi selection structure has allows the handling of even more complicated decision statement, other than a two way if-else statement. It chooses one of the cases depending on the result of the expression. 2. One variable with int or char data type may be used in the expression, sometime called the controlling expression of switch statement.
  • 47. switch(expression) { case value 1: program statement --------------------------; break; case value 2: program statement -----------------------------; break; ...... case value n: program statement; break; default: printf("Entry is invalid"); break; } The general format of switch statement is as follows -
  • 48. Write a program to display the names of the days of a week. case 3: printf("Day is tuesday"); break; case 4: printf("Day is wednesday") break; case 5: printf("Day is thursday"); break; case 6: printf("Day is friday") break; case 7: printf("Day is saturday"); break; case 8: printf("Entry is invalid"); break; } getch(); }
  • 49. C is used the keyword if to execute the set of command lines when the logical condittion is true. The set of command lines are executed only one when the logical condition is true. IF STATEMENT
  • 50. Write a program to check whether entered number is less than 10 ? If yes, display the same. #include<stdio.h> #include<conio.h> void main() { int i ; clrscr(); printf("Enter the value you want to check :"); scanf("%d n", &i); if(i<10) printf("Entered value is <10"); getch(); }
  • 51. Write a program to find Area of triangle using base and height. #include<stdio.h> #include<conio.h> void main() { float base, height, area ; printf("n Enter the base of a triangle "); scanf("%f" , &base); printf("n Enter the height of a triangle "); sscanf"("%f", &height); area=(base*height)/2; printf("n The area of given triangle = %2fn" , area); getch(); }
  • 52. Write a c program to generate first n-prime numbers. #include<stdio.h> #include<conio.h> void main() { int n, i=3, count, c ; printf("How many prime numbers you want to print :"); scanf("%d", &n); printf('first n prime numbers are") for(count=2; count<=n; count++) { for(c=2; c<=i-1; c++) { if(i%c==0) break; } if(c==i) printf("%dn", i); count++; } i++; } return 0; }
  • 53. Write a program to find roots of quadratic equation.
  • 54. if(discriminant>0) { root1=(-b+sqrt(discriminant))/(2*a); root2=(-b-sqrt(discriminant))/(2*a); printf("root1=%f and root2=%f", root1, root2); } //Condition for Real and different Root :- //Condition for real and Equal root if(discriminant==0) { root1=root=-b/2*a); printf("root1=root2=%f", root1); }
  • 55. else { real part==-b/(2*a); image part=squrt(-discriminant)/(2*a); printf("root1=%f %f i and root2=%f %f i", real part, image part, real part, image part); } return 0; } //If roots are not Real
  • 56. #include<stdio.h> #include<math.h> int is perfect (unsigned long log int n) { unsigned long long int dsum=0 ; unsigned long long int i ; for(i=1; i<=sqrt(n); ++i) { if(n%i==0) { if(i==n/i) } else { dsum=dsum+i; Write a program to generate first n perfect number. dsum=dsum+n/i; } } } dsum=dsum-n; if(dsum==n) return 1; else return 0; }
  • 57. int main() { unsigned long long int n, i,temp; printf("Enter n "); scanf("%llu", &n); i=1; while(n>0) { if(is perfect(i)==1) printf("%llu", i); n=n-1; } i=i+1; return 0; }
  • 58. Write a c program to evaluate sinx and cosx up to n terms using Taylor's series. #include<stdio.h> #include<sonio.h> void main() { int i, n; float x, sum_cos=1, sum_sin, t=1; printf("Enter the value of x"); scanf("%f, &x); printf("Enter the llimit t /term to which series should be evaluated); scanf("%d", &n); x=x*8.14159/180; /*loop to calculate value of cos in series */
  • 59. t=(t*(-1)*x*x)/2*i*(2*i-1)); sum_cos=sum_cos+t; } t=x; sum_sin=x; /*loop to calculate value of sin series */ for(i=1; i<=n; i++) { t=(t*(-1)*x*x/(2*i*(2+t+1)); sum_sin=sum_sin+t; } printf("The value of cos(7.f) is : %0.4 f/n", x, sum_cos); printf("The value of sin (%f) is %0.4f", x, sum_sin); getch();
  • 60. Write a Program in c to print addition & multiplication of two matrices of order m*n. #include<stdio.h> #include<conio.h> void main() { int a[10][10], b[10][10], c[10][10], m, n, i, j ; printf("Enter the value of row m and column n of matrices"); scanf("%d%d", &m,&n); printf("Enter the element of matrix a"); for(i=0; i<=(m-1); i=i+1) { for(j=0; j<=(n-1); j++) { scanf("%d", &a[i][j]); }}
  • 61. printf("Enter the element of matrix b"); for(i=0; i<=(m-1); i++) { for(j=0; j<=(m-10); j=j+1) { scanf("%a", &b[i][j]); }} printf("matrix a is n"); for(i=0; i<=(m-1); i+1) { for(j=0; j<=(n-1); j+1) { printf("dt", a[i][j]); } printf("n"); } printf("matrix b is n"); for(i=0; i<=(m-1); j=j+1) { for(j=0; j<=(n-1); j=j+1) { printf("%dt", b[i][j]);
  • 62. } printf("n"); } for(i=0; i<=(m-1); i=i+1) { for(j=0; j<=(n-1); j=j+1) { c[i][j]=a[i][j]+b[i][j]; }} printf("rrsulted matrix after addition"); for(i=0; i<=(m-1); i=I=1) { for(j=0; j<=(n-1); j=j+1) { printf(%dt", c[i][j]) } printf("n); } int k; for(i=0; i<m; i++) { for(k=0; k<=(n-1); k=k+1) { c[i][j]=c[i][j] + a[i][j]*b[k][j]; }} priintf("matrix after multipllication is n"); for(i=0; i<m; i++) { for(j=0; j<n; j++) { printf("%dt", c[i][j]); } printf(''n"); } getch(); }
  • 63. Write a program in c to print Transpose of a matrix of order n*n. #include<stdio.h> #include<conio.h> void main() { int a[10][10], n, m,i, j ; printf("Emter value of row m & colum n : "); scanf("%d%d", &m, &n); printf("Enter the element of matrix a : "); for(i=0; i<=(m+1); i++) { for(j=0; j<=(n-1); j=j+1 { scanf("%d", &a[i][j]); }}
  • 64. #include<stdio.h> main() { int i, j; for(i=1; i<=5; i++) { for(j=1; j<=i; j++) { printf(%d", i); } printf("n"); } } 1 22 333 4444 55555 Write a prigramme to print :
  • 65. for((i=0; i<=(m-1); i=i++) { for(j=0; j<=(n-1); j=j++) { printf(%dt", a[i][j]); } printf("n") } printf("Transpose is : n "); for(i=0; i<=(n-1); i=i+1) { for(j=0; j<=(m-1); j=j+1) { printf("%dt", a[j][i]); } printf("n"); } jgetch();
  • 66. #include<stdio.h> main() { int i, j; for(i=1; i<=5; i++) { for(j=1; j<=i; j++) { print("%d", j); } printf("n"); } } Write a programe to print 1 12 123 1234 12345
  • 67. QUESTION BANK QUESTIONS Write a program to take a five digits number and find the sum of the digit of the number. #include<stdioi.h> #inclulde<conio.h> void main() { int n, r, sum=0 ; priintf("Enter the number of five digits"); scanf("%d", &n); while(n>0) { r=n%10; sum=sum+r; n=n=n/10; } printf("sum of digits = %d", sum); getch(); }
  • 68. Write a program to find the product of two matrices. #include<stdio.h> #include<conio.h> void main() { int a[2][2], b[2][2], c[2][2], i, j, k, sum; printf("Enter four values for 1st matrix''); for(i=0; i<2; i++) { for(j=0; f<2; j++) scanf("%d", &a[i][j]); } printf("Enter four values for 2nd matrix''); for(i=0; i<2; i++) { for(j=0; j<2; j++) { scanf("%d", &b[i][j]); }} for(i=0; i<2; i++0) { for(j=0; j<2; j++) { sum=0; } for(k=0; k<2; k++) { sum=sum+a[i[]k]*b[k][i]; c[i][j] = sum; }} printf("product of matrix is "); for(i=0; i<2; i++) { for("j=0; j<2; j++); printf("%dt", c[i][j]); printf("n"); } getch(); }
  • 69. What is union? How it differs from structure? Definition of union A union is a user defined type in which all members share the same memory location, this means that at any given time a union can contain no more than one object from its list of members. It also means that no matter how many members a union has. It always uses only enouygh memory to share the largest member. Differnnce between union and structure Strucfture 1. The keyword struct is used to defined a structure. 2. When a variable is associate with a structure the compiler allocates the memory for each member. The size of structure is greater than or equal to sum of sizes ofits member. 3. Each member with a structure is assigned uniquestrange area of location Union 1. The keyword union is used to defined union. 2. When a variable is associated with a union the compiler allocates the memory by considering size of the largest memory. So size of union is equal to size of largest member. 3. Memory allocation is shared by individuals a member if union. 4. Altering the values of any of the member will alter other member values.
  • 70. 4. Altering the value of a member will not alter other members of the structre. 5. Individual member can be accessed at a time. 6. Several members of a structure can initialize at once. 5. Only one member can be accessed at a time. 6. Only the first member of a union can be initialize. Write the difference between logical operator and Bitwise operator. Bitwise operator 1. Its symbol is '&'. 2. It evaluates both left and right side of expression. 3. It operates on "Boolean data type " as well as operates on "bits". 4. It use to check logical condition and also used to mask offcertain bits such as parity bits. Logical operators 1. Its symbol is '&&'. 2. Its only evaluates the left side of the expression. 3. It operates only on "Boolean datatypes". 4. It uses to only check.
  • 71.
  • 72. What is recursion? What are its advantages? How it is excuted. Explain with the help of an example. A recursive function is a function that calls itself to perform a specific operation. The process of a function calling itself is known as recursion. In other word, A function is called recursive when it calls itself there is always if statement in recursive function to force the function to return without recursive call being exacated otherwise the function goes in indefinite loop. Advantages of recursion:- Through recursion we can solve the problem in easy way while its interative solution is very big and complex. It is useful to step through the function observing what value gets returned with each call.
  • 73. Execution with example :- Recursion in C for factorial - #include<stdio.h> #include<conio.h> int fact(int); void main() { int n; int res; priintf("Enter a numner"); scanf("%d", &n); res=fact(n); printf("factorial is =%d", res); } int fact(int x) { int f: if(x==1) return(1); else f=x*fact(x-1); return(f); }
  • 74. What is looping ? Explain the syntax of while loop by taking an example. Looping :- Looping is a concept that is applied in programming in general. It is the way to execute a set of instructions any number of times. In C the loopiing concept can be applied using - 1. While loop 2. Do - while loop 3. Go to sattement. While loop is also known as entry controlled loop as the condition to be checked is given before the statements that are to be iterated. Syntax for a while loop is -
  • 75. for example :- #include<stdio.h> #Include<conio.h> void Main() { int i=0; while (i<5) { printf("%d", i); i++; getch(); } 01234