0% found this document useful (0 votes)
77 views

C Programming @home

The document discusses various C programming concepts including variables, data types, conditional statements like if and if-else, and loop statements like for. It provides examples of declaring different variable types like char, int, float and using conditionals and loops. The key concepts covered are data types, if/if-else statements, and for loops along with examples of printing patterns using loops.

Uploaded by

PalmDINO
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
77 views

C Programming @home

The document discusses various C programming concepts including variables, data types, conditional statements like if and if-else, and loop statements like for. It provides examples of declaring different variable types like char, int, float and using conditionals and loops. The key concepts covered are data types, if/if-else statements, and for loops along with examples of printing patterns using loops.

Uploaded by

PalmDINO
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 25

C Programming

BSRU@Home

C-01/24-03-55
Variables
char
int
float

Condition statement
if() , if().. else

Loop statement
for()

printf() statement
3/24/2012

Variables
char

a, A, b, B

Int

100, 125, -165

Float

3/24/2012

10.5, -34, -1.5, 31.0


10

int

*(

(data type)

!"# $% &' '

'$

(% ' $ )

int num; //
num = 10; //
3/24/2012

char ch;
ch = a;
float f;
f = 14.5;

3/24/2012

char ch1;
char ch2;
ch1 = a;
ch2 = b;

3/24/2012

char ch1, ch2;


ch1 = a;
ch2 = b;

char !"
char " % &'

char ch;
ch = a;
('
char ch;
ch = 121;
3/24/2012

& ! char
255 !) &
$

( '

"

( (+ +
( + + unsigned

3/24/2012

"
&! 7

8
!
0
&! -128 *+ 127 ! ,
1
& ' ( -

0 *+ 255

-!

(, -.

!
signed char ch;

"
-

! char ch;

ch = a;
* ( " )( 0 *+ 255 "

unsigned char ch;


ch = 231;

3/24/2012

unsigned
int i;

// " &!
// ( ' !

unsigned int i;
unsigned )

3/24/2012

"

# int $%

) !

( ' ! *+

//

0 *+ 65535

! ,

10

Condition statement
if()
$ /%# #$% ) %( '
#$% ) if ! )
#$% %(
'$ )

# $ # (
( ) )

#' $

if()..else
$

3/24/2012

/%# #$% ) '


else

#&

#' "%# 0

(% #

if

11

if
if(a > 5)
{
printf(sta1);
}
printf(sta2);

3/24/2012

a = 3;

Output:
sta2
*
a = 6;
Output:
sta1
sta2
12

if .. else
if(a > 5)
{
printf(sta1);
} else {
printf(sta2);
}

3/24/2012

a = 3;

Output:
sta2
*
a = 6;
Output:
sta1

13

if .. else
if(a > 5)
{
printf(sta1);
} else {
printf(sta2);
}
printf(sta3);
3/24/2012

*
a = 3;
Output:
sta2
sta3
*
a = 6;
Output:
sta1
sta3
14

if.. if
if (a > 7)
{
printf(sta1);
}
if (a > 3)
{
printf(sta2);
}
3/24/2012

15

if.. if
if (a < 3)
{
printf(sta1);
}
if (a < 5)
{
printf(sta2);
}
3/24/2012

if (a < 3)
{
printf(sta1);
} else
if (a < 5)
{
printf(sta2);
}
16

Loop statement
for()
/%#

1,

#$% )

; '

for(&!

&! )

for( i=0; i<10; i++)



0 i (
$% '

3/24/2012

1,
0
%

! i

10

$% i )

10

10 #,
) (
#

.%

( & # (
/ #$% )
' )

i ,# 1

#' $

10

i<10
#

/%# i++
17

Loop statement
for(i=0; i<20; i++)
for(i=20; i>10; i--)
for( ; ;) //
!"
for( ; i< 10; i++)
for( ; i<10; )
for(i=10 ; i>0 ; i--)

3/24/2012

18

! &

$%' ()*% +

2x1=2
2x2=4
2x3=6

2 x 12 = 24

3/24/2012

19

! &

$%' ()*% +

2 x 12 = 24
2 x 11 = 22
2 x 10 = 20

2x1=2

3/24/2012

20

! &

$%' ()*% +

2 x 12 = 24
2 x 10 = 20

2x2=4

3/24/2012

21

i++
//i = i + 1
i = i + 2 => i +=2
i= i - 2 => i -= 2

3/24/2012

22

Star. up
*
**
***
****
*****

3/24/2012

23

Star. down
*****
****
***
**
*

3/24/2012

24

Bankstar
*
**
***
****
*****

3/24/2012

25

You might also like