Practical 1: Familiarization With Programming Enviroment.: Pps Lab Aayush Sharma BTPS 102-18 (1803742)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

PPS LAB AAYUSH SHARMA

BTPS 102-18 (1803742)

Practical 1: Familiarization with Programming Enviroment.


Introduction to Programming Enviroment

A program is a set of instructions written in a language (such as BASIC) understandable by the


computer to perform a particular function on the computer. A well written program could be
parceled well to form an application package customized for solving specific type of problem on
the computer system.
A computer programmer is computer scientist (a professional) skilled in using constructs of
programming languages to develop executable and acceptable computer programs. A software
developer is a programmer. Programmers often work hand in hand with system analysts on large
projects.
Programming languages are artificial notational languages created or developed to be used in
preparing coded instructions on the computer for later execution by the computer. They are
usually composed of series of usage rules (syntax) that determine the meaning (semantics) of
expressions written in the language. Each programming language comes handy with its own
translator i.e interpreter or compiler as the case may be.
Programming is the art of developing computer programs with the aid of selected programming
language by a computer programmer. It is a special skill whose quality is tested by the quality
ofthe resulting program or software. In programming, programming stages must be
properlyfollowed, i.e from problem definition to maintenance and review.

Introduction to C Language.

C is a procedural programming language. It was initially developed by Dennis Ritchie between


1969 and 1973. It was mainly developed as a system programming language to write operating
system. The main features of C language include low-level access to memory, simple set of
keywords, and clean style, these features make C language suitable for system programming
like operating system or compiler development.Many later languages have borrowed
syntax/features directly or indirectly from C language. Like syntax of Java, PHP, JavaScript and
many other languages is mainly based on C language. C++ is nearly a superset of C language .

Characteristics of C Langauge.
Importance of C language. It is a robust language with a rich set of built-in functions and
operators that can be used to write any complex program. The C compiler combines the
capabilities of an assembly language with features of a high-level language. Programs Written in
C are efficient and fast.

1
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

Avantages of Language.

1. C language is a building block for many other currently known languages. C language has
variety of data types and powerful operators. Due to this, programs written in C language are
efficient, fast and easy to understand.

2. Another important advantage of C is its ability to extend itself. A C program is basically a


collection of functions that are supported by the C library this makes us easier to add our own
functions to C library. Due to the availability of large number of functions, the programming task
becomes simple.

3. There are only 32 keywords in ANSI C and its strength lies in its built-in functions. Several
standard functions are available which can be used for developing programs.

Disadvantages of C Language.

1. C does not have concept of OOPs, that’s why C++ is developed.

2. There is no runtime checking in C language.

3. C doesn’t have the concept of namespace.

4. C doesn’t have the concept of constructor or destructor.

Turbo C.

Turbo C was an integrated development environment (IDE) for programming in the C language.
It was developed by Borland and first introduced in 1987. At the time, Turbo C was known for
its compact size, comprehensive manual, fast compile speed and low price. It had many
similarities to an earlier Borland product, Turbo Pascal, such as an IDE, a low price and a fast
compiler, but was not as successful because of competition in the C compiler market.

2
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

Practical 2: Simple Computational Problems Using Arithmatic Expressions

2.1: Write a Program to Add Two Numbers.

#include<stdio.h>

#include<conio.h>

void main()

inta,b,c;

clrscr();

printf("Enter two numbers");

scanf("%d%d",&a,&b);

c=a+b;

printf("Result is %d",c);

getch();

3
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

2.2: Write a Program to Subtract, Multiply and Devide Two Numbers.

#include<stdio.h>

#include<conio.h>

void main()

inta,b,c,d,e,f;

clrscr();

printf("Enter two numbers");

scanf("%d%d",&a,&b);

c=a+b;

d=a-b;

e=a*b;

f=a/b;

printf("Result of addition is %d \n",c);

printf("Result of subtraction is%d \n",d);

printf("Result of multiplication is %d \n",e);

printf("Result of division is %d \n",f);

getch();

4
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

2.3: Write a Program to Find Average of Four Numbers.

#include<stdio.h>

#include<conio.h>

void main()

inta,b,c,d,e,f;

clrscr();

printf("Enter Four Numbers");

scanf("%d%d%d%d",&a,&b,&c,&d);

e=a+b+c+d;

f=e/4;

printf("Sum is %d \n",e);

printf("Average is %d",f);

getch();

5
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

2.4: Write a Program to find Percentage of Two Numbers.

#include<stdio.h>

#include<conio.h>

void main()

floata,b,c;

clrscr();

printf("Enter two numbers");

scanf("%f%f",&a,&b);

c=(a/b)*100;

printf("Percentage is %f",c);

getch();

6
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

2.5:Write a Program to Swap Two Numbers.

#include<stdio.h>

#include<conio.h>

void main()

inta,b;

clrscr();

printf("Enter two numbers");

scanf("%d%d",&a,&b);

a=a+b;

b=a-b;

a=a-b;

printf("Value of swapping is %d %d",a,b);

getch();

7
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

Practical 3: Problems Involving if-Then-else Structutre.


3.1: Write a Program to Find Greater Number Among Two Given Numbers Using if
Condition.

#include<stdio.h>

#include<conio.h>

void main()

inta,b;

clrscr();

bprintf("Enter two numbers");

scanf("%d%d",&a,&b);

if(a>b)

printf("a is greater");

if(b>a)

printf("b is greater");

getch();

8
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

3.2: Write a Program to Find Greater Number Among Two Given Numbers Using if-else
Condition.

#include<stdio.h>

#include<conio.h>

void main()

inta,b;

clrscr();

printf("Enter two numbers");

scanf("%d%d",&a,&b);

if(a>b)

printf("a is greater");

else

printf("b is greater");

getch();

9
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

3.3: Write a Program to Find Greatest Number Among Three Given Number Using Nested
if Condition.

#include<stdio.h>

#include<conio.h>

void main()

inta,b,c;

clrscr();

printf("Enter three numbers");

scanf("%d%d%d",&a,&b,&c);

if(a>b)

if(a>c)

printf("a is greater");

else

printf("c is greater");

else

if(b>c)

10
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

printf("b is greater");

else

printf("c is greater");

getch();

11
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

3.4:Write A Program To Show The Use Of Else- If Ladder Statement.


#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("enter any number");
scanf("%d",&a);
if(a==1)
printf("a");
else if(a==2)
printf("b");
else if(a==3)
printf("c");
else if(a==4)
printf("d");
else
printf("wrong output");
getch();
}

12
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

Practical 4: Itrative Statements.


4.1: Write A Program To Print First ‘n’ Natural Number Using For Loop.
#include<stdio.h>
#include<conio.h>
void main()
{
intn,i;
clrscr();
printf("enter n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf(" %d ",i);
}
getch();
}

13
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

4.2 Write A Program To Print First ‘n’ Natural Number Using While Loop.
#include<stdio.h>
#include<conio.h>
void main()
{
intn,i;
clrscr();
printf("enter n");
scanf("%d",&n);
i=1;
while(i<=n)
{
printf(" %d ",i);
i++;
}
getch();
}

14
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

4.3: Write A Program To Print First ‘n’ Natural Numbers Using Do While Loop.
#include<stdio.h>
#include<conio.h>
void main()
{
intn,i;
clrscr();
printf("enter n");
scanf("%d",&n);
i=1;
do
{
printf(" %d ",i);
i++;
}
while(i<=n);
getch();
}

15
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

4.4: Write A Program To Show The Use Of Goto Statement.


#include<stdio.h>
#include<conio.h>
void main()
{
int a=10,b=20,c,d,e;
clrscr();
c=a+b;
printf("sum is %d",c);
gotoaayush;
d=a-b;
printf("substraction is %d",d);
aayush:
e=a*b;
printf("multiply is %d",e);
getch();
}

16
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

4.5: Write A Program To Show The Use Of Break Statement.


#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=5;i++)
{
if(i==3)
{
break;
}
printf(" %d ",i);
}
getch();

17
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

4.6: Write A Program To Show The Use Of Continue Statement.


#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=5;i++)
{
if(i==3)
{
continue;
}
printf(" %d ",i);
}
getch();
}

18
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

4.7:Write a Program to Sum of n Natural Numbers.


#include<stdio.h>
#include<conio.h>
void main()
{
inti,n,sum=0;
clrscr();
printf("enter any number");
scanf("%d",&n);
for(i=1;i<=n;i++)
sum=sum+i;
printf("sum is %d",sum);
getch();
}

4.8:Write a Program to Find Factorial of Natural Numbers.

19
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,factorial=1;
clrscr();
printf("enter any value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
factorial=factorial*i;
}
printf("factorial is %d",factorial);
getch();
}

Practical 5: 1-Dimensional Array.

20
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

5.1: Write a Program To Display Elements of Array.


#include<stdio.h>

#include<conio.h>

void main()

int i,a[5]={5,6,7,8,9};

clrscr();

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

printf("%d",a[i]);

getch();

5.2: Write a Program to Read an Array From User and Display it.

21
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)

#include<stdio.h>

#include<conio.h>

void main()

int a[10],i,n;

clrscr();

printf("enter size of array");

scanf("%d",&n);

printf("enter elements of array");

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

scanf("%d",&a[i]);

printf("elements are");

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

printf("%d",a[i]);

getch();

22

You might also like