C PROGRAMMING
CONTENT
UNIT
1: FUNNDAMENTALS OF C PROGRAMMING LANGUAGE
History of c Language and its advantage
Simple Structure of programming
language
Character set
C-Token
Data types of C
Operators of C
Examples of program
UNIT 2: DECISION MAKING
AND BRANCHING
If Statement
Switch Statement
Conditional Statement
Goto Statement
UNIT 3: DECISION MAKING AND LOOPING
Do-while Loop
While Loop
For Loop
Break
Continue
UNIT 4: ARRAY
One Dimensional Array
Two Dimensional Array
Advantage and Disadvantage of array
UNTIT 5: CHARACTER ARRAY
Basics of Character array
Programs related to character array
UNIT 6:
STRING HANDLING FUNCTION
Strcat() Function
Strcmp() Function
Strcpy() Function
Strlen() Function
Strrev() Function
Strupr Function
Strlwr Function
Programes
UNIT 7: USER DEFINED FUNCTION
Advantage of Function
Defining
a Function
Top
Down approach
Function
prototype
Bottom
up approach
Categories
of Function
Recursion
UNIT 8: POINTER
Pointer and its advantage
How to use pointer
Pointer
to pointer
UNIT 9: STRUCTURE AND UNION
Declaration of structure
Union
UNIT10: FILE
HANDLING
Ascil text file
Binary files
How
to use file
UNIT 11:
STORAGE CLASSES AND MACROS
Scope of Identifiers
Storage
class
Macro
substitution
UNIT -1
FUNDAMENTALS OF C-LANGUAGE
1. HISTORY OF C LANGUAGE
a) The Mother of all the modern languages is ALGOL(ALGOrithmic Language). It was
developed in 1960 by International Group.
b) In 1967 BCP(Basic Combined programming Language ) was developed by Martin Richards.
c) In 1970 ken Thompson developed a language called 'B' language.
d) C Language was developed by Dennis Ritchie at AT & T Bell Laboratiories in 1972.
2. RESASPM BEJOMD THE DEVELOPMENT OF C LANGUAGE
Initially Unix the Lack developed by ken Thompson In Machine Language.
But due to the Lack of portability it was not used in some machine.
In order to overcome this Limitation, Dennis Ritche needs a new language that would create
fast, efficient and compact programs that controls the hardware efficiently. This necessity
invented the development of new high level language called 'C' . So its initial aim was to
make Unix a portable.
But due to the Lack of portability it was not used in some machine.
In order to overcome this Limitation, Dennis Ritche needs a new language that would create
fast, efficient and compact programs that controls the hardware efficiently. This necessity
invented the development of new high level language called 'C' . So its initial aim was to
make Unix a portable.
3. IMPORTANCE OF C LANGUAGE
C lang is a famous programming lang due to its qualities. Some qualities r:
(1)it is robust lang whose rich setup of built in functions and operator can be used to write any complex prog.
(2)prog written in c are efficient due to severals variety of data types and powerful operators.
(3)the c complier combines the capabilities of an assembly lang with the feature of hige level language. Therefore it is well suited for writing both system software and business package.
(4)there r only 32 keywords, severals standard functions r available which can be used for developing prog.
(5)c is portable lang , this means that c programes written for one computer system can be run on another system, with little or no modification.
(6)c lang is well suited for stuctured programming, this requires user to think of a problems in terms of function or modules or block. A collection of these modules make a program debugging and testing easier.
(7)c language has its ability to extend itself. A c program is basically a collection of functions that are supported by the c library. We can contuniously add our own functions to the library with the avaibility of the large number of functions.
In india and abroad mostly people use c programming lang becoz it is easy to learn and understand.
4. A SIMPLE EXAMPLE OF C PROGRAMMING
/* Program- simple.c*/ /*comment statement*/
#include<stdio.h> /*reprocessor directive*/
void main() /*a function heading*/
{
printff ("simple program of C language") /* statement*/
}
Here the program simple.c has following elements.
a) source code comments, indicated by /* */.
b) A preprocessor # include directive.
c) A function heading: void main().
d) A function body enclosed within { and }.
e) A statement that writes a message on the screen.
The above program is explained below:
4.1 comment: In the C Programming Language, you can place comments in your code that are not executed as part of the program. A comment starts with /* symbol and ends with */ and can be anywhere in your program. Comments can span several lines within your C program.
comment on c language is given as /*.........................................*/
comment begin with /* character sequence and continue through the */ character sequence as following.
/* this is my book*/
4.2 main () Function
In many programming languages, the main function is where a program starts execution. It is responsible for the high-level organization of the program's functionality, and typically has access to the command arguments given to the program when it was executed.
note:- If you don't have main(), your program will be complied successfully, but it will not run and complier
will report that you have not defined a main() function.
4.3 The C preprocessor directives : #include
C uses a preprocessor. A preprocessor is a program that processes a source file before the main compliation
takes place. C handles direcives whose names begins with a number sign # .
The # include directive tells the compiler to include a different source-code file in your program. This directive
tells the compiler to add the contents of the stdio.h file into our source. file . This action of preprocessor is
similar to pasting a block of text data into a doucument with your word processor.
5. CHARACTER SET
Characters are collectively used to write the program by forming words, letters, numbers etc.
so C characters can be grouped into three categories:-
IN C-TOKEN
1. Keywords:- Keywords have the fixed meaning and these meanings cannot be
changed and we can also say that these are reserve words having
fixed meaning .
For example of keywords are:
List of all Keywords in C Language
32 keywords in C
auto
2. Identifiers:- it is the name of variable, Functions and
Arrays.
constanst meaning
comment on c language is given as /*.........................................*/
comment begin with /* character sequence and continue through the */ character sequence as following.
/* this is my book*/
4.2 main () Function
In many programming languages, the main function is where a program starts execution. It is responsible for the high-level organization of the program's functionality, and typically has access to the command arguments given to the program when it was executed.
note:- If you don't have main(), your program will be complied successfully, but it will not run and complier
will report that you have not defined a main() function.
4.3 The C preprocessor directives : #include
C uses a preprocessor. A preprocessor is a program that processes a source file before the main compliation
takes place. C handles direcives whose names begins with a number sign # .
The # include directive tells the compiler to include a different source-code file in your program. This directive
tells the compiler to add the contents of the stdio.h file into our source. file . This action of preprocessor is
similar to pasting a block of text data into a doucument with your word processor.
5. CHARACTER SET
Characters are collectively used to write the program by forming words, letters, numbers etc.
so C characters can be grouped into three categories:-
- Letters
- Digits
- Special Characters
Letters :
- C language comprises the following set of letters to form a standard program. They are :
- A to Z in Capital letters.
- a to z in Small letters.
Digits :
C language comprises the following sequence of numbers to associate the letters.
0 to 9 digits.
Special Characters:
C language contains the following special character in association with the letters and digits.
| Symbol | Meaning |
| ~ | Tilde |
| ! | Exclamation mark |
| # | Number sign |
| $ | Dollar sign |
| % | Percent sign |
| ^ | Caret |
| & | Ampersand |
| * | Asterisk |
| ( | Lest parenthesis |
| ) | Right parenthesis |
| _ | Underscore |
| + | Plus sign |
| | | Vertical bar |
| \ | Backslash |
| ` | Apostrophe |
| - | Minus sign |
| = | Equal to sign |
| { | Left brace |
| } | Right brace |
| [ | Left bracket |
| ] | Right bracket |
| : | Colon |
| " | Quotation mark |
| ; | Semicolon |
| < | Opening angle bracket |
| > | Closing angle bracket |
| ? | Question mark |
| , | Comma |
| . | Period |
| / | Slash |
IN C-TOKEN
(1) keywords
(2) Constants
(3) Identifiers
(4) Strings
(5) Special Symbols
(6) Operators 1. Keywords:- Keywords have the fixed meaning and these meanings cannot be
changed and we can also say that these are reserve words having
fixed meaning .
For example of keywords are:
List of all Keywords in C Language
32 keywords in C
auto
break
case
char
conset
continue
default
do
double
else
enum
extern
float
for
goto
if
int
long
register
return
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while
e.g:- int x;
int a[10];
void getdata();
float *x;
Rules for identifiers
- Fist Character must be alphabet or underscore.
- Must consist of only letters, digits, or underscore.
- Must have only 31 characters.
- Must not have white space.
- It should not be a keyword.
3. Constants:- It has the fixed meaning and it does not change during the execution
of program.
e.g:- 2(Integer constant). 7.24 (Real
constant), ‘c’ (Character constant), “Ranjan”
(String constant).
Constants are two type:
1. Numeric constants
2. Character constants
Numeric constants are also two type:
1. Interger constant
2. Real constants
Character constants two type:
1. Single character constants
2. String constants
4.String:- Anything written in quotation marks " " is called String.
e.g " Ranjan kumar sharma"
constanst meaning
'\a Audible alert(bell)
'\b Back space
'\f from feed
'\n New line
'\r' Carriage return
'\t' Horizontal tab
'\v' Vertical tab
'\" Single quote
'\"' Double quote
'\?' Question mark
'\\' Backslash
'\0' Null
Special Symbol: are {,},>,<,;,= etc
Operator : operator decide what operation is to be performed in the given set data.
for example.... +,-,*,/ etc
Data types of C
In c programming we have to deal with various types of data , hence it is necessary for a
programmer to select an appropriate data type according to the data taken in a program.
Data types
There are three types of data type:
(1) primary or fundamental data types(int,char,and float)
(2) Derived data types (pointer, array, function)
(3) User defined data types (structure, union)
primary Data type: The data types, which is independent of any other type,are
known as primitive Data Type or primary data types. These also called Basic Data types.
for examples.....int, long,,,float,,,,double,,,etc...
Derived Data types
Such Data types are derived from primary data types. examples of derived data types are
functions array and pointer. These topics will be discussed in next chapters.
User Defined Data types
Such Data types are defined by user and they are directly or indirectly dependent upon
primary or derived data types. for examples.....structure....union,,,,,typedef,,,enumerated
data types
Operators of C
An operators is a symbol that tells the computer to perfom cerfom cetain mathematical or
logical manipulations. Operators are used in programs to manipulate data and variables.
They usually from a part of mathematical or logical expressions.
Arithmetic operators
Special Symbol: are {,},>,<,;,= etc
Operator : operator decide what operation is to be performed in the given set data.
for example.... +,-,*,/ etc
Data types of C
In c programming we have to deal with various types of data , hence it is necessary for a
programmer to select an appropriate data type according to the data taken in a program.
Data types
There are three types of data type:
(1) primary or fundamental data types(int,char,and float)
(2) Derived data types (pointer, array, function)
(3) User defined data types (structure, union)
primary Data type: The data types, which is independent of any other type,are
known as primitive Data Type or primary data types. These also called Basic Data types.
for examples.....int, long,,,float,,,,double,,,etc...
Derived Data types
Such Data types are derived from primary data types. examples of derived data types are
functions array and pointer. These topics will be discussed in next chapters.
User Defined Data types
Such Data types are defined by user and they are directly or indirectly dependent upon
primary or derived data types. for examples.....structure....union,,,,,typedef,,,enumerated
data types
Operators of C
An operators is a symbol that tells the computer to perfom cerfom cetain mathematical or
logical manipulations. Operators are used in programs to manipulate data and variables.
They usually from a part of mathematical or logical expressions.
Arithmetic operators
operator
Meaning
+
Addition or unary plus
-
Subtraction or
unary minus
*
Multiplication
/
Division
%
Modulo division
Relational Operators
Operator
Meaning
<
Is less than
<=
Is less than or equal to
>
Greater than
>=
Greater than or equal to
==
Is equal to
!=
Is not equal to
Logical
operators
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT
Assignment
Operators
Statement
with simple
Statement with shorthand
Assignment operator operator
a=a+1 a+=1
a=a-1 a-=1
a=a*(n+1) a*=n+1
a=a/(n+1) a/=n+1
a=a%b a%=b
Symbol Meaning
+= Addition assignment
-= Subtraction assignment
*= Multiplication assignment
/= Division assignment
%= Modulus assignment
Increment
and decrement operators
C
provides the ++ increment and decrement – operators ,increment
or
decrement the variable by the value if
Operator Meaning
++ Increment
__ Decrement
Conditional
operators or Ternary operator
A
ternary operator pair “?:” is available in c to construct conditional
Expressions
of the form (condition)?
Example
:
a=10;
b=15;
x=(a>b)?
a:b;
In
the above example ‘a’ is not greater than ‘b’,so condition is not
Satisfied
the value of b =15 will assigned to the variable ‘x’.
Bitwise
operations
Operator Meaning
& Bitwise
AND
| Bitwise
OR
^ Bitwise
EX- OR
<< Shift
left
>> Shift
right
Explanation
A.
Logical
AND:
Logical AND table
X Y X&Y
0 0 0
0 1 0
1 0 0
1 1 1
Example
a= 12 = 1100(use binary value)
b= 10 = 1010
______
a&b = 1000=8 (decimal)
B Logical OR:
Logical OR table
X y x/y
0 0 0
0 1 1
1 0 1
1 1 1
Example:
a=12=1100(use binary value)
b=10=1010
______
a/b = 1110=14(decimal)
C Exclusive OR:
Exclusive OR:
Exclusive OR table
X y x^y
0 0 0
0 1 1
1 0 1
1 1 0
Example
a=12 =1100 (use binary value)
b= 10 =1010
________
a^b= 0110=6(decimal)
1. simple program of c
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("This is my First Page");
getch();
}
output:- This is my First Page
2. wap to add two numbers ?
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
clrscr();
printf("Enter two number :");
scanf("%d%d",&x,&y(;
z=x+y;
printf("sum=%d",z);
getch();
}
3. wap to find the compound Interest.
#Include<stido.h>
#Include<conio.h>
void main()
{
float si,p,r,t;
clrscr();
printf("Enter priciple ,rate and time");
scanf("%f%f%f",&p,&r,&t);
si=(p*r*t)/100;
printf("Simple Interest :%f",si);
getch();
}
Output:
Enter principle , rate, and time
2000
2
12
simple Interest 480.000000
3. wap to find the compound Interest.
#Include<stido.h>
#Include<conio.h>
void main()
{
float si,p,r,t;
clrscr();
printf("Enter priciple ,rate and time");
scanf("%f%f%f",&p,&r,&t);
si=(p*r*t)/100;
printf("Simple Interest :%f",si);
getch();
}
Output:
Enter principle , rate, and time
2000
2
12
simple Interest 480.000000
4. wap to find the Compound Interest.
#include<stdio.h>
#include<conio.h>
void main()
{
float ci
clrscr();
printf("principle ,rate, and time");
scanf("%f%f%f",&p,&r,&n);
a=p*pow((1+r/100),n);
ci=a-p;
printf("compound Interest =%f",ci);
getch();
}
Output :
Enter principle , rate, and time
2000
10
12
compond Interest =4276.856934
5. wap to enter a number and display its octal and Hexadecimal form.
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
clrscr();
printf("Enter a number :");
scanf("%d",&x);
printf("octal form=%o",x);
printf("Hexadecimal form=%x",x);
getch();
}
output:
enter a number =121
octal form=171Hexadecimal form=79
6. wap to find the volume of cylinder.
#include<stdio.h>
#include<conio.h>
void main()
{
float r,h,v;
printf("Enter radius & height of cylinder");
scanf("%f%f",&r,&h);
v=3.14*r*h;
printf("volume=%f",v);
getch();
}
output:
Enter radius & height of cylinder
2
10
volume =125.599998
7. wap to find the diagonal a Rectangle.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,d,t;
clrscr();
printf("Enter sides of Rectangle :");
scanf("%d%d",&a,&b);
t= a*+b*b;
d= sqrt(t);
printf("Diagonal of rectange = %d",d);
getch();
}
8. wap to find the temperature in Fahrenheit when temperature is given in Celsius.
#include<stdio.h>
#include<conio.h>
void main()
{
float c,fh;
clrscr();
printf("Enter temperature in celcius :");
scanf("%df",&c);
fh=(9*c/5+32);
printf("Temperature in Fahrenhiet=%f",fh);
getch();
}
9. wap to illustrate Increment &decrement operator
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
x=3;
y=5;
++x;
printf("Incremental value of x=%d",x);
--y;
printf("decremental value of y=%d',y);
getch();
}
10. wap to calculate the displacement when initial velocity, time and acceleration is
by the user.
#include<stdio.h>
#include<conio.h>
void main ()
{
float s, u, t, a;
clrscr();
printf("Enter initial velocity, time and acceleration :');
scanf("%f%f%f",&u,&t,&a);
s=u*t+a*t*t/2;
printf("displacement =%f",s);
getch();
}
11. wap to illustrate Bitwise operator program
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,p,q,r,s,t;
clrscr();
a=12;
b=10;
p=a&b;
q=a/b;
r=a^b;
s=a>>2;
t=a<<2;
printf("\n Bitwise AND=%d",p);
printf("\n Bitwise OR=%d",q);
printf("\n Bitwise Exclusive=%d",r);
printf("\n Shift Right=%d",s);
printf("\n Shift Left=%d",t);
getch();
}
12. wap to swap two numbers using third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,t;
clrscr();
printf("Enter value of x and y:");
scanf("%d%d",&x,&y);
t=x;
x=y;
y=t;
printf("After swapping");
printf("\n x=%d",x);
printf("\n y=%d",y);
getch();
}
13. wap to swap two numbers without using third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
printf("Enter two numbers");
scanf("%d%d",&x,&y);
x=x+y;
y=x-y;
x=x-y;
printf("After swap ");
printf("x=%d",x);
printf("\n y=%d",y);
getch();
}
14. wap tocheck greatest among two numbes using conditional operator.
#include<stido.h>
#includes<conio.h>
void main()
{
int x,y,t;
clrscr();
printf("Enter two numbers");
scanf("%d%d",&x,&y);
t=(x>y)?x:y;
printf(""Greatest=%d",t);
getch();
}
15. wap to find the sum of 'n' natural numbers without using loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum;
clrscr();
printf("Enter value of n");
scanf("%d",&n);
printf("sum if n natural numbers=%d",sum);
getch();
}
16. wap to show the days and the numbes of days in a week using enumeration .
#include<stdio.h>
#include<conio.h>
void main()
{
enum weak
{
sunday,monday,tuesday, wednesday, thursday,friday,saturday
};
clrscr();
printf("\n sunday=%d", sunday);
printf("\n moday=%d", monday
printf("\n tuesday=%d", tuesday);
printf("\n wednesday=%d",wednesday);
printf("\n thursday=%d", thursday);
printf("\n friday=%d", friday);
printf("\n saturdat=%d", saturday);
getch();
}
17. wap to show your resume throw hello programs.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(" RESUME ");
printf("\n\n\nRANJAN KUMAR SHARMA");
printf("\n\nC/o:BINAY KUMAR SHARMA");
printf("\n\nCity:-Gandhi nagar gali-6");
printf("\n\nDehri-on-sone Rohtas(Bihar");
printf("\n\nEmail-Sharmaranjan743@gmail.com");
printf("\n\n-9122466534,9772073824,");
printf("\n____________________________________________________________");
printf("\n\n\n\nCareer Prospective:");
printf("\n__________________");
printf("\n\n\n");
printf("To grab every opportunity at right time to achieve my target.Give");
printf("\nmy 100% to make place for myself.To meet organizational objectiv");
printf("\nthrough hard work and integrity.");
printf("\n\n\ncareer highlight/qualification:");
printf("\n______________________________");
printf("\n\n\n10+2 :From J.J.College Rohtas(Bihar) wiht 68% in COMMERCE IN 2009");
printf("\n\n\nMatriculation :From Dehri hight school Rohtas(Bihar)with 59% in 2007");
printf("\n\n\nProfessional Qualification:");
printf("\n_________________________");
printf("\n\n\nBCA :Pursuing in 6th semester");
printf("\n\n :Birsa Institute of technology (trust)");
printf("\n\n :Ranchi,JHARKHAND");
printf("\n\n\nProfessional Qualification");
printf("\n__________________________");
printf("\n\n\nHobbies:");
printf("\n_______");
printf("\n\n Net surffing");
printf("\n\n Operating Pc");
printf("\n\n\nPersonal Information:");
printf("\n____________________");
printf("\n\n Father's Name :Mr BINAY KUMAR SHARMA");
printf("\n\n Date of birth :2-jan-1992");
printf("\n\n Marital Status :Single");
printf("\n\n Language know :Hindi,English");
printf("\n\n\nInterpersonal Skill:");
printf("\n__________________");
printf("\n\n co-opertive,Flexible and Reliable");
printf("\n\n\nDeclaration:");
printf("\n___________");
printf("\n\n\n");
printf(" I here by declare that the above mentioned information is");
printf("\ncorrect and that to the best of my knowledge and belief.I self");
printf("\nbear the responsiblity for the correction of the above men-");
printf("\ntioned partcular.");
printf("\n\n\n\n\n\nDate (signature of candidate");
printf("\n\n\n\n\n\n Ranjan kumar sharma");
getch();
}
UNIT 2: DECISION MAKING AND BRANCHING
One of the keys to designing intelligent programs is to make them able to make decisions, such
as whether you are going to see a movie or not, whether to play a cricket match or not, whether
you want to go on a long journey, and if so by the train or by the air.
Like these activities programs also need to decide among alternative
Actions, such as whether the year is a leap or not, whether the number is even or odd, and so
on. Thus there is the possibility of changing the seqyebce of statements. based on these
decisions.
There are four types of decision making and branchin statement:
1. IF STATEMENT
2. SWITCH STATEMENT
3. CONDITIONAL OPERATOR STATEMENT
4. GOTO STATEMENT
7. wap to find the diagonal a Rectangle.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,d,t;
clrscr();
printf("Enter sides of Rectangle :");
scanf("%d%d",&a,&b);
t= a*+b*b;
d= sqrt(t);
printf("Diagonal of rectange = %d",d);
getch();
}
8. wap to find the temperature in Fahrenheit when temperature is given in Celsius.
#include<stdio.h>
#include<conio.h>
void main()
{
float c,fh;
clrscr();
printf("Enter temperature in celcius :");
scanf("%df",&c);
fh=(9*c/5+32);
printf("Temperature in Fahrenhiet=%f",fh);
getch();
}
9. wap to illustrate Increment &decrement operator
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
x=3;
y=5;
++x;
printf("Incremental value of x=%d",x);
--y;
printf("decremental value of y=%d',y);
getch();
}
10. wap to calculate the displacement when initial velocity, time and acceleration is
by the user.
#include<stdio.h>
#include<conio.h>
void main ()
{
float s, u, t, a;
clrscr();
printf("Enter initial velocity, time and acceleration :');
scanf("%f%f%f",&u,&t,&a);
s=u*t+a*t*t/2;
printf("displacement =%f",s);
getch();
}
11. wap to illustrate Bitwise operator program
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,p,q,r,s,t;
clrscr();
a=12;
b=10;
p=a&b;
q=a/b;
r=a^b;
s=a>>2;
t=a<<2;
printf("\n Bitwise AND=%d",p);
printf("\n Bitwise OR=%d",q);
printf("\n Bitwise Exclusive=%d",r);
printf("\n Shift Right=%d",s);
printf("\n Shift Left=%d",t);
getch();
}
12. wap to swap two numbers using third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,t;
clrscr();
printf("Enter value of x and y:");
scanf("%d%d",&x,&y);
t=x;
x=y;
y=t;
printf("After swapping");
printf("\n x=%d",x);
printf("\n y=%d",y);
getch();
}
13. wap to swap two numbers without using third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
printf("Enter two numbers");
scanf("%d%d",&x,&y);
x=x+y;
y=x-y;
x=x-y;
printf("After swap ");
printf("x=%d",x);
printf("\n y=%d",y);
getch();
}
14. wap tocheck greatest among two numbes using conditional operator.
#include<stido.h>
#includes<conio.h>
void main()
{
int x,y,t;
clrscr();
printf("Enter two numbers");
scanf("%d%d",&x,&y);
t=(x>y)?x:y;
printf(""Greatest=%d",t);
getch();
}
15. wap to find the sum of 'n' natural numbers without using loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum;
clrscr();
printf("Enter value of n");
scanf("%d",&n);
printf("sum if n natural numbers=%d",sum);
getch();
}
16. wap to show the days and the numbes of days in a week using enumeration .
#include<stdio.h>
#include<conio.h>
void main()
{
enum weak
{
sunday,monday,tuesday, wednesday, thursday,friday,saturday
};
clrscr();
printf("\n sunday=%d", sunday);
printf("\n moday=%d", monday
printf("\n tuesday=%d", tuesday);
printf("\n wednesday=%d",wednesday);
printf("\n thursday=%d", thursday);
printf("\n friday=%d", friday);
printf("\n saturdat=%d", saturday);
getch();
}
17. wap to show your resume throw hello programs.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(" RESUME ");
printf("\n\n\nRANJAN KUMAR SHARMA");
printf("\n\nC/o:BINAY KUMAR SHARMA");
printf("\n\nCity:-Gandhi nagar gali-6");
printf("\n\nDehri-on-sone Rohtas(Bihar");
printf("\n\nEmail-Sharmaranjan743@gmail.com");
printf("\n\n-9122466534,9772073824,");
printf("\n____________________________________________________________");
printf("\n\n\n\nCareer Prospective:");
printf("\n__________________");
printf("\n\n\n");
printf("To grab every opportunity at right time to achieve my target.Give");
printf("\nmy 100% to make place for myself.To meet organizational objectiv");
printf("\nthrough hard work and integrity.");
printf("\n\n\ncareer highlight/qualification:");
printf("\n______________________________");
printf("\n\n\n10+2 :From J.J.College Rohtas(Bihar) wiht 68% in COMMERCE IN 2009");
printf("\n\n\nMatriculation :From Dehri hight school Rohtas(Bihar)with 59% in 2007");
printf("\n\n\nProfessional Qualification:");
printf("\n_________________________");
printf("\n\n\nBCA :Pursuing in 6th semester");
printf("\n\n :Birsa Institute of technology (trust)");
printf("\n\n :Ranchi,JHARKHAND");
printf("\n\n\nProfessional Qualification");
printf("\n__________________________");
printf("\n\n\nHobbies:");
printf("\n_______");
printf("\n\n Net surffing");
printf("\n\n Operating Pc");
printf("\n\n\nPersonal Information:");
printf("\n____________________");
printf("\n\n Father's Name :Mr BINAY KUMAR SHARMA");
printf("\n\n Date of birth :2-jan-1992");
printf("\n\n Marital Status :Single");
printf("\n\n Language know :Hindi,English");
printf("\n\n\nInterpersonal Skill:");
printf("\n__________________");
printf("\n\n co-opertive,Flexible and Reliable");
printf("\n\n\nDeclaration:");
printf("\n___________");
printf("\n\n\n");
printf(" I here by declare that the above mentioned information is");
printf("\ncorrect and that to the best of my knowledge and belief.I self");
printf("\nbear the responsiblity for the correction of the above men-");
printf("\ntioned partcular.");
printf("\n\n\n\n\n\nDate (signature of candidate");
printf("\n\n\n\n\n\n Ranjan kumar sharma");
getch();
}
UNIT 2: DECISION MAKING AND BRANCHING
One of the keys to designing intelligent programs is to make them able to make decisions, such
as whether you are going to see a movie or not, whether to play a cricket match or not, whether
you want to go on a long journey, and if so by the train or by the air.
Like these activities programs also need to decide among alternative
Actions, such as whether the year is a leap or not, whether the number is even or odd, and so
on. Thus there is the possibility of changing the seqyebce of statements. based on these
decisions.
There are four types of decision making and branchin statement:
1. IF STATEMENT
2. SWITCH STATEMENT
3. CONDITIONAL OPERATOR STATEMENT
4. GOTO STATEMENT
very nice
ReplyDeleteThanx bhai....
Deletehii
ReplyDelete