INTRODUCTION TO COMPUTER PROGRAMMING
Loop as repetitive statement, For loop/statement.
While loop statement and do while loop statement.
Variable Types, Data types, ranges and width.
2. INTRODUCTION TO COMPUTER PROGRAMMING
1) Loop as repetitive statement, For loop/statement.
2) While loop statement and do while loop statement.
3) Variable Types, Data types, ranges and width.
3. For loop or For statement
• It is the construct to repeat a body to be executed upto a
number of times depending on condition.
Syntax:
for(initialization;checking;increment)
{
// body of for loop
}
4. Program to generate numbers 1 to 100
#include<stdio.h>
void main(void)
{
int counter;
for(counter=1;counter<=100;counter++)
{
printf(“%d=”,counter);
}
}
5. Program to generate Hello Quest message 100 times
#include<stdio.h>
void main(void)
{
int counter;
for(counter=1;counter<=100;counter++)
{
printf(“Hello Quest”);
}
}
10. Program to generate numbers 1 to 100
#include<stdio.h>
void main(void)
{
int counter=1;
do
{
printf(“%d=”,counter);
counter++;
}while(counter<=100);
}
11. Program to generate Hello Quest message 100 times
#include<stdio.h>
void main(void)
{
int counter=1;
do
{
printf(“Hello Quest”);
counter++;
}while(counter<=100);
}
12. • Technical difference among for, while and do-while loop
• Write a program in C using loop to generate even
numbers from 1 to 100
• Write a program in C using loop statement to generate
odd numbers from 1 to 100
• Write a program in C using loop to generate even
numbers from 100 to 1
• Write a program in C using loop statement to generate
odd numbers from 100 to 1
• Write a program in C using loop statement to generate
table of any number
• Write a program in C using loop statements to generate 1
one time, 2 times 3….. Upto 10 ten times
1
2 2
13. • Write a program in C using loop statements to generate 1
one time, 2 times 3….. upto 10 ten times
1
2 2
…..
10 10 10 10 10 10 10 10 10 10
• Write a program in C using loop statements to generate
10 ten times, 9 nine times….. upto 1 one time
10 10 10 10 10 10 10 10 10 10
9 9 9 9 9 9 9 9 9
…
1
14. • Write a program in C using loop statements to generate
(a) *
**
***
****
*****
(b)
*****
****
***
**
*
15. Data types
• short int (short)
• unsigned short int (unsigned short)
• char
• unsigned char
• signed char
• int
• unsigned int(unsigned)
• long int(long)
• unsigned long int(unsigned long)
• float
• double
• long double
16. Data types
Ranges of values that can be stored in variables of these
types will depend on the compiler you are using, but on an
IBM PC’s and Borland turbo c compiler the ranges are:
• short int -128 to 127(1 byte)
• unsigned short int (unsigned short) 0 to 255(1 byte)
• char 0 to 255 or -128 to +127(1 byte)
• unsigned char 0 to 255(1 byte)
• signed char -128 to +127(1 byte)
• int -32768 to +32767(2 byte)
• unsigned int(unsigned) 0 to 65,535(2 byte)
• long int(long) -2147,483648 to 2147,483647(4 byte)
• unsigned long int(unsigned long) 0 to 4,294,967,295(4 byte)
• float single precision floating point(4 byte)
• double double precision floating point(8 byte)
• long double extended precision floating point(10 byte)