[go: up one dir, main page]

0% found this document useful (0 votes)
19 views68 pages

Tally Notes

The document is an assignment report on programming in C submitted by Mohammed Jubaid to Hemchand Yadav University in partial fulfillment of the requirements for a Post Graduate Diploma in Computer Application. It contains 30 programming problems solved in C language with outputs related to checking even-odd numbers, finding the greatest among three numbers, swapping numbers with and without third variable, patterns printing using loops, Fibonacci series, Lucas series, factorials, prime checking, Armstrong number checking, array operations and functions.

Uploaded by

shabansheikh75
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views68 pages

Tally Notes

The document is an assignment report on programming in C submitted by Mohammed Jubaid to Hemchand Yadav University in partial fulfillment of the requirements for a Post Graduate Diploma in Computer Application. It contains 30 programming problems solved in C language with outputs related to checking even-odd numbers, finding the greatest among three numbers, swapping numbers with and without third variable, patterns printing using loops, Fibonacci series, Lucas series, factorials, prime checking, Armstrong number checking, array operations and functions.

Uploaded by

shabansheikh75
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 68

Programming in ‘C’ PGDCA (2023-24)

AN
Assignment
Report
On

PROGRAMING IN “C”
Submitted in partial fulfilment of the requirements for
the award of diploma

Post Graduate Diploma in Computer Application


(PGDCA, SEM-1)
From
Hemchand Yadav University Durg (C.G.)

Guided By
Submitted by:

GOPAL DEWANGAN SIR MOHAMMED JUBAID

INDIRA GANDHI GOVERNMENT ARTS SCIENCE AND COMMERCE


. COLLEGE
VAISHALI NAGAR BHILAI

Hemchand Yadav University (Durg) (C.G.)

Page 1
Programming in ‘C’ PGDCA (2023-24)

CERTIFICATE OF APPROVAL

This is to certify that the project work entitled “Office Automation


and Tally” is carried out by “MOHAMMED JUBAID”, a student of
PGDCA-I at “INDIRA GANDHI GOVERNMENT ARTS SCIENCE AND
COMMERCE COLLEGE ” is here by approved as a credible work in the
discipline of computer science & information technology for the
award of degree of Post Graduate Diploma in Computer Application
during the year 2023-2024 from Hemchand Yadav University
(Durg) (C.G.).

MR. SURESH KUMAR THAKUR

H.O.D (COMPUTER DEPARTMENT)

Page 2
Programming in ‘C’ PGDCA (2023-24)

CERTIFICATE OF GUIDE

This is to certify that the project work entitled “Office


Automation and Tally“ submitted to the “INDIRA GANDHI
GOVERNMENT ARTS SCIENCE AND COMMERCE COLLEGE ” by
“MOHAMMED JUBAID” roll no

in partial fulfillment for the requirements relating


to nature & standard of the award of degree of “Post Graduate
Diploma in Computer Application” diploma by “ Hemchand Yadav
University (Durg) (C.G.)” for the academic year 2023-2024.

This project work has been carried out under my guidance.

MR. GOPAL DEWANGAN


……………………………………..

Page 3
Programming in ‘C’ PGDCA (2023-24)

DECLARATION/SELF CERTIFICATE

This is to certify that the project work entitled “Office Automation


and Tally” which is submitted by me in the partial fulfillment for the
award of degree of “Post Graduate Diploma in Computer
Application” “INDIRA GANDHI GOVERNMENT ARTS SCIENCE AND
COMMERCE COLLEGE ” comprises the original work carried out by
me.

I further declare that the work reported in the project has


not been submitted & will not be submitted, either in part or in
full award of any other degree or diploma in this institute or any
other institute or university.

PLACE :- BHILAI NAME:- MOHAMMED


JUBAID

DATE :- ……/…../……. ROLL NO.

Page 4
Programming in ‘C’ PGDCA (2023-24)

ACKNOWLEDGEMENT

We are very delighted on the accomplishment of the project in visual


basic, which was very educational and practically beneficial. It is due to his
encouragement and persistent motivation that i could extent the scope of
project to much useful data processing report. We have specially thankful to Mr.
GOPAL DEWANGAN SIR the INDIRA GANDHI GOVERNMENT ARTS SCIENCE
AND COMMERCE COLLEGE who helps us by his deep knowledge and
practical experience in computer science, rendered all possible in fulfillment of
the project and for explaining the method of approach. So system development
is the pooling of talents, extends help and cooperation above as a team effort.

Page 5
Programming in ‘C’ PGDCA (2023-24)

INDEX

S.NO OBJECTS OF PRACTICALS DATE PG.NO SIGN.

1 Write a program in c to check whether a given number is even or odd.

2 Write a program in c to find out greatest number among three


number.

3 Write a program in c to swap 2 number using 3rd variable.

4 Write a program in c to swap 2 number without using 3rd


variable.

5 Write a program to print following pattern using for loop.


* 1 1
** 22 12

*** 333 123

**** 4444 1234

***** 55555 12345

* 1 1
** 22 12

* * * 333 123

**** 4444 1234

* * * * * 55555 12345

6 Write a prog ram in c to print Fibonacci ser iies.

7 Write a program in c to print Luca’s series.

8 Write a program in c to calculate factorial of a given number.

9 Write a program in c to check whether a given number is


prime or not.

10 Write a program in c to weather a given number is Armstrong or not.

11 Write a program in c to search an element in 1D array.

12 Write a program in c to sort element in 1D array.

13 Write a program in c to perform addition of 2 matrix.

14 Write a program in c to perform subtraction of 2 matrix.

Page 6
Programming in ‘C’ PGDCA (2023-24)

15 Write a program in c to perform multiplication of 2


matrix.

16 Write a program in c to create a function name power(a,b) and it calculate a


raised to b.
Write a program in c to print day name according to given
17 number. (1=Sunday)

18 Write a program in c to check weather a given String is Palindrome or not.

19 Write a program in c to swap 2 number using pointer.

20 Write a program in c to demonstrate call by value.

21 Write a program in c to demonstrate call by reference.

22 Write a program in c to calculate factorial using recursion.

23 Write a program in c to calculate length of string without using string handling


function.
24 Write a program in c to create a structure employee with data members (id, name,
salary) to store the id, name, salary and print values of data members.

25 Write a program in c to check whether a given no is positive or negative


26
Write a program in c to perform arithmetic operation as per user’s choice.
27 Write a program in c to reverse the digit of any no using for loop

28 Write a program in c to check whether a given character is vowel or consonant

29 Write a program in c to reverse a string without using library function .Write user
defined function.
30 Write a program in c to calculate length of string without using string handling
function.

Program- 1

 Write a program in c to check whether a given number is even or odd.

Page 7
Programming in ‘C’ PGDCA (2023-24)

Source code :

#include<stdio.h>
#include<conio.h> void
main()

int a,b; clrscr();


printf("**** To check given no. is odd or even ****\n");
printf("\n Enter a number = ");
scanf("%d",&a); b=a%2;
printf("\n******** RESULT ********\n"); if(b==0)
{

printf("\n%d is an Even number",a);

else

printf("\n%d is an Odd number",a);

getch();

------------------------------------------ Output:- -------------------------------------------

Program- 2

 Write a program in c to find out greatest number among three number.

Source code :
#include<stdio.h>

#include<conio.h> void main()

Page 8
Programming in ‘C’ PGDCA (2023-24)

{ int a,b,c; clrscr();

printf("------* Find greatest among Three numbers *------\n"); printf("Enter value

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

printf("\nEnter value b=");

scanf("%d",&b); printf("\nEnter value c=");

scanf("%d",&c);

printf("\n------------* Result *------------"); if(a>b)

if(a>c) printf("\na is greatest=%d",a);

else printf("\nc is greatest=%d",c);

else

if(b>c) printf("\n b is greatest=%d",b);

else printf("\n c is greatest=%d",c);

getch();

------------------------------------------ Output:- -------------------------------------------

Program- 3
 Write a program in c to swap 2 numbers using 3rd variable.

Source code :
#include<stdio.h>

#include<conio.h> void

main()

Page 9
Programming in ‘C’ PGDCA (2023-24)

{ int a,b,c; clrscr();

printf("-----------** find square root **-----------");

printf("\nValue of first no. before swap= ");

scanf("%d",&a);

printf("Value of second no. before swap = ");

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

printf("---------- result ----------");

printf("\nValue of first no. after swap = %d",a);

printf("\nValue of second no. after swap = %d",b);

getch();

------------------------------------------ Output:- --------------------------------------------

Program- 4

 Write a program in c to swap 2 number without using 3rd variable.

Source code :
#include<stdio.h>

#include<conio.h> void

main()

{ int a,b; clrscr();

Page 10
Programming in ‘C’ PGDCA (2023-24)

printf("***Before Swapping***\n");

printf("\nvalue of first number = ");

scanf("%d",&a);

printf("value of second number =");

scanf("%d",&b);

a=a+b; b=a-b; a=a-b;

printf("\n***After Swapping***\n");

printf("\nvalue of first number = %d",a);

printf("\nvalue of second number = %d",b);

getch();

--------------------------------------------- Output:- --------------------------------------------

Program- 5(A)

 Write a program to print following pattern using for loop.

Source code :

Page 11
Programming in ‘C’ PGDCA (2023-24)

#include<stdio.h>

#include<conio.h> void

main()

{ int i,j; clrscr();

printf("OUTPUT Pattern :\n");

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

for(j=1;j<=i;j++)

{ printf("*

");

printf("\n");

getch();

------------------------------------------- Output:- ---------------------------------------------

Program- 5(B)

 Write a program to print following pattern using for loop.

Page 12
Programming in ‘C’ PGDCA (2023-24)

Source code :
#include<stdio.h>

#include<conio.h> void

main()

{ int i,j; clrscr();

printf("OUTPUT Pattern : \n");

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

for(j=1;j<=i;j++)

printf(" %d",i);

printf("\n");

getch();

---------------------------------------------------------Output:- -----------------------------------------------------

Page 13
Programming in ‘C’ PGDCA (2023-24)

Program- 5(C)

 Write a program to print following pattern using for loop.

Source code :
#include<stdio.h>

#include<conio.h> void

main()

{ int i,j; clrscr(); printf("OUTPUT

Pattern ; \n"); for(i=1;i<=5;i++)

for(j=1;j<=i;j++)

printf(" %d",j);

printf("\n");

getch();

--------------------------------------------------------- Output:- ------------------------------------------------------

Page 14
Programming in ‘C’ PGDCA (2023-24)

Program- 5(D)

 Write a program to print following pattern using for loop.

Source code :
#include<stdio.h>

#include<conio.h> void main()

{ int i,j,s; clrscr(); printf("OUTPUT

Pattern : \n"); for(i=1;i<=5;i++)

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

printf(" ");

for(s=1;s<=i;s++)

{ printf("* ");

printf("\n");

getch();

Page 15
Programming in ‘C’ PGDCA (2023-24)

------------------------
---------------------
Output:-
------------------------
-------------------

Page 16
Programming in ‘C’ PGDCA (2023-24)

Page 17
Programming in ‘C’ PGDCA (2023-24)

Program- 5(E)

 Write a program to print following pattern using for loop.

Source code :
#include<stdio.h>

#include<conio.h> void

main()

{ int i,j,s; clrscr(); printf("OUTPUT

Pattern : \n"); for(i=1;i<=5;i++)

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

printf(" ");

for(s=1;s<=i;s++)

printf("%d ",i);

printf("\n");

getch();

---------------------------------------------------------- Output:- -----------------------------------------------------------

Page 18
Programming in ‘C’ PGDCA (2023-24)

Program 6

 Write a program in c to print Fibonacci series.

Source code :
#include<stdio.h>

#include<conio.h> void

main()

{ int a,b,c,i,n; clrscr();

printf("Enter limit= ");

scanf("%d",&n); a=0; b=1;

printf("Fibonacci series :");

printf("%d ",a); printf("%d

",b);

for(i=1;i<=n-2;i++)

c=a+b;

printf("%d ",c);

a=b; b=c;

getch();

-----------------------
----------------------
Output:-
-----------------------
---------------------

Page 19
Programming in ‘C’ PGDCA (2023-24)

Page 20
Programming in ‘C’ PGDCA (2023-24)

Program 7

 Write a program in c to print Lucca’s series.

Source code :
#include<stdio.h>

#include<conio.h> void

main()

{ int a,b,c,d,i,n; clrscr();

printf("Enter limit= ");

scanf("%d",&n); a=0;

b=1; c=1; printf("Luccas

series :"); printf("%d

",a); printf("%d ",b);

printf("%d ",c);

for(i=1;i<=n-3;i++)

d=a+b+c;

printf("%d ",d);

a=b; b=c; c=d;

getch();

--------------------
--------------------
----- Output:-
--------------------
--------------------
----

Page 21
Programming in ‘C’ PGDCA (2022-23)

Program 8

 Write a program in c to calculate factorial of a given number.


Source code :
#include<stdio.h>

#include<conio.h> void

main()

int i,n,fact=1; clrscr();

printf(" Enter any number = ");

scanf("%d",&n); printf("----Result----");

for(i=n;i>=1;i--)

fact=fact*i;

printf("\n Factorial of %d = %d",n,fact); getch();

--------------------
--------------------
----- Output:-
--------------------
--------------------
----

Page 22
Programming in ‘C’ PGDCA (2023-24)

Program 9

 Write a program in c to check whether a given number is prime or not.


Source code :
#include<stdio.h>

#include<conio.h> void

main()

int n,i,flag=0; clrscr();

printf("Enter a number = ");

scanf("%d",&n); printf("\

n----RESULT----\n");

for(i=2;i<=n/2;i++)

if(n%i==0)

flag=1; break;

if(flag==0)

Page 23
Programming in ‘C’ PGDCA (2022-23)

printf("\nGiven number is PRIME Number");

else

printf("\nGiven number is NOT Prime Number");

getch();

Page 24
Programming in ‘C’ PGDCA (2023-24)

---------------------
--------------------
---- Output:-
--------------------
--------------------
----

Page 25
Programming in ‘C’ PGDCA (2023-24)

Program- 10

 Write a program in c to weather a given number is Armstrong or not.


Source code :
#include<stdio.h>

#include<conio.h> void

main()

int num,n,sum,r; clrscr(); printf("----*

To check Armstrong *----"); printf("\n

Enter a number = ");

scanf("%d",&num); n=num; sum=0;

while(n!=0)

r=n%10;

sum=sum+r*r*r;

n=n/10;

printf("\n----RESULT----"); if(sum==num)

printf("\n%d is an Armstrong Number",num);

else

printf("\n%d is NOT an Armstrong Number",num);

getch();

Page 26
Programming in ‘C’ PGDCA (2023-24)

---------------------
--------------------
---- Output:-
--------------------
--------------------
----

Page 27
Programming in ‘C’ PGDCA (2023-24)

Program- 11

 Write a program in c to search an element in 1D array using linear Search.


Source code :
#include<stdio.h>
#include<conio.h> void
main()
{ int n,i,j,k,flag;
int arr[10];
clrscr();

printf("Enter Limit= "); scanf("%d",&n);


printf("Enter the Elements= \n");

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

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

printf("*The Elements are= ");

for(j=0;j<=n-1;j++)

Page 28
Programming in ‘C’ PGDCA (2023-24)

printf("%d ",arr[j]);

} printf("\n-------------------------\n");
printf("enter any no. of search= ");
scanf("%d",&k);

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

if(arr[i]==k)

flag=0;

printf("\n--------* RESULT *--------\n"); if(flag==0)


{

printf("%d NUMBER is found",k);

} else
{

printf("%d NUMBER is NOT found",k);

getch();

Page 29
Programming in ‘C’ PGDCA (2023-24)

---------------------
--------------------
---- Output:-
--------------------
--------------------
----

Page 30
Programming in ‘C’ PGDCA (2023-24)

Program- 12

 Write a program in c to sort element in 1D array using Bubble sort.

Source code :
#include<stdio.h>

#include<conio.h> void

main()

int n,i,j,temp; int arr[10]; clrscr(); printf("------*

BUBBLE SORT 1D ARRAY *------\n"); printf("Enter

Limit of Elements = "); scanf("%d",&n);

printf("Enter the Array Elements= \n");

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

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

printf("*The Elements are= ");

for(j=0;j<=n-1;j++)

printf("%d ",arr[j]);

} printf("\n-------------------------\n");

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

for(j=0;j<n-i-1;j++)

Page 31
Programming in ‘C’ PGDCA (2023-24)

if(arr[j]>arr[j+1])

temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

printf("\n SORTED LIST : "); for(i=0;i<n;i++)

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

getch();

---------------------
--------------------
---- Output:-
--------------------
--------------------
----

Page 32
Programming in ‘C’ PGDCA (2023-24)

Program- 13

 Write a program in c to perform addition of 2 matrix.

Source code :
#include<stdio.h>

#include<conio.h> void

main()

int m,n,c,d; int fst[10][10],sec[10][10],sum[10][10]; clrscr();

printf("------* ADDITION OF 2 MATRIX *------\n");

printf("Enter the number of ROWS (between 1 - 10) :- ");

scanf("%d", &m); printf("Enter the number of COLUMNS

(between 1 - 10) :- "); scanf("%d", &n); printf("\n* Enter the

Elements of First Matrix :\n"); for(c=0;c<m;c++)

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

scanf("%d",&fst[c][d]);

printf("\n* Enter the Elements of Second Matrix :\

n"); for(c=0;c<m;c++)

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

scanf("%d",&sec[c][d]);

Page 33
Programming in ‘C’ PGDCA (2023-24)

} printf("-----------------------------\n");

printf("* Sum of Entered Matrices :- \n");

for(c=0;c<m;c++)

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

sum[c][d]=fst[c][d]+sec[c][d]; printf("%d\t",sum[c]

[d]);

printf("\n");

getch();

---------------------
--------------------
---- Output:-
--------------------
--------------------
----

Page 34
Programming in ‘C’ PGDCA (2023-24)

Page 35
Programming in ‘C’ PGDCA (2023-24)

Program 14

 Write a program in c to perform subtraction of 2 matrix.

Source code :
#include<stdio.h>

#include<conio.h> void

main()

int m,n,c,d; int fst[10][10],sec[10][10],sub[10][10]; clrscr();

printf("------* SUBSTRACTION OF 2 MATRIX *------\n");

printf("Enter the number of ROWS (between 1 - 10) :- ");

scanf("%d", &m); printf("Enter the number of COLUMNS

(between 1 - 10) :- "); scanf("%d", &n);

printf("\n* Enter the Elements of First Matrix :\n");

for(c=0;c<m;c++)

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

scanf("%d",&fst[c][d]);

printf("\n* Enter the Elements of Second Matrix :\n");

for(c=0;c<m;c++)

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

scanf("%d",&sec[c][d]);

Page 36
Programming in ‘C’ PGDCA (2023-24)

} } printf("-----------------------------\

n");

printf("* SUBSTRACTION of Entered Matrices :- \n");

for(c=0;c<m;c++)

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

sub[c][d]=fst[c][d]-sec[c][d]; printf("%d\t",sub[c]

[d]);

printf("\n");

getch();

Page 37
Programming in ‘C’ PGDCA (2023-24)

----------------------
----------------------
- Output:-
----------------------
---------------------

P
r
o
g
r
a
m

1
5

 Write a program in c to perform multiplication of 2 matrix.

Source code :

Page 38
Programming in ‘C’ PGDCA (2023-24)

#include<stdio.h>

#include<conio.h> void

main()

int m,n,c,d; int fst[10][10],sec[10][10],mult[10][10];

clrscr(); printf("------* MULTIPLICATION OF 2 MATRIX

*------\n"); printf("Enter the number of ROWS (between 1 -

10) :- "); scanf("%d", &m); printf("Enter the number of

COLUMNS (between 1 - 10) :- "); scanf("%d", &n); printf("\

n* Enter the Elements of First Matrix :\n"); for(c=0;c<m;c+

+)

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

scanf("%d",&fst[c][d]);

printf("\n* Enter the Elements of Second Matrix :\n");

for(c=0;c<m;c++)

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

scanf("%d",&sec[c][d]);

} printf("-----------------------------\n");

printf("* MULTIPLICATION of Entered Matrices :- \n");

for(c=0;c<m;c++)

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

Page 39
Programming in ‘C’ PGDCA (2023-24)

mult[c][d]=fst[c][d]*sec[c][d]; printf("%d\t",mult[c]

[d]);

printf("\n");

getch();

----------------------
----------------------
- Output:-
----------------------
----------------------

Program 16

 Write a program in c to create a function name power(a,b) and it calculate a raised

to b.

Page 40
Programming in ‘C’ PGDCA (2023-24)

Source code :
#include<conio.h>

#include<stdio.h> #include<math.h>

int power(int a, int b); void

main()

{ int a, b, res; clrscr(); printf("* Create function name

power(a,b) ,Calculate a raised to b *");

printf("\n ----------------------------------------------------------");

printf("\n Enter a : "); scanf("%d", &a);

printf("\n Enter b : "); scanf("%d",

&b);

res=power(a,b);

printf(" ----------------------------------------------------------");

printf("\n Result : %d",res); getch();

int power(int a, int b)

{ int

x;

x=pow(a,b);

return x;

Page 41
Programming in ‘C’ PGDCA (2023-24)

----------------------
----------------------
- Output:-
----------------------
----------------------

Page 42
Programming in ‘C’ PGDCA (2023-24)

Program 17

 Write a program in c to print day name according to given number. (1=Sunday)

Source code :
#include<stdio.h>

#include<conio.h> void

main()

{ int a; clrscr(); printf(" ****** Identify the day from

day no. ******\n"); printf(" Enter day no. = ");

scanf("%d",&a);

printf("----------------");

printf("\n DAY is "); switch(a)

case 1: printf("Sunday");

break;

case 2: printf("Monday");

break;

case 3: printf("Tuesday");

break;

case 4: printf("Wednesday");

break;

case 5: printf("Thursday");

break;

case 6: printf("Friday");

break;

Page 43
Programming in ‘C’ PGDCA (2023-24)

case 7: printf("Saturday");

break;

default:

printf(" Please enter valid day no. from 1 to 7");

getch();

----------------------
----------------------
- Output:-
----------------------
----------------------

Page 44
Programming in ‘C’ PGDCA (2023-24)

Program 18

 Write a program in c to check weather a given String is Palindrome or not.

Source code :
#include<conio.h>

#include<stdio.h> void

main()

char str1[20]; int i, length; int flag=0; clrscr();

printf("To check given string is Palindrome or Not");

printf("\n-----------------------------------------\n");

printf("Enter a String : "); scanf("%s",str1);

length=strlen(str1);

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

if(str1[i]!=str1[length-i-1])

flag=1;

printf("\n---------* Result *---------\n"); if(flag)

printf("%s is Not a PALINDROME",str1);

Page 45
Programming in ‘C’ PGDCA (2023-24)

else

printf("%s is a PALINDROME",str1);

getch();

----------------------
----------------------
- Output:-
----------------------
----------------------

Page 46
Programming in ‘C’ PGDCA (2023-24)

Program 19

 Write a program in c to swap 2 number using pointers.


Source code :
#include<conio.h>

#include<stdio.h>

void swap(int *x, int *y)

{ int

t;

t=*x;

*x=*y;

*y=t;

void main()

int num1,num2;

printf("\n----------* SWAP 2 num using POINTERS *----------");

Page 47
Programming in ‘C’ PGDCA (2023-24)

printf("\nEnter value of num1 : ");

scanf("%d",&num1); printf("\nEnter

value of num2 : ");

scanf("%d",&num2);

printf("\n ----------* Before Swapping *----------");

printf("\n num1 is : %d",num1); printf("\n

num2 is : %d",num2); swap(&num1,&num2);

printf("\n ----------* After Swapping *----------");

printf("\n num1 is : %d",num1); printf("\n

num2 is : %d",num2);

getch(); clrscr();

----------------------
----------------------
- Output:-
----------------------
----------------------

Page 48
Programming in ‘C’ PGDCA (2023-24)

Program 20

 Write a program in c to demonstrate call by value.


Source code :
#include<stdio.h>

#include<conio.h> void

swap(int,int); void

main()

int a=255,b=454; clrscr(); printf("**** -- Before swapping\t: -- ****

\na=%d\nb=%d\n",a,b); swap(a,b); printf("\n**** -- After

swapping\t: -- **** \na=%d\nb=%d\n",a,b); getch();

void swap(int a,int b)

int temp; temp=a; a=b; b=temp; printf("\n**** -- After swapping values in function :

-- **** \na=%d\nb=%d\n",a,b);

Page 49
Programming in ‘C’ PGDCA (2023-24)

----------------------
----------------------
- Output:-
----------------------
----------------------

Program 21

 Write a program in c to demonstrate call by reference.


Source code :
#include<stdio.h>

#include<conio.h> void

swap(int*,int*); void

main()

int a=21,b=230; clrscr(); printf("**** -- Before swapping\t: -- **** \

na=%d\nb=%d\n",a,b); swap(&a,&b); printf("\n**** -- After

swapping\t: -- **** \na=%d\nb=%d\n",a,b); getch();

void swap(int *x,int *y)

Page 50
Programming in ‘C’ PGDCA (2023-24)

int temp; temp=*x;

*x=*y;

*y=temp;

----------------------
----------------------
- Output:-
----------------------
----------------------

P
r
o
g
r
a
m
-

2
2

 Write a program in c to calculate factorial using recursion.

Page 51
Programming in ‘C’ PGDCA (2023-24)

Source code :
#include<conio.h>

#include<stdio.h>

int find_factorial(int); void

main()

int num, fact; clrscr(); printf(" To calculate

Factorial using recursion");

printf("\n* ----------------------------------- *");

printf("\n Enter any Integer Number : ");

scanf("%d",&num); fact=find_factorial(num);

printf("* ----------------------------------- *"); printf("\n

Factorial of %d is : %d",num,fact);

getch();

int find_factorial(int n)

if(n==0)

return(1);

return(n*find_factorial(n-1));

Page 52
Programming in ‘C’ PGDCA (2023-24)

----------------------
----------------------
- Output:-

----------------------
----------------------

Page 53
Programming in ‘C’ PGDCA (2023-24)

Page 54
Programming in ‘C’ PGDCA (2023-24)

Program- 23

 Write a program in c to calculate length of string without using string handling

function.

Source code :
#include<stdio.h>

#include<conio.h> void

main()

char str[30]; int i,l=0;

clrscr(); printf(" Enter any

string= "); scanf("%s",str);

printf("----------------------------"); printf("\n

Result :- \n"); for(i=0;str[i]!='\0';i++)

l++;

printf(" Length of the string= %d",l);

getch();

Page 55
Programming in ‘C’ PGDCA (2023-24)

---------------------
---------------------
--- Output:-
---------------------
---------------------
--

Program- 24

 Write a program in c to create a structure employee with data members (id, name,

salary) to store the id, name, salary and print values of Data members.

Source code :
#include<stdio.h>

#include<conio.h>

#include<string.h> struct

employee

char name[50];

int id; float

salary;

};

struct employee e1,e2; void

main()

Page 56
Programming in ‘C’ PGDCA (2023-24)

clrscr(); printf("**** - Name,Id and Salary of First Employee : -

**** \n"); e1.id=101; strcpy(e1.name,"Mohan Das");

e1.salary=50000; printf("Emp1 id \t:%d",e1.id);

printf("\nEmp1 Name \t:%s",e1.name); printf("\

nEmp1 salary \t:%2f",e1.salary);

printf("\n\n**** - Name,Id and Salary of Second Employee : - **** \n");

e2.id=102; strcpy(e2.name,"Ramesh

Das"); e2.salary=25000;

printf("Emp1 id \t:%d",e2.id);

printf("\nEmp2 Name \t:%s",e2.name); printf("\

nEmp2 salary \t:%2f",e2.salary);

getch();

---------------------
---------------------
--- Output:-
---------------------
---------------------
--

Page 57
Programming in ‘C’ PGDCA (2023-24)

Program- 25

 Write a program in c to check whether a given no is positive or negative Source

code :
#include<stdio.h>

#include<conio.h> void

main()

{ int n; clrscr(); printf("--** Check Number is Positive or

Negative **--"); printf("\n\n Enter any number = ");

scanf("%d",&n); printf("\n Result :- "); if(n>=0)

printf(" Number is Positive.");

else

Page 58
Programming in ‘C’ PGDCA (2023-24)

printf(" Number is Negative");

getch();

---------------------
---------------------
--- Output:-
---------------------
---------------------
--

Program- 26

 Write a program in c to perform arithmetic operation as per user’s choice.


Source code :
#include<stdio.h>

#include<conio.h> void

main()

{ int a,b,c; clrscr(); printf("\t\t Types of

Arithmetic operations \t\t"); printf("\n1.

Addition"); printf("\n2. Substraction"); printf("\

n3. Multiplication"); printf("\n4. Division");

printf("\n5. Modulus");

Page 59
Programming in ‘C’ PGDCA (2023-24)

printf("\n--------------------------");

printf("\nEnter value a =");

scanf("%d",&a); printf("Enter

value b ="); scanf("%d",&b);

printf("--------------------------");

printf("\nChoose Operation ="); scanf("%d",&c);

printf("--------------------------\n"); switch(c)

case 1: c=a+b; printf("\nResult

of Addition : ");

break; case 2: c=a-b; printf("\

nResult of Substraction : "); break;

case 3: c=a*b; printf("\Result of

Multiplication : ");

break;

case 4: c=a/b; printf("\nResult

of Division : ");

break; case

5:

c=a%b;

printf("\nResult of Modulus : ");

break; default:

printf("\nPlease choose valid no. from 1 to 5");

printf("%d",c); getch();

Page 60
Programming in ‘C’ PGDCA (2023-24)

---------------------
---------------------
--- Output:-
---------------------
---------------------
--

Program- 27

 Write a program in c to reverse the digit of any no using for loop.


Source code :
#include<stdio.h>

#include<conio.h> void

main()

Page 61
Programming in ‘C’ PGDCA (2023-24)

int n,rev=0,rem;

clrscr();

printf("Enter any integer="); scanf("%d",&n);

for(;n!=0;)

rem=n%10;

rev=rev*10+rem;

n=n/10;

printf("\n---* After Reversing *---"); printf("\n\nReversed

no. = %d",rev);

getch();

---------------------
---------------------
--- Output:-
---------------------
---------------------
--

Page 62
Programming in ‘C’ PGDCA (2023-24)

Pr
o
gr
a
m
2
8

 Write a program in c to check whether a given character is vowel or consonant.


Source code :
#include<stdio.h>

#include<conio.h> void

main()

char ch; clrscr(); printf("Enter

an alphabet: ");

scanf("%c",&ch); printf("\

n------RESULT--------");

if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')

printf("\nIt's a vowel");

else if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')

printf("\nIt's a VOWEL");

else

printf("\nIt's a CONSONENT");

getch();

Page 63
Programming in ‘C’ PGDCA (2023-24)

---------------------
---------------------
--- Output:-
---------------------
---------------------
--

Page 64
Programming in ‘C’ PGDCA (2023-24)

Program-

Pr
o
gr
a
m
2
9

 Write a program in c to reverse a string without using library function .Write user

defined function.
Source code :
#include<stdio.h>

#include<conio.h> void

main()

char str[30]; int i,count;

clrscr(); count=0;

printf("Enter any string= ");

scanf("%s",str);

printf("-------------------\n");

printf("REVERSED STRING : "); for(i=0;str[i]!='\0';i+

+)

count++;

for(i=count-1;i>=0;i--)

printf("%c",str[i]);

getch();

Page 65
Programming in ‘C’ PGDCA (2023-24)

---------------------
---------------------
--- Output:-
---------------------
---------------------
--

Page 66
Programming in ‘C’ PGDCA (2023-24)

Program-

30

 Write a program in c to reverse a string without using library function .Write user

defined function.
Source code :
#include<stdio.h>

#include<conio.h> void

main()

char str[30]; int i,l=0;

clrscr(); printf(" Enter any

string= "); scanf("%s",str);

printf("----------------------------"); printf("\n

Result :- \n"); for(i=0;str[i]!='\0';i++)

l++;

printf(" Length of the string= %d",l);

getch();

Page 67
Programming in ‘C’ PGDCA (2023-24)

---------------------
---------------------
--- Output:-
---------------------
---------------------
--

Page 68

You might also like