Suman Stha
Suman Stha
Computer science
2082
First and foremost, I would like to thank my subject teacher, Anil thakur , for their invaluable
guidance, encouragement, and continuous support. Their expertise and feedback helped me
greatly in completing this project successfully.
I am also grateful to my college, Nirvana , for providing the necessary facilities and a moti-
vating environment for learning.
Finally, I would like to thank my parents, friends, and everyone who directly or indirectly
contributed to the successful completion of this project.
Thank you.
2
Table of Contents
C PROGRAMMING 4
DATA TYPE 5
CONTROL STATEMENT 10
LOOP STATEMENT 16
SWITCH CASE STATEMENT 26
ARRAY 35
STRING FUNCTION…………………………………………………………………………………………………………………………40
INTRODUCTION OF HTML……………………………………………………………………………………………………………….47
STRUCTURE OF HTML ………………………………………………………………………………………………………………..48
3
C PROGRAMMING
Introduction
C programming is a high-level, general-purpose programming language developed in the
early 1970s by Dennis Ritchie at Bell Labs. It is one of the most influential programming
languages, serving as the foundation for many modern languages like C++, Java, and
Python. C is known for its efficiency, simplicity, and versatility, making it ideal for sys-
tem programming, embedded systems, and software development. It provides low-level
access to memory through pointers and direct manipulation of hardware, giving program-
mers greater control. Due to its compact nature, C is widely used for developing operating
systems, compilers, and other performance-critical applications.
Structure of C programming
# include < stdio.h>
int main ()
{
Printf (“Hello world”);
Return 0;
}
4
DATA TYPES:
#include <stdio.h>
int main()
{
int num1 = 5;
int num2 = 9;
int sum;
sum = num1 + num2;
Printf ("The sum of %d and %d is %d\n", sum);
return 0;
}
#include <stdio.h>
int main()
{
int num1 = 10;
int num2 = 5;
int d;
d = num1 - num2;
Printf ("The difference of %d and %d is %d\n", d);
return 0;
}
5
3. Write a program to find a quotient of any two numbers.
#include <stdio.h>
int main()
{
int num1 = 25;
int num2 = 5;
float d;
d = num1 / num2;
Printf ("The division of %d and %d is %d\n", d);
return 0;
}
# include<stdio.h>
Void main
{
Int l, v;
Printf (“Enter length/n”)
Scanf (“%d”, &l);
V=l^3;
Printf (“The volume is %d/n”, v);
}
#include <stdio.h>
Void main()
{
Float r, A;
Printf ("Enter the radius /n”);
Scanf (“%d”, & r);
PI=3.14
float A = PI * radius * radius;
printf ("Area of the circle: %f\n” A);
}
6
6. WAP to find volume of rectangle.
#include <stdio.h>
void main()
{
float length, width, height, volume;
printf("Enter the length of the rectangle: ");
scanf("%f", &length);
#include <stdio.h>
void main()
{
float radius, height, volume;
7
8. WAP to find area of four walls.
#include <stdio.h>
void main()
{
float length, width, height, A;
printf("Enter the length of the room: ");
scanf("%f", &length);
#include <stdio.h>
void main()
{
float principal, rate, time, S.I;
printf("Enter the principal amount: ");
scanf("%f", &principal);
8
10. WAP to find compound interest.
#include <stdio.h>
void main()
{
float p, r, t, C.I;
printf("Enter principal amount: ");
scanf("%f", &p);
9
CONTROL STATEMENT
"Control statement" is a general term used in programming to describe instructions that control the
flow of execution in a program. These statements help determine how and when different parts of
code are executed.
1. If statement
An if statement is a basic control statement used to execute a block of code only if a certain
condition is true.
i. If
ii. If……else
iii. If……else if…..else
Syntax:
If<condition>
e.g.
WAP to find a number is positive.
#include <stdio.h>
void main ()
{
int n;
printf (“Enter any number\n”);
scanf ( “%d”, &n);
if (n>0)
printf (“The number is positive\n);
}
10
i. if….else statement
Syntax:
statement 1
else,
statement 2
e.g.
#include<stdio.h>
void main ( )
int n;
printf (“ Enter any number\n);
scanf (“%d”, &n);
if (n>0)
printf (“ The number is positive\n” );
else
printf (“The number is negative\n”);
}
11
ii. if….else if….else statement
syntax:
if <condition 1>
statement 1;
elseif <condition 2>
statement 2;
………..
………..
elseif < condition n>
ststement n;
else, statement n+1;
e.g.
#include <stdio.h>
void main ( )
{
int n;
printf(“Enter any number\n);
scanf(“%d”, &n)
if (n=0)
printf (“%d is zero\n”,n);
elseif (n>0)
printf (“%d is positive\n”,n);
else
printf (“%d is negative\n”,n);
}
12
1. WAP to find the number is odd, even or zero.
#include <stdio.h>
void main( )
{
int n;
printf (“Enter any number\n”);
scanf(“%d”, &n);
if (n==0)
printf (“%d is zero\n, n);
elseif (n%2==0)
printf (“ % d is even\n”, n);
else
printf (“%d is odd \n”, n);
}
# include<stdio.h>
void main( )
{
int a , b ;
printf (“Enter any two numbers\n”);
scanf (“%d, %d”, &a, &b);
if (a>b)
printf (“a is greater”);
else
printf(“b is greater”);
}
13
3. WAP to pass a certain exam, a candidate has to give 4 exam. The candidate has to
score above 35 in each exam. Write a C program to display the result as pass or fail.
# include <stdio.h>
void main ( )
{
int M, N, E, C;
printf (“Enter value of M ,N, E, C\N”);
scanf (“%d, %d, %d, %d”, &M, &N, &E, &C);
if ( M>=35 && N>=35 && E>=35 && C>=35)
printf (“The student is pass\n”);
else
printf(“The student is fail\n”);
}
# include<stdio.h>
void main ( )
{
int m, n, e, c;
float Avg;
printf (“ Enter value of m, n, e, c\n”);
scanf (“%d, %d, %d, %d, &m, &n, &e, &c);
Avg = ( m+n+e+c)/4
if (m>=35 && n>=35 && e>=35 && c>=35 && Avg>=45%)
printf (“ The student is pass\n”);
else
printf (“The student is fail\n”);
}
14
5. WAP to input marks, percentage of a student and find the division he/she got.
# include<stdio.h>
void main ( )
{
int p;
printf (“ Enter percentage of student\n);
scanf ( “%d”, &p);
if ( p>=80)
printf (“Distinction\n”);
elseif (p>=60 && p<80)
printf ( “ first division\n”);
elseif (p>=50 && p<60)
printf ( “ second division\n);
elseif ( p>45 && p<50)
printf (“third division\n”)
else
printf (“ fail\n”)
}
15
LOOP STATEMENT
Loop statements are used to execute a block of code repeatedly as long as a certain
condition is true. This helps avoid writing repetitive code.
Types:
1. for loop
2. while loop
3. do….while loop
1. for loop
A for loop is used to repeat a block of code a specific number of times. It’s best when you know in
advance how many times the loop should run.
syntax;
# include <stdio.h>
void main( )
{
int i;
for ( i= 0; i<10; i++)
{
printf (“My name is suman\n”);
}
}
2. while loop
17
A while loop is used to execute a block of code repeatedly as long as a condition is
true.
Unlike the for loop, you don’t need to know in advance how many times it’ll run.
syntax:
initialization;
while <condition>
{
block of statement;
increment/decrement;
}
Example;
# include <stdio.h>
void main( )
{
int i=0;
while ( i<10 )
{
printf (“ My name is suman\n”);
i++;
}
}
18
# include<stdio.h>
void main( )
{
int i=0, n=1;
while ( i<20 )
{
printf(“%d \t”, n);
n=n+2;
i++;
}
}
do….while loop
19
A do...while loop is a control flow statement that executes a block of code at least
once, and then continues to execute the loop as long as a specified condition is true. It's
different from a regular while loop because the condition is checked after the code
runs, not before.
syntax:
initialization;
do
{
block of statements;
increment/decrement;
}
while<condition>;
Example:
# include<stdio.h>
void main ( )
{
int i=0;
do
{
printf (“My name is suman\n”);
i++;
}
while (i<10);
}
20
# include <stdio.h>
void main ( )
{
int i=0;
do
{
printf (“%d\n”,i);
i++;
}
while (i<10);
}
# include <stdio.h>
void main( )
{
int i=0; n=2;
do
{
printf(“%d\n”,n);
n=n+2;
i++;
}
while( i<10 );
}
21
# include<stdio.h>
void main ( )
{
int i=0, n=2;
while(i<15)
{
printf (“%d\n”, n);
n=n*2;
i++;
}
}
# include<stdio.h>
void main ( )
{
int i=0, n=1;
while (i<20)
{
printf (“%d\n”,n);
n=n^2;
n=n+1;
i++;
}
}
22
# include<stdio.h>
void main( )
{
int i=0,n,p=1;
while (i<20)
{
n=p^3;
printf (“%d\n”,n);
p=p+1;
i++;
}
}
# include<stdio.h>
void main( )
{
int i=0, a=1, b=1, c;
while (i<15)
{
printf(“%d\t”,a);
c=a+b;
b=c;
i++;
}
}
23
# include <stdio.h>
void main ( )
{
int i=0, a=3, b=1, c;
while (i<20)
{
printf (“%d\t”, a);
c = a+b;
a = b;
b = c;
i++;
}
}
# include <stdio.h>
void main ( )
{
int i = 9;
while (i>=0)
{
printf (“%d\t”, i);
i--;
}
}
24
# include<stdio.h>
void main( )
{
int i = 1, a;
while ( i <= 10)
{
a = 5*i;
printf (“5*%d = %d”, I, a);
i++;
}
}
# include<stdio.h>
void main ( )
{
int i = 1, n, a;
printf (“ Enter any number\n”,);
scanf (“ %d”, &a);
while (i<= 10)
{
n = a * i;
printf (“%d * %d = %d\n”, i, n, a);
i++;
}
}
25
The switch...case statement is used to execute one block of code among many op-
tions based on the value of a variable or expression. It’s often used as a cleaner alterna-
tive to long chains of if...else if...else.
syntax:
switch (condition)
{
case1:
block of statement;
break;
………..
………..
case n:
block of statement;
break;
default:
block of statement;
}
26
WAP to display he name of days using switch….case.
# include <stdio.h>
# include <conio.h>
void main ( )
{
clrsclr;
int n;
printf (“Enter any number from 1 to 7\n”):
scanf (“%d”,&n);
switch(n)
{
case 1:
printf (“Sunday\n”);
break;
case 2:
printf (“Monday\n”);
break;
case 3:
printf (“Tuesday\n”);
break;
case 4:
printf (“Wednesday\n”);
break;
case 5 :
printf (“Thursday\n”);
break;
case 6 :
printf (“Friday\n”);
break;
case 7:
printf (“Saturday\n”);
break;
default:
printf (“input is invalid\n”);
}
getch( );
}
27
1. WAP to display the name of months using switch….case.
28
case 12 :
printf (“ December\n”);
break;
default:
printf (“input is invalid\n”);
}
getch ( );
}
29
2. WAP to find sum, subtract, product and division of any two number using
swich….case.
# include <stdio.h>
# include <conio.h>
void main ( )
{
clrsclr;
int n;
float a, b, c;
printf (“Enter any two numbers\n”);
scanf (“%f, %f”, &a, &b );
printf (“Enter 1 for sum, 2 for subtract, 3 for multiply and 4 for di vide\n”);
scanf (“%d”, &n);
switch (n)
{
case 1:
c = a+b;
printf (“The sum of %f and %f is %f \n”, a, b, c);
break;
case 2:
c = a-b;
printf (“The difference of %f and %f is %f\n”, a, b,c);
break;
case 3:
c = a*b;
printf (“ The product of %f and %f is %f\n”, a, b, c);
break;
case 4:
c = a/b;
printf (“The division of %f and %f is %f\n”, a, b, c);
break;
default:
printf (“Input is invalid\n”);
}
getch ( );
}
30
1. WAP to print:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
# include <stdio.h>
void main ( )
int i, j;
for (i=1; i<=5; i++)
{
for (j=1; j<=i; j++)
{
printf (“%d”, j);
}
printf (“\n”);
}
}
31
2. WAP to print:
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
# include <stdio.h>
void main( )
{
int i, j;
for (i=5; i>=1; i--)
{
for (j=1; j<=i; j++)
{
printf (“%d”, j);
}
printf (“\n”);
}
}
32
3. WAP to print:
*****
****
***
**
*
# include <stdio.h>
void main( )
{
int i, j;
for (i=5; i>=1; i--)
{
for (j=1; j<=i; j++)
{
printf (“*”);
}
printf (“\n”);
}
}
33
4. WAP to print:
*
**
***
****
****
# include <stdio.h>
void main( )
{
int i, j;
for (i=1; i<=5; i++)
{
for (j=1; j<=i; j++)
{
printf (“*”);
}
printf (“\n”);
}
}
34
Array: - An array is a collection of elements stored at contiguous memory locations.
All elements in an array are of the same data type. Arrays are used to store multiple val-
ues in a single variable, instead of declaring separate variables for each value.
Types:
1. One dimensional array: A 1D array is a linear collection of elements that can be
accessed using a single index.
# include <stdio.h>
void main ( )
{
int n[10];
int i;
printf (“Enter any 10 numbers\n”);
for (i=0; i<10; i++)
{
scanf (“%d”, &n[i]);
}
printf (“The numbers are:\n”);
for (i=0; i<10; i++)
{
printf (“%d\t”,n[i]);
}
}
35
2. WAP to input marks of 20 students in an array and find average marks.
# include <stdio.h>
void main ()
{
int n[20];
int i, sum = 0;
float Avg=0;
printf (“Enter the marks of 20 students\n”);
for (i=0; i<20; i++)
{
scanf (“%d”, &n[i]);
sum = sum + n[i];
}
Avg = sum/20;
printf (“The marks are:\n”);
for (i=0; i<20; i++)
{
printf (“%d\t”, n[i]);
}
printf (“The average marks of students are %f\n”, Avg);
}
36
2. Two dimensional array: A 2D array stores data in a grid-like structure. You ac-
cess elements using two indices: one for the row, one for the column.
syntax:
int variable name [row-size] [column-size]
E.g:
int [5] [5];
# include <stdio.h>
void main ( )
{
int m1[2][2], m2[2][2];
int i, j, m3[2][2];
printf (“Enter first matrix\n”);
for (i=0; i<2; i++)
{
for (j=0; j<2; j++)
{
scanf (“%d”, &m1[i][j]);
}
}
printf (“Enter second matrix\n”);
for (i=0; i<2; i++)
{
for (j=0; j<2; j++)
{
scanf (“%d”, &m2[i][j]);
}
}
37
for (i=0; i<2; i++)
{
for (j=0; j<2; j++)
{
m3[i][j]= m1[i][j]+m2[i][j];
}
}
printf (“ The sum is:\n);
for (i=0; i<2; i++)
{
for (j=0; j<2; j++)
{
printf (“%d”, m3[i][j]);
}
printf (“\n”);
}
}
38
2. WAP to input any two 3*3 matrix and their sum.
# include <stdio.h>
void main ( )
{
int m1[3][3], m2[3][3];
int i, j, m3[3][3];
printf (“Enter first matrix\n”);
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
scanf (“%d”, &m1[i][j]);
}
}
printf (“Enter second matrix\n”);
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
scanf (“%d”, &m2[i][j]);
}
}
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
m3[i][j]= m1[i][j]+m2[i][j];
}
}
printf (“ The sum is:\n);
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf (“%d”, m3[i][j]);
}
printf (“\n”);
}
}
39
STRING FUNCTION
they help you manipulate and work with strings (like text or sequences of characters) in
programming.
1. Strlen function: The function strlen used to find length of the string.
# include<stdio.h>
# include<conio.h>
# include<string.h>
void main ( )
{
clrsclr( );
int L;
char name [20];
printf (“ Enter any string\n” );
gets (name);
L= strlen(name);
printf (“ The length of the string is %d”, L);
getch( );
}
40
2. Strcpy function: The function strcpy used to copy the string value from one vari-
able and paste it into another string variable.
# include<stdio.h>
# include<conio.h>
# include<string.h>
void main ( )
{
clrsclr ( );
char a[50];
char b[50];
printf (“Enter any string\n”);
gets(a);
strcpy (b,a);
printf (“The string is %s and %s\n”, a,b);
getch ( );
}
41
3. Stremp (): This function is used to compare two string to find if both string is equal
or not.
WAP to input any two string and find if both string is equal or not.
# include <stdio.h>
# include <conio.h>
Void main ( )
{
int a;
char str1[50], str2[50];
printf (“Enter first string\n”);
gets (str1);
printf (“Enter second string\n”);
gets (str2);
a= strcmp(str1, str2);
if (a==0)
printf (“Both strings are equal\n”);
else
printf (“Both strings are not equal\n”);
}
42
4. Strcat ( ): This string function is used to join one string with another
#include<stdio.h>
#include<string.h>
Void main ()
{
Char str1[50],str2[50];
printf(“Enter first string\n”);
gets(str1);
printf(“Enter second string\n”);
gets(str2);
strcat(str1,str2);
printf(“After joined the string is %s”,str1);
}
43
5. Strrev ( ): This string function is used to reverse the string.
# include <stdio.h>
# include <string.h>
Void main ( )
{
Char str1[50]
Printf (“Enter first string\n”);
gets( str1);
str rev (str1);
printf(“After reverse the string the string is %s”, str1);
}
44
6. Struper( ): This string function is used to convert the string into uppercase.
# include <stdio.h>
# include <string.h>
Void main( )
{
Char str1[50]
Printf (“Enter any string\n”);
gets( );
Struper (str1);
Printf (“After converting into upper case\n %s”,str1);
}
45
7. Strlwr ( ): This string function is used to convert the string into lowercase.
# include <stdio.h>
# include <string.h>
Void main ( )
{
Char str1 [50]
Printf (“Enter any string\n”);
gets( str1);
strlwr(str1);
printf (“After converting into lowercase\n %s”, str1);
}
46
INTRODUCTION TO HTML
HTML stands for Hyper Text Markup Language. It was invented in 1990 by a scientist
called Tim Berners Lee. The purpose was to make it easier for scientists at different uni-
versities to gain access to each other’s research documents. HTML is one language in a
class of markup languages, the most general form which is Standard Generalized Markup
Language (SGML), SGML was developed to create docume that could be displayed con-
sistently on computers of different hardware and operating system. Soc SGML was com-
plex, HTML was invented as a simple way of creating web pages that could be easy ac-
cessed by any browsers, HTML is a special case of SGML HTML consists of tags and
data. The serve to define what kind of data follows them, thereby enabling the browser to
provide the data in the appropriate form for the user to see.
HTML provides a way of displaying Web pages with text and images or multimedia con-
tent. HTM actually, is not a programming language, but a markup language. An HTML
file is a text file contain small markup tags. The markup tags tell the Web browser, such
as Google Chrome, Mozilla Fire Internet Explorer or Netscape Navigator, how to display
the page. An HTML file must have an han html file extension. These files are stored on
the web server. So, to see the web page of a company, U (Uniform Resource Locator)
should be entered, which is the web site address of that company, inte address bar of the
browser. This sends a request to the web server, which in turn responds by retum the de-
sired web page. The browser then provides the web page and we see it on your computer.
HTML. Allows Web page publishers to create complex pages of text and images that can
be viewed anyone on the Web, regardless of what kind of computer or browser is being
used. If we want to ca Web pages, we need a tool to write the HTML code for the page.
47
STRUCTURE OF HTML
HTML is a structure based web page designing scripting language which has specific
structure start b HTML. tag and contains heading part and body part clearly separated
with head tag and body tag lady ended with closing HTML tag.Basic Structure of HTML
DocumentThe skeleton of HTML Document is;<HTML><HEAD>}Heading Section</
HEAD><BODY>}Actual Text (Contents)</BODY></HTML>In every HTML document
<HTML> and </HTML> tags marks the beginning and the end document. These tags in-
form the browser that the document is an HTML file. All other HTML come within
<HTML>....</HTML> tags`
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
48
Second: Table with colspan
<TABLE BORDER=1>
<TR>
<TD COLSPAN=2>Ajay</TD>
<TD>Vijay</TD>
</TR>
<TR>
<TD>Vikas</TD>
<TD>Pankaj</TD>
<TD>Rohan</TD>
</TR>
</TABLE>
Third: Table with rowspan
<TABLE BORDER=1>
<TR>
<TD ROWSPAN=2>Ajay</TD>
<TD>Vijay</TD>
<TD>Rohan</TD>
</TR>
<TR>
<TD>Pankaj</TD>
<TD>Deepak</TD>
</TR>
</TABLE>
Fourth: Table with rowspan and colspan
49
<TABLE BORDER=1>
<TR>
<TD ROWSPAN=2>Ajay</TD>
<TD COLSPAN=2>Vijay</TD>
</TR>
<TR>
<TD>Pankaj</TD>
<TD>Rohan</TD>
</TR>
</TABLE>
Fifth: Table with strong tag and a link in cell’s data
<TABLE BORDER=1>
<TR>
• <TD COLSPAN=3
ALIGN=CENTER><STRONG><AHREF=“http://NEB.org/”>Ajay</STRO
NG>
</TD>
</TR>
<TR>
<TD>Vijay</TD>
<TD>Vikas</TD>
<TD>Pankaj</TD>
</TR>
</TABLE>
</BODY>
</HTML>
• Second: Table with colspan
<TABLE BORDER=1>
<TR>
<TD COLSPAN=2>Ajay</TD>
<TD>Vijay</TD>
</TR>
<TR>
<TD>Vikas</TD>
<TD>Pankaj</TD>
<TD>Rohan</TD>
50
</TR>
</TABLE>
Third: Table with rowspan
<TABLE BORDER=1>
<TR>
<TD ROWSPAN=2>Ajay</TD>
<TD>Vijay</TD>
<TD>Rohan</TD>
</TR>
<TR>
<TD>Pankaj</TD>
<TD>Deepak</TD>
</TR>
</TABLE>
Fourth: Table with rowspan and colspan
<TABLE BORDER=1>
<TR>
<TD ROWSPAN=2>Ajay</TD>
<TD COLSPAN=2>Vijay</TD>
</TR>
<TR>
<TD>Pankaj</TD>
<TD>Rohan</TD>
</TR>
</TABLE>
Fifth: Table with strong tag and a link in cell’s data
<TABLE BORDER=1>
<TR>
• <TD COLSPAN=3
ALIGN=CENTER><STRONG><AHREF=“http://NEB.org/”>Ajay</STRO
NG>
</TD>
</TR>
<TR>
<TD>Vijay</TD>
<TD>Vikas</TD>
<TD>Pankaj</TD>
</TR>
</TABLE>
</BODY>
</HTML>
51
• Form
<HTML
<HEAD>
<TITLE> Welcome to NEB </TITLE>
</HEAD>
<BODY>
<FORM METHOD=POST>
<BR>Checkbox<BR>
<OPTION VALUE=“Ajay”>Ajay
<OPTION VALUE=“Rohan”>Rohan
<OPTION VALUE=“Tarun”>Tarun
52
<OPTION VALUE=“Gagan”>Gagan
<OPTION VALUE=“Harish”>Harish
<OPTION VALUE=“Manjit”>Manjit
</SELECT>
</FORM>
53
• Lisd
• Unordered lists
• <HTML>
<HEAD>
<TITLE>NEB</TITLE>
</HEAD>
<BODY BGCOLOR=“#FFFFFF”>
<<UL>
<LI>English</LI>
<LI>Math </LI>
<LI> Physics</LI>
<LI>Chemistry </LI>
<LI>Botany </LI>
<LI> Zoology</LI>
</UL>
</BODY>
</HTML>
54
• Ordered list.
• <HTML>
<HEAD>
<TITLE>NEB</TITLE>
</HEAD>
<BODY BGCOLOR=“#FFFFFF”>
ute
<OL>
<LI>binoculars</LI>
</OL>
</BODY>
</HTML>
•
55
• Definition lists
<HTML>
<HEAD>
<TITLE>NEB</TITLE>
</HEAD>
<BODY BGCOLOR=“#FFFFFF”>
<DL>
</DD>
</DL
•
56