Practical 1: Familiarization With Programming Enviroment.: Pps Lab Aayush Sharma BTPS 102-18 (1803742)
Practical 1: Familiarization With Programming Enviroment.: Pps Lab Aayush Sharma BTPS 102-18 (1803742)
Practical 1: Familiarization With Programming Enviroment.: Pps Lab Aayush Sharma BTPS 102-18 (1803742)
Introduction to 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.
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.
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)
#include<stdio.h>
#include<conio.h>
void main()
inta,b,c;
clrscr();
scanf("%d%d",&a,&b);
c=a+b;
printf("Result is %d",c);
getch();
3
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)
#include<stdio.h>
#include<conio.h>
void main()
inta,b,c,d,e,f;
clrscr();
scanf("%d%d",&a,&b);
c=a+b;
d=a-b;
e=a*b;
f=a/b;
getch();
4
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)
#include<stdio.h>
#include<conio.h>
void main()
inta,b,c,d,e,f;
clrscr();
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)
#include<stdio.h>
#include<conio.h>
void main()
floata,b,c;
clrscr();
scanf("%f%f",&a,&b);
c=(a/b)*100;
printf("Percentage is %f",c);
getch();
6
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)
#include<stdio.h>
#include<conio.h>
void main()
inta,b;
clrscr();
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
getch();
7
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)
#include<stdio.h>
#include<conio.h>
void main()
inta,b;
clrscr();
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();
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();
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)
12
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)
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)
16
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)
17
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)
18
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)
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();
}
20
PPS LAB AAYUSH SHARMA
BTPS 102-18 (1803742)
#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();
scanf("%d",&n);
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