Rijul_PPS
Rijul_PPS
1
RIJUL, 312/24, BTPS 102-18
2
RIJUL, 312/24, BTPS 102-18
PROGRAM 1
FLOWCHART:
START
PRINT “HELLO
WORLD”
STOP
PROGRAM:
#include<stdio.h>
#include<conio.h
> void main()
{
printf("Hello
world"); getch();
}
OUTPUT:
3
RIJUL, 312/24, BTPS 102-18
PROGRAM 2
FLOWCHART:
START
SUM = A+B
PRINT SUM
STOP
4
RIJUL, 312/24, BTPS 102-18
PROGRAM:
#include <stdio.h>
#include
<conio.h> int
main()
{
float a,b,c;
printf("ENTER FIRST NUMBER: \n");
scanf("%f",&a);
printf("ENTER SECOND NUMBER: \n");
scanf("%f",&b);
c=(a+b);
printf("the sum of the numbers is: %f
\n",c); getch();
return 0;
}
OUTPUT:
5
RIJUL, 312/24, BTPS 102-18
PROGRAM 3
FLOWCHART:
START
SI=(P*R*T)/100
PRINT SI
STOP
6
RIJUL, 312/24, BTPS 102-18
PROGRAM:
#include <stdio.h>
#include
<conio.h> int
main()
{
float p, r, t, s, q;
printf("enter principal amount: ");
scanf("%f", &p);
printf("enter rate: ");
scanf("%f", &r);
printf("enter time: ");
scanf("%f", &t);
s=((p*r*t)/100);
printf("simple interest is: %f
\n",s); q=s+p;
printf("total amount is: %f \n",q);
}
OUTPUT:
7
RIJUL, 312/24, BTPS 102-18
PROGRAM 4
FLOWCHART:
START
INPUT a
Calculate b=sqrt(a)
C= pow(a,3)
PRINT b,c
STOP
8
RIJUL, 312/24, BTPS 102-18
PROGRAM:
#include<stdio.h>
#include<conio.h
>
#include<math.h
> void main()
{
float a,b,c;
printf("enter a number, a=");
scanf("%f",&a);
b=sqrt(a);
c=pow(a,3);
printf("%f is the square root
\n",b); printf("%f is the
power",c);
getch();
}
OUTPUT:
9
RIJUL, 312/24, BTPS 102-18
PROGRAM 5
FLOWCHART:
START
ENTER A
NUMBER
YES NO
IF A>B
PRINT A IS
PRINT B IS
GREATER
GREATER
STOP
10
RIJUL, 312/24, BTPS 102-18
PROGRAM:
#include<stdio.h>
#include<conio.h
> void main()
{
int a,b;
printf("enter a number,
a="); scanf("%d",&a);
printf("enter a number,
b="); scanf("%d",&b);
if (a>b)
printf("%d is
greater",a); else
printf("%d is
greater",b); getch();
}
OUTPUT:
11
RIJUL, 312/24, BTPS 102-18
PROGRAM 6
FLOWCHART:
START
ENTER 3
NUMBERS
IF a>b
if if
b>c a>c
PRINT C IS
LARGEST
PRINT B IS PRINT A IS
LARGEST LARGEST
STOP
12
RIJUL, 312/24, BTPS 102-18
PROGRAM:
#include<stdio.h>
#include<conio.h
> void main()
{
float a,b,c;
printf("enter a number, a=");
scanf("%f",&a);
printf("enter a number, b=");
scanf("%f",&b);
printf("enter a number, c=");
scanf("%f", &c);
if(a>b && a>c)
printf("%f is the greatest",
a); else if (b>c)
printf("%f is the greatest",
b); else
printf("%f is the greatest", c);
getch();
}
OUTPUT:
13
RIJUL, 312/24, BTPS 102-18
PROGRAM 7
FLOWCHART:
START
READ THE
VALUE OF N
i=1
FALSE
IF i>N
TRUE
PRINT i
i=i+1
STOP
14
RIJUL, 312/24, BTPS 102-18
PROGRAM:
#include<stdio.h>
#include<conio.h
> void main()
{
int i;
for(i=1; i<=10; i=i+1)
{
printf("%d \n",i);
}
getch();
}
OUTPUT:
15
RIJUL, 312/24, BTPS 102-18
PROGRAM 8
FLOWCHART:
START
READ THE
VALUE OF N
i=2
FALSE
IF i<n
TRUE YES NO
IF
i==n
i=i+1
STOP
16
RIJUL, 312/24, BTPS 102-18
PROGRAM:
#include<stdio.h>
#include<conio.h
> void main()
{
int a,b=0,c,d;
printf("enter any
number=");
scanf("%d",&a);
for(c=2;c<a;c++)
{
d=a%c;
if(d==0)
{
b=1;
}
}
if(b==0)
printf("the number entered is a prime
number"); else
printf("the number entered is not a prime number");
getch();
}
OUTPUT:
17
RIJUL, 312/24, BTPS 102-18
PROGRAM 9
FLOWCHART:
START
READ num
Reverse=0
tempNum=num
FALSE
Num!=0
TRUE
Rem=num%10
Reverse*=10+rem
Num=num/10 Reverse
==num
PALINDROME
NOT A
PALINDROME
STOP
18
RIJUL, 312/24, BTPS 102-18
PROGRAM:
#include<stdio.h>
#include<conio.h
> void main()
{
int n, rev=0, rem, orig;
printf("enter an integer,
n="); scanf("%d",&n);
orig=n;
while(n!=0)
{
rem=n%10; rev=rev*10 + rem; n=n/10;
}
if(orig == rev)
printf("%d is a palindrome number",orig);
else
printf("%d is not a palindrome number",orig);
getch();
}
OUTPUT:
19
RIJUL, 312/24, BTPS 102-18
PROGRAM 10
FLOWCHART:
START
ENTER NUMBER OF
ROWS
Int n
I=1, I++
j<=n
J=1, J++
j<=1
Printf(“*”)
Printf(“\n”)
STOP
20
RIJUL, 312/24, BTPS 102-18
PROGRAM:
#include<stdio.h>
#include<conio.h
> void main()
{
int n;
printf("enter the number of rows:");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
OUTPUT:
21
RIJUL, 312/24, BTPS 102-18
PROGRAM 11
AIM: WRITE A PROGRAM TO FIND AVERAGE OF N NUMBERS USING
AN ARRAY
PROGRAM:
#include<stdio.h>
#include<conio.h>
int main()
{
int i , n , average , sum=0;
int marks[20];
printf("enter the number of marks to be entered: \n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter number %d: ", i+1);
scanf("%d", &marks[i]);
sum=sum+marks[i];
}
average= sum/n;
printf("the average of %d numbers is %d \n", n , average);
return 0;
}
OUTPUT:
22
RIJUL, 312/24, BTPS 102-18
PROGRAM 12
AIM: WRITE A PROGRAM TO USE STRING FUNCTIONS
PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
char s1[25],s2[25],s3[50];
int x, l1, l2, l3;
printf("ENTER FIRST STRING CONSTANT: \n");
scanf("%s", s1);
printf("ENTER SECOND STRING CONSTANT: \n");
scanf("%s", s2);
strcat(s1,s2);
strcpy(s3,s1);
l1=strlen(s1);
l2=strlen(s2);
l3=strlen(s3);
printf("s1= %s \t length= %d characters \n",s1, l1);
printf("s2= %s \t length= %d characters \n",s2, l2);
printf("s3= %s \t length= %d characters \n",s3, l3);
printf("MODIFY THE STRING TO LOWER CASE \n");
printf("%s \n", strlwr(s1));
printf("MODIFY THE STRING TO UPPER CASE \n");
printf("%s \n", strupr(s1));
}
23
RIJUL, 312/24, BTPS 102-18
OUTPUT:
24
RIJUL, 312/24, BTPS 102-18
PROGRAM 13
AIM: WRITE A PROGRAM TO FIND SUM OF TWO MATRICES
PROGRAM:
#include <stdio.h>
#include<conio.h>
int main()
{
int r, c, a[20][20], b[20][20], sum[20][20], i, j;
printf("Enter the number of rows (between 1 and 20): ");
scanf("%d", &r);
printf("Enter the number of columns (between 1 and 20): ");
scanf("%d", &c);
25
RIJUL, 312/24, BTPS 102-18
return 0;
}
OUTPUT:
26
RIJUL, 312/24, BTPS 102-18
PROGRAM 14
AIM: WRITE A PROGRAM FOR (A) LINEAR SEARCH
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int list[20], size, i, Selement;
printf("ENTER THE SIZE OF LIST \n");
scanf("%d", &size);
printf("ENTER THE INTEGERS \n");
for(i=0;i<size;i++)
scanf("%d", &list[i]);
printf("ENTER THE ELEMENT TO BE SEARCHED \n");
scanf("%d",&Selement);
for(i=0;i<size;i++)
{
if(Selement==list[i])
{
printf("ELEMENT IS FOUND AT %d INDEX ",i);
break;
}
}
if(i==size)
printf("GIVEN ELEMENT IS NOT FOUND IN THE LIST!");
getch();
}
27
RIJUL, 312/24, BTPS 102-18
OUTPUT:
28
RIJUL, 312/24, BTPS 102-18
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int c, first, last, middle, n, search, array[100];
printf("ENTER NUMBER OF ELEMENTS \n");
scanf("%d", &n);
printf("ENTER %d INTEGERS IN ASCENDING ORDER \n",n);
for(c=0;c<n;c++)
{
scanf("%d",&array[c]);
}
printf("ENTER VALUE TO FIND: \n");
scanf("%d", &search);
first=0;
last=(n-1);
middle= (first+last)/2;
while(first<=last)
{
if(array[middle]<search)
first= middle+1;
else if(array[middle]== search)
{
printf("%d FOUND AT LOCATION %d \n", search, middle+1);
break;
}
else
last= middle-1;
middle=(first+last)/2;
}
if(first>last)
printf("NOT FOUND! %d IS NOT PRESENT IN THE LIST \n", search);
29
RIJUL, 312/24, BTPS 102-18
OUTPUT:
30
RIJUL, 312/24, BTPS 102-18
PROGRAM 15
AIM: WRITE A PROGRAM TO IMPLEMENT (A) BUBBLE SORT
PROGRAM:
#include<stdio.h>
#include<conio.h>
int main()
{
int count, temp, i, j, number[30];
printf("HOW MANY NUMBERS TO ENTER \n");
scanf("%d", &count);
printf("ENTER %d NUMBERS \n", count);
for(i=0;i<count;i++)
scanf("%d", &number[i]);
for(i=count-2; i>=0; i--)
{
for(j=0;j<=i;j++)
{
if(number[j]> number[j+1])
{
temp=number[j];
number[j]= number[j+1];
number[j+1]=temp;
}
}
}
printf("SORTED ELEMENTS: \n");
for(i=0;i<count;i++)
printf("%d \n", number[i]);
return 0;
}
31
RIJUL, 312/24, BTPS 102-18
OUTPUT:
32
RIJUL, 312/24, BTPS 102-18
PROGRAM:
#include<stdio.h>
#include<conio.h>
int main()
{
int i, j, count, temp, number[25];
printf("HOW MANY NUMBERS ARE TO BE ENTERED \n");
scanf("%d", &count);
printf("ENTER %d ELEMENTS \n", count);
for(i=0;i<count;i++)
scanf("%d", &number[i]);
for(i=0;i<count;i++)
{
for(j=i+1; j<count; j++)
{
if(number[i] > number[j])
{
temp= number[i];
number[i]= number[j];
number[j]=temp;
}
}
}
printf("SORTED ELEMENTS \n");
for(i=0;i<count;i++)
{
printf("%d \n", number[i]);
}
return 0;
}
33
RIJUL, 312/24, BTPS 102-18
OUTPUT:
34
RIJUL, 312/24, BTPS 102-18
PROGRAM:
#include<stdio.h>
#include<conio.h>
int main()
{
int i, j, n, temp, a[30];
printf("ENTER THE NUMBER OF ELEMENTS \n");
scanf("%d",&n);
printf("ENTER THE ELEMENTS \n");
for(i=0;i<n;i++)
scanf("%d \n", &a[i]);
for(i=1;i<=n-1;i++)
{
temp= a[i];
j=i-1;
while((temp < a[j])&&(j>=0))
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=temp;
}
printf("SORTED LIST IS: \n");
for(i=0;i<n;i++)
{
printf("%d \n",a[i]);
}
return 0;
}
35
RIJUL, 312/24, BTPS 102-18
OUTPUT:
36
RIJUL, 312/24, BTPS 102-18
PROGRAM 16
AIM: WRITE A PROGRAM TO FIND ROOTS OF QUADRATIC
EQUATION
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,d,r,r1,r2;
printf("ENTER COEFFICIENTS A B AND C\n");
scanf("%f %f %f",&a, &b, &c);
d=(b*b)-(4*a*c);
printf("the value of D is %f \n", d);
if(d>0)
{
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("THE FIRST ROOT IS %f", r1);
printf("THE SECOND ROOT IS %f", r2);
}
if(d==0)
{
r=-b/(2*a);
printf("ROOTS ARE EQUAL \n");
printf("ROOT 1 = ROOT 2 = %f",r);
}
if(d<0)
{
printf("ROOTS ARE NOT REAL");
}
getch();
}
37
RIJUL, 312/24, BTPS 102-18
OUTPUT:
38
RIJUL, 312/24, BTPS 102-18
PROGRAM 17
AIM: WRITE A PROGRAM TO SWAP BY CALL BY VALUE
PROGRAM:
#include<stdio.h>
#include<conio.h>
void swap(int x, int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("x=%d, y=%d",x,y);
}
void main()
{
int a,b;
printf("enter two numbers x and y: ");
scanf("%d %d",&a, &b);
swap(a,b);
}
OUTPUT:
39
RIJUL, 312/24, BTPS 102-18
PROGRAM 18
AIM: WRITE A PROGRAM TO SWAP BY CALL BY REFERENCE
PROGRAM:
#include<stdio.h>
#include<conio.h>
void swap(int *x, int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
printf("x=%d, y=%d",*x,*y);
}
void main()
{
int a,b;
printf("enter two numbers x and y: ");
scanf("%d %d",&a, &b);
swap(&a,&b);
}
OUTPUT:
40
RIJUL, 312/24, BTPS 102-18
PROGRAM 19
AIM: WRITE A PROGRAM TO PASS ARRAYS IN FUNCTION
PROGRAM:
#include<stdio.h>
void display(int age)
{
printf("%d", age);
}
int main()
{
int ageArray[]={2,3,4};
display(ageArray[2]);
return 0;
}
OUTPUT:
41
RIJUL, 312/24, BTPS 102-18
PROGRAM 20
AIM: WRITE A PROGRAM TO CALCULATE FACTORIAL USING
RECURSION
PROGRAM:
#include<stdio.h>
int fact(int i)
{
if (i<=1)
return 1;
else
return i*fact(i-1);
}
int main()
{
int n;
printf("ENTER A POSITIVE INTEGER \n");
scanf("%D", &n);
printf("FACTORIAL OF %d IS %d", n, fact(n));
return 0;
}
OUTPUT:
42
RIJUL, 312/24, BTPS 102-18
PROGRAM 21
AIM: WRITE A PROGRAM TO DISPLAY FIBONACCI SERIES USING
RECURSION
PROGRAM:
#include<stdio.h>
int fib(int n)
{
if(n==0)
return 0;
else if(n==1)
return 1;
else
return (fib(n-1)+fib(n-2));
}
int main()
{
int k, i=0,c;
printf("ENTER THE NUMBER \n");
scanf("%d",&k);
printf("FIBONACCI SERIES \n");
for(c=1;c<=k;c++)
{
printf("%d \n", fib(i));
i++;
}
return 0;
}
43
RIJUL, 312/24, BTPS 102-18
OUTPUT:
44
RIJUL, 312/24, BTPS 102-18
PROGRAM 22
AIM: WRITE A PROGRAM TO IMPLEMENT QUICK SORT
PROGRAM:
#include<stdio.h>
void quicksort(int number[25], int first, int last)
{
int i, j, pivot, temp;
if(first<last)
{
pivot = first;
i = first;
j = last;
while(i<j)
{
while(number[i]<=number[pivot] && i<last)
i++;
while(number[j]> number[pivot])
j--;
if(i<j)
{
temp = number[i];
number[i] = number[j];
number[j] = temp;
}
}
temp= number[pivot];
number[pivot]=number[j];
number[j]=temp;
quicksort(number, first, j-1);
quicksort(number, j+1, last);
}
}
int main()
{
int i, count, number[25];
45
RIJUL, 312/24, BTPS 102-18
OUTPUT:
46
RIJUL, 312/24, BTPS 102-18
PROGRAM 23
AIM: WRITE A PROGRAM TO IMPLEMENT MERGE SORT
PROGRAM:
#include<stdio.h>
void mergesort(int a[], int i, int j);
void merge(int a[], int i1, int j1, int i2, int j2);
int main()
{
int a[30],n,i;
printf("ENTER THE NUMBER OF ELEMENTS \n");
scanf("%d", &n);
printf("ENTER ARRAY ELEMENTS \n");
for(i=0;i<n;i++)
scanf("%d" ,&a[i]);
mergesort(a,0,n-1);
printf("THE SORTED ARRAY IS \n");
for(i=0;i<n;i++)
printf("%d \n",a[i]);
return 0;
}
void mergesort(int a[], int i, int j)
{
int mid;
if(i<j)
{
mid=(i+j)/2;
mergesort(a,i,mid);
mergesort(a, mid+1,j);
merge(a,i,mid,mid+1,j);
}
}
void merge(int a[], int i1, int j1, int i2, int j2)
{
int temp[50];
int i,j,k;
47
RIJUL, 312/24, BTPS 102-18
i=i1;
j=i2;
k=0;
while(i<=j1 && j<=j2)
{
if(a[i]<a[j])
temp[k++]=a[i++];
else
temp[k++]=a[j++];
}
while(i<=j1)
temp[k++]=a[i++];
while(j<=j2)
temp[k++]=a[j++];
for(i=i1,j=0; i<=j2;i++,j++)
a[i]=temp[j];
}
OUTPUT:
48
RIJUL, 312/24, BTPS 102-18
PROGRAM 24
AIM: WRITE A PROGRAM TO IMPLEMENT STRUCTURES
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
{
int rollno;
char name[10];
};
int main()
{
int i;
struct student st[5];
printf("ENTER RECORDS OF 5 STUDENTS \n");
for(i=0;i<5;i++)
{
printf("ENTER ROLLNO: \n");
scanf("%d", &st[i].rollno);
printf("ENTER NAME: \n");
scanf("%s", &st[i].name);
}
printf(" STUDENT INFORMATION LIST \n");
for(i=0;i<5;i++)
{
printf("ROLLNO: %d , NAME: %s", st[i].rollno, st[i].name);
}
getch();
return 0;
49
RIJUL, 312/24, BTPS 102-18
OUTPUT:
50
RIJUL, 312/24, BTPS 102-18
PROGRAM 25
AIM: WRITE A PROGRAM TO IMPLEMENT POINTERS
PROGRAM:
#include<stdio.h>
#include<conio.h>
int main()
{
int var=20;
int *ip;
ip= &var;
printf("ADDRESS OF VARIABLE VAR: %x \n", &var);
printf("ADDRESS STORED IN IP VARIABLE: %x \n", ip);
printf("VALUE OF *IP VARIABLE IS %d \n", *ip);
return 0;
}
OUTPUT:
51