CNotes 1
CNotes 1
start
step 1: read a
step 2: read b
step 3: c := a+b
step 4: print a
step 5: print b
step 6: print c
stop
Draw the flow chart to calculate the addition of 2 numbers.
start
Read a
Read b
C:= a+b
Print a
Print b
Print c
stop
write an algorithm to calculate the addition of 3 numbers.
start
step 1: read a
step 2: read b
step 3: read c
step 4: d := a+b+c
step 5: print a
step 6: print b
step 7: print c
step 8: print d
stop
rewrite the above the algorithm to represent more input and output(read or
print) statements in a single line.
start
step 2: d := a+b+c
stop
Draw the flow chart for addition of 3 numbers.
start
Read a,b,c
D:= a+b+c
Print a,b,c,d
stop
Algorithm 3.
start
stop
Draw the flow chart for the above algorithm
start
Read maths,
physics, chemistry
Avg := total/3
stop
Algorithm 4.
start
stop
Read radius
Area_circle := 3.14 *
radius * radius
Print radius,
araa_circle
stop
Algorithm 7.
start
else
stop
Read num1,num2
false
If num1
> num2 Print “num2 is big”
true
stop
Algorithm 8.
start
else
stop
Read num1,num2,num3
If num1>num2 and
num1>num3
true
flase
flase
true
stop
Introduction to C Programming Language
keywords
statements
programs
Alphabets :
a-z, A-Z
Digits :
0-9
Symbols :
~ tilde
! Exclamatory
@ at the rate
# Hash(preprocessor)
$ Dollar
% Percentage
^ carret
& ampersand
* star
( parenthesis open
) parenthesis close
- highfun/minus
_ underscore
+ plus
= equal
: colon
; semi colon
, comma
. dot
? question mark
/ slash or division
\ backward slash
| vertical bar
[ bracket open
] bracket close
Keywords :
Each keyword in c language is having its own specific purpose and meaning.
auto
break
case
char
const or constant
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
Structure of C Programming Language
Definition Section
main()
{
Decleration Section
Execution Section
}
In this section we can include the header libraries or we can link the other
programs with the current programs
We can include the header library using the preprocessor directive #include
in the program
Here # symbol is known as a preprocessor and #include is a preprocessor
directive
Example :
#include<stdio.h>
Definition Section:
main function:
> The program execution always begins from the main function only.
(or)
main()
We cannot write anything between the closed parenthesis and the open
brace of main function.
In between the open brace and closed brace of main function we write the
decleration section and execution section.
Decleration Section:
In the decleration section we can declare the variables required in the
program.
Execution Section:
All the executable statements can be written under the execution section.
The main function returns an integer value always, Hence we must write a
return statement at the end of main function.
example:
return 0;
Datatypes:
i. integer types
- short int
- int
- long int
- float
- double
- long double
- char
2. Derived Datatypes
i. arrays
ii. strings
iii. functions
iv. pointers
i. structures
ii. unions
iii. enumerations
Identifier:
2. we can start with either any alphabet from lower case a to z or _ symbol.
Ex:
student_name
gross_salary
_subject
result_1
Variable:
syntax:
datatype variablename;
ex:
int num1;
int num2;
int num3;
(or)
int num1,num2,num3;
num1=10;
num2=20;
num3=num1+num2;
Input/Output functions:
1. printf()
2. scanf()
3. fprintf()
4. fscanf()
1. printf():
syntax:
printf("Formatstring",list of variables);
ex:1
int a; => %d
float b; => %f
char c; => %c
> When we give different types of variables we must follow the order of
format specifiers with the order of variables list.
> The number of variables must be matched with the number of format
specifiers.
ex:2
int a,b;
printf("%d%d",a,b);
2. scanf():
This function will read the input from the standard input device(key board)
to the variables.
syntax:
Ex:1
int a,b;
scanf("%d%d",&a,&b);
Ex:2
int a;
float b;
char c;
scanf("%d%f%c",&a,&b,&c);
3. fprintf():
syntax:
fprintf(filepointer,"Format String",List of variables);
Ex:
fprintf(stdout,"%d",a);
4. fscanf():
syntax:
Ex:
fscanf(stdin,"%d",&a);
1. getchar()
2. putchar()
3. getc()/fgetc()
4. putc()/fputc()
5. gets()
6. puts()
1. getchar():
ex:
char ch;
ch=getchar();
2. putchar():
ex:
putchar(ch);
3. getc():
ex:
char ch;
ch=getc(fp);
4. putc():
ex:
putc(ch,fp);
5. gets():
gets(str);
6. puts()
ex:
puts(str);
Comment lines:
The comment lines can be written as a single line or multiple lines as per the
need.
Ex:
first.c
#include<stdio.h>
main()
printf("Welcome");
return 0;
output:
Welcome
To erase the previous output on the console we can use clrscr() function in
the program.
#include<stdio.h>
main()
clrscr()
printf("Welcome");
return 0;
output:
Welcome
Operators in C language:
1. Assignment Operator =
This operator will evaluate the value/expression written at the right side and
assigns to the variable at left side.
ex:
a=10;
a=10+20;
2. Arithmatic Operators:
In this operation there will atleast 2 operands with the operator to perform
the operation.
#include<stdio.h>
main()
int a,b,c;
clrscr();
scanf("%d",&b);
c=a+b;
printf("Addition is %d\n",c);
return 0;
output:
Enter a value : 10
Enter b value : 20
a value is 10
b value is 20
Addition is 30
ii. Unary Arithmatic Operators:
1. Unary Minus -
Ex:
int a,b;
a=10;
-a;
(or)
b=-a;
int a=10;
a=10-1;
(or)
a=a-1;
int a=10;
a=10+1;
(or)
a=a+1;
printf("a is %d",a); => 11
note : When the left hand side variable and the first variable in the right
hand side is same we can write short hand notation.
2. Increment/Decrement Operators(++/--):
> Here we will write the operator first and the operand next
syntax:
operator operand;
++a;
--a;
>In this first the value of a variable is increased/decreased by one and the
expression is evaluated second.
int a;
a=10;
preinc.c
#include<stdio.h>
main()
int a;
clrscr();
a=10;
printf("a is %d\n",a);
printf("a is %d\n",++a);
return 0;
output:
a is 10
a is 11
HW1:
> Here we will write the operand first and the operator next.
syntax:
operand operator
a++
a--
int a;
a=10;
postinc.c
#include<stdio.h>
main()
int a;
a=10;
clrscr();
printf("a is %d\n",a);
printf("a is %d\n",a++);
printf("a is %d\n",a);
return 0;
output:
a is 10
a is 10
a is 11
HW2:
5. Equal ==
6. Not Equal !=
Ex :
10 > 20 0
10 > 5 1
5 < 100 1
56 < 25 0
47 <= 50 1
47 <= 47 1
47 <= 23 0
67 >= 67 1
45 >= 34 1
45 >= 56 0
90 == 90 1
90 == 121 0
100 != 100 0
123 != 121 1
rel.c
#include<stdio.h>
main()
printf("100 == 90 %d\n",100==90);
printf("100 != 90 %d\n",100!=90);
printf("90 != 90 %d\n",90!=90);
return 0;
Output:
10 > 20 0
10 > 5 1
5 < 100 1
5<30
6 >= 6 1
8 >= 20 0
5 <= 100 1
56 <= 20 0
100 == 100 1
100 == 90 0
100 != 90 1
90 != 90 0
4. Logical Operators:
Logical Operators will checks the logical relationship of the two expressions.
2. Logical Or ||
3. Logical Not !
X Y X&&Y
----------------------
1 1 1
1 0 0
0 1 0
0 0 0
----------------------
1 1 1
1 0 1
0 1 1
0 0 0
X !X
-----------
1 0
0 1
Logical.c
#include<stdio.h>
main()
{ clrscr();
printf("(10 > 20) && (10 < 25) %d\n",(10>20) && (10<25));
return 0;
Output:
2. Bitwise Or |
X Y X&Y
----------------------
1 1 1
1 0 0
0 1 0
0 0 0
Truth Table of Bitwise Or
X Y X|Y
----------------------
1 1 1
1 0 1
0 1 1
0 0 0
X Y X^Y
----------------------
1 1 0
1 0 1
0 1 1
0 0 0
Ex: a<<3
This operator will moves the specified number of bits to right side.
Ex: a>>2
Example:
a=34
b=49
a 1 0 0 0 1 0
b 1 1 0 0 0 1
a&b 1 0 0 0 0 0 32 a&b=32
32 0 0 0 0 0
a 1 0 0 0 1 0
b 1 1 0 0 0 1
a|b 1 1 0 0 1 1 51 a|b=51
32 16 0 0 2 1
a 1 0 0 0 1 0
b 1 1 0 0 0 1
a^b 0 1 0 0 1 1 19 a^b =19
0 16 0 0 2 1
Bitwise
Left Shift
Operator
a<<3 a 1 0 0 0 1 0
1 0 0 0 1 0 0 0 0
256 0 0 0 16 0 0 0 0 272
Bitwise
Right
Shift
Operator
a>>2 a 1 0 0 0 1 0
0 0 1 0 0 0
0 0 8 0 0 0 8
Bitwise.c
#include<stdio.h>
main()
int a,b;
clrscr();
a=34;
b=49;
printf("a | b %d\n",a|b);
printf("a ^ b %d\n",a^b);
return 0;
Output:
a&b 32
a|b 51
a^b 19
a << 3 272
a >> 2 8
Example:
int a,b,c,d;
a=10;
b=5;
c=20;
300
Prefix increment/decrement
Unary plus/minus
++ — Logical negation/bitwise complement
+– Cast (convert value to temporary value
2 !~ of type)
(type) Dereference
* Address (of operand)
& Determine size in bytes on this
sizeof implementation right-to-left
3 * / % Multiplication/division/modulus left-to-right
4 + – Addition/subtraction left-to-right
12 || Logical OR left-to-right
= Assignment
+= -= Addition/subtraction assignment
*= /= Multiplication/division assignment
14
%= &= Modulus/bitwise AND assignment
^= |= Bitwise exclusive/inclusive OR assignment
<<= >>= Bitwise shift left/right assignment right-to-left
syntax:
Condition.c
#include<stdio.h>
main()
int a,b,c;
clrscr();
scanf("%d%d",&a,&b);
c=a>b?a-b:b-a;
return 0;
Output:
Type Conversion:
Ex:
int a;
float b;
a=10;
b=a;
syntax:
variable=(desitination datatype)variable/value;
int a;
float b;
a=10;
b=(float)a;
Type_con.c
#include<stdio.h>
main()
int a;
float b;
clrscr();
printf("Enter b value");
scanf("%f",&b);
printf("b is %.2f\n",b);
a=(int)b;
printf("a is %d\n",a);
return 0;
Output:
Conditional Branching and Loops:
--------------------------------
1. Conditional Statements
2. Looping Statements
1. Conditional Statements
-------------------------
These statements will checks the condition and executes the selected
statements based on the truthfullness of the condition.
i. if :
if statement will check the condition and executes the statements written
after it if the condition is true only.
syntax:
if <condition>
statement
(or)
if <condition>
{
statments
........
........
}
c1.c
#include<stdio.h>
main()
{
int age;
clrscr();
printf("Enter age value\n");
scanf("%d",&age);
if(age>=18)
{
printf("The person is eligible to vote");
}
return 0;
}
output:
ii. if-else:
if else statement will check the condition and executes the statements
written after if when the condition is true and executes the statements
written after else when the condition is false.
syntax:
if <condition>
{
statements
........
........
}
else
{
statements
.........
........
}
write a program to check whether a person is eligible to vote or not using if-
else statement
c2.c
#include<stdio.h>
main()
{
int age;
clrscr();
printf("enter age value\n");
scanf("%d",&age);
if(age>=18)
{
printf("Eligible to vote\n");
}
else
{
printf("Not eligible to vote\n");
}
return 0;
}
output:
write a program to check biggest of 2 numbers using if-else statement.
c3.c
#include<stdio.h>
main()
{
int a,b;
clrscr();
printf("Enter a and b values\n");
scanf("%d%d",&a,&b);
if(a>b)
{
printf("a is big\n");
printf("a value is %d\n",a);
}
else
{
printf("b is big\n");
printf("b value is %d\n",b);
}
return 0;
}
Output:
c4.c
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter a,b,c values\n");
scanf("%d%d%d",&a,&b,&c);
if((a>b) && (a>c))
{
printf("a is big");
}
else if((b>a) && (b>c))
{
printf("b is big");
}
else
{
printf("c is big");
}
return 0;
}
output:
c5.c
#include<stdio.h>
main()
{
int maths,physics,chemistry;
int total;
float avg;
clrscr();
printf("Enter maths,physics and chemistry marks\n");
scanf("%d%d%d",&maths,&physics,&chemistry);
total=maths+physics+chemistry;
avg=total/3.0;
if(avg>=90)
{
printf("Grade is O");
}
else if((avg>=80) && (avg<90))
{
printf("Grade is A+");
}
else if((avg>=70) && (avg<80))
{
printf("Grade is A");
}
else if((avg>=60) && (avg<70))
{
printf("Grade is B+");
}
else if((avg>=50) && (avg<60))
{
printf("Grade is B");
}
else if((avg>=40) && (avg<50))
{
printf("Grade is C");
}
else
{
printf("Failed");
}
return 0;
}
output:
syntax:
if <condition>
{
if <condition>
{
statements
..........
}
else
{
statements
..........
}
}
else
{
if <condition>
{
statements
..........
}
else
{
statements
..........
}
}
c6.6
#include<stdio.h>
main()
{
int age;
char gender;
clrscr();
printf("enter the gender m-male and f-female\n");
scanf("%c",&gender);
printf("enter the age \n");
scanf("%d",&age);
if(gender=='m')
{
if(age>=21)
{
printf("The person is eligible for marriage\n");
}
else
{
printf("The person is not eligible for marriage\n");
}
}
else
{
if(age>=18)
{
printf("The person is eligible for marriage\n");
}
else
{
printf("The person is not eligible for marriage\n");
}
}
return 0;
}
output:
iv. switch:
it is a multiway conditional statement. It takes an expression and compares
with the cases written with in switch block. If any case is matched with the
expression then it executes the corresponding matched case statements, if
no case is matched with the expression then it executes default case
statements.
syntax:
switch(expression)
{
case constant1:
statements
..........
case constant2:
statements
..........
case constant3:
statements
..........
.
.
.
.
case constantn:
statements
..........
default:
statements
..........
}
#include<stdio.h>
main()
{
int num;
clrscr();
printf("Enter number between 1 and 5\n");
scanf("%d",&num);
switch(num)
{
case 1:
printf("One\n");
case 2:
printf("Two\n");
case 3:
printf("Three\n");
case 4:
printf("Four\n");
case 5:
printf("Five\n");
default:
printf("The number not between 1 and 5\n");
}
return 0;
}
output:
Note:
In switch statement if any case is matched with the given expression then
the cases after the matched case will be executed. To eliminate this problem
we should use the break in each case in the switch statement.
Rewrite the above program to get the proper output using break
#include<stdio.h>
main()
{
int num;
clrscr();
printf("Enter number between 1 and 5\n");
scanf("%d",&num);
switch(num)
{
case 1:
printf("One\n");
break;
case 2:
printf("Two\n");
break;
case 3:
printf("Three\n");
break;
case 4:
printf("Four\n");
break;
case 5:
printf("Five\n");
break;
default:
printf("The number not between 1 and 5\n");
}
return 0;
}
output:
#include<stdio.h>
main()
{
char alpha;
clrscr();
printf("Enter an alphabet\n");
scanf("%c",&alpha);
switch(alpha)
{
case 'a':
case 'A':printf("Vowel");
break;
case 'e':
case 'E':printf("Vowel");
break;
case 'i':
case 'I':printf("Vowel");
break;
case 'o':
case 'O':printf("Vowel");
break;
case 'u':
case 'U':printf("Vowel");
break;
default:
printf("Consonant");
}
return 0;
}
output:
c9.c
#include<stdio.h>
main()
{
char alpha;
clrscr();
printf("Enter an alphabet\n");
scanf("%c",&alpha);
switch(alpha)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':printf("Vowel");
break;
default:
printf("Consonant");
}
return 0;
}
output:
c10.c
#include<stdio.h>
main()
{
int maths,physics,chemistry;
int total;
float avg;
int grade;
clrscr();
printf("Enter maths,physics and chemistry marks\n");
scanf("%d%d%d",&maths,&physics,&chemistry);
total=maths+physics+chemistry;
avg=total/3.0;
grade=avg/10;
switch(grade)
{
case 9:printf("Grade O");
break;
case 8:printf("Grade A+");
break;
case 7:printf("Grade A");
break;
case 6:printf("Grade B+");
break;
case 5:printf("Grade B");
break;
case 4:printf("Grade C");
break;
default:
printf("Failed");
}
return 0;
}
output:
1. while loop:
While loop is a pre condition checking(pre-test) looping statement, which
checks the condition first, if the condition is true it enters into looping block
to execute the statements repetatively until the condition becomes false.
syntax:
while <condition>
{
statements
statements
..........
..........
}
Note:
1. We cannot terminate the while condition with semi colon in while loop.
2. While loop is also known as entry control looping statement.
Write a program to display your name for 5 times by using while loop
loop1.c
#include<stdio.h>
main()
{
int i;
clrscr();
i=1;
while(i<=5)
{
printf("Prashanth\n");
i++;
}
return 0;
}
output:
loop2.c
#include<stdio.h>
main()
{
int i;
clrscr();
i=1;
while(i<=5)
{
printf("%d\n",i);
i++;
}
return 0;
}
output:
loop3.c
#include<stdio.h>
main()
{
int i;
clrscr();
i=1;
while(i<=20)
{
if(i%2==1)
{
printf("%d\n",i);
}
i++;
}
return 0;
}
output:
HW1
Write a program to display the even numbers from 1 to 20 by using while
loop.
loop4.c
#include<stdio.h>
main()
{
int n,sum,digit;
clrscr();
printf("Enter n value\n");
scanf("%d",&n);
sum=0;
while(n!=0)
{
digit=n%10;
sum=sum+digit;
n=n/10;
}
printf("Sum is %d\n",sum);
return 0;
}
output:
HW2
Write a program to display the reverse of a given number using while loop.
123 => 321
loop5.c
#include<stdio.h>
main()
{
int n,rev,digit;
rev=0;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
while(n!=0)
{ digit=n%10;
rev=(rev*10)+digit;
n=n/10;
}
printf("The Reverse Number is %d\n",rev);
return 0;
}
output:
loop6.c
#include<stdio.h>
main()
{
int n,rev,digit,n1;
rev=0;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
n1=n;
while(n!=0)
{ digit=n%10;
rev=(rev*10)+digit;
n=n/10;
}
if(n1==rev)
{
printf("The Number is Polindrome %d\n",rev);
}
else
{
printf("The Number is not Polindrome\n");
}
return 0;
}
output:
loop7.c
#include<stdio.h>
main()
{
int n,i,count=0;
clrscr();
printf("Enter n value\n");
scanf("%d",&n);
i=2;
while(i<=n)
{
if(n%i==0)
{ count++;
}
i++;
}
if(count==1)
{
printf("The number is prime number %d\n",n);
}
else
{
printf("The number is not prime number %d\n",n);
}
return 0;
}
output:
Ex:
5
5x1=5
5 x 2 = 10
5 x 3 = 15
....
....
5 x 10 = 50
loop8.c
#include<stdio.h>
main()
{
int n,i;
clrscr();
printf("Enter n value\n");
scanf("%d",&n);
i=1;
while(i<=10)
{
printf("%d x %d = %d\n",n,i,n*i);
i++;
}
return 0;
}
output:
HW1.
Write a program to check whether a given number is arm strong number or
not.
2. do while loop:
do while loop is a post condition checking(post-test) looping statement. It
enters into the loop block without checking a condition and executes the
statements of loop block once and at the exit it checks the condition, if the
condition is true it repeats loop execution, if false execution will be stopped.
syntax:
do
{
statements
..........
..........
}while<condition>;
Note:
1. We should terminate the while condition with semi colon in the do while
loop.
2. Even the condition may be false the statements of loop will be executed
atleast once.
3. do while loop is also known as exit control looping statement.
Write a program to display your name for 5 times using do while loop.
loop9.c
#include<stdio.h>
main()
{
int i;
clrscr();
i=1;
do
{
printf("Prashanth\n");
i++;
}while(i<=5);
return 0;
}
output:
loop10.c
#include<stdio.h>
main()
{
int i;
clrscr();
i=1;
do
{
printf("%d\n",i);
i++;
}while(i<=20);
return 0;
}
output:
loop11.c
#include<stdio.h>
main()
{
int n,digit,sum;
sum=0;
clrscr();
printf("Enter n value\n");
scanf("%d",&n);
do
{ digit=n%10;
sum=sum+digit;
n=n/10;
}while(n!=0);
printf("Sum of individual digits is %d\n",sum);
return 0;
}
output:
HW:
Write all the remaining programs discussed in while loop using do while
loop.
syntax;
for(initialization; condition; updation)
{
statements
..........
..........
}
write a program to display your name for 5 times using for loop
loop12.c
#include<stdio.h>
main()
{
int i;
clrscr();
for(i=1;i<=5;i++)
{
printf("Prashanth\n");
}
return 0;
}
output:
Write a program to check whether a given number is prime or not using for
loop.
loop13.c
#include<stdio.h>
main()
{
int n,i,count=0;
printf("Enter n value\n");
scanf("%d",&n);
for(i=2;i<=n;i++)
{
if(n%i==0)
{ count++;
}
}
if(count==1)
{
printf("the number is prime\n");
}
else
{
printf("The number is not prime\n");
}
return 0;
}
output:
#include<stdio.h>
main()
{
int n,n1,rev=0,digit;
clrscr();
printf("Enter n value\n");
scanf("%d",&n);
for(n1=n;n1!=0;n1=n1/10)
{
digit=n1%10;
rev=(rev*10)+digit;
}
if(n==rev)
{
printf("The number is polindrome\n");
}
else
{
printf("The number is not polindrome\n");
}
return 0;
}
output:
Nested Loops:
Writing one loop inside the other loop is known as nested loops
syntax:
Nested While loop:
while <condition>
{
...............
while<condition>
{
statements
..........
..........
}
...............
}
do
{
.............
do
{
statements
..........
..........
}while<condition>;
.............
}while<condition>;
for(initialization;condition;updation)
{
..................
for(initialization;condition;updation)
{
statements
.........
.........
}
}
*
**
***
****
*****
1
12
123
1234
12345
loop18.c
#include<stdio.h>
/*nested for loop*/
main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",j);
}
printf("\n");
}
return 0;
}
output:
1
22
333
4444
55555
loop19.c
#include<stdio.h>
/*nested for loop*/
main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",i);
}
printf("\n");
}
return 0;
}
output:
HW:
1. Write a program to display the following format using nested loops
12345
1234
123
12
1
#include<stdio.h>
main()
{
int i,j,count;
for(i=2;i<=100;i++)
{ count=0;
for(j=2;j<=i;j++)
{
if(i%j==0)
{
count++;
}
}
if(count==1)
{
printf("%d\t",i);
}
}
return 0;
}
output:
loop21.c
#include<stdio.h>
main()
{
long unsigned int n,i,fact;
fact=1;
clrscr();
printf("Enter n value\n");
scanf("%lu",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("The factorial of %lu is %lu\n",n,fact);
return 0;
}
output:
1.break:
break statement will stops the execution of loop or block and comes out of
loop or block.
2. continue:
continue statement will stops executing the statements written after it
inside the loop or block and repeats from begining.
#include<stdio.h>
main()
{
int i;
clrscr();
for(i=1;i<=10;i++)
{
if(i>5)
{
break;
}
printf("%d\n",i);
}
return 0;
}
output:
#include<stdio.h>
main()
{
int i;
clrscr();
for(i=1;i<=10;i++)
{
if(i%3==0)
{
continue;
}
printf("%d\n",i);
}
return 0;
}
output:
goto:
goto statement will takes the execution control to the specified label and
executes the statements written under the label.
syntax:
goto labelname;
......
......
......
......
labelname:
statements
..........
..........
write a program to demonstrate the goto statement to display 1 to 10
numbers.
goto1.c
#include<stdio.h>
main()
{
int i;
clrscr();
i=1;
dis:
printf("%d\n",i);
i++;
if(i<=10)
goto dis;
return 0;
}
output:
goto2.c
#include<stdio.h>
main()
{
int a,b;
clrscr();
return 0;
}
output: