0% found this document useful (0 votes)
133 views

A C' Language: Practical File On

This document contains 16 programs written in C language. Each program is focused on solving a different programming problem such as finding the largest of three numbers, calculating the sum and average of numbers, determining if a number is even or odd, and more. The programs demonstrate various C programming concepts like loops, conditional statements, functions, arrays, structures, and more. Output for each program is displayed.

Uploaded by

Subhash Bajaj
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)
133 views

A C' Language: Practical File On

This document contains 16 programs written in C language. Each program is focused on solving a different programming problem such as finding the largest of three numbers, calculating the sum and average of numbers, determining if a number is even or odd, and more. The programs demonstrate various C programming concepts like loops, conditional statements, functions, arrays, structures, and more. Output for each program is displayed.

Uploaded by

Subhash Bajaj
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/ 40

JCD COLLEGE OF ENGINEERING

A
PRACTICAL FILE ON

C Language

Submitted By:
to:

Submitted

Kulwinder Singh

Vinod Beniwal

Roll No:1211253018
Proffessor,

Asst.

B.Tech-Ist sem(ME)

CSE, Deptt.

INDEX
S.n Program Name
o
1
2
3
4
5
6

WAP to print line of


text (your name)
WAP to find largest of
three numbers
WAP to calculate sum
and average of three
numbers
WAP to find whether
a given number is
even or odd
WAP to calculate the
sum of n natural
numbers
WAP to swap the
value of two variable
(a) using third
variable
(b) without using
third variable

Date

Teachers
remarks(si
gn)

8
9
10
11
12
13
14
15

16

WAP to find sum of


digits of a number
and also reverse of
the number
WAP to find factorial
of a given number
WAP to find sum of
two given matrices
WAP to convert a
decimal number to
binary number
WAP to transpose a
matrix using array.
WAP to multiply two
matrices using array
WAP to use call by
value
WAP to use call by
reference
WAP to check
whether a string is
pallindrom or not
using array
WAP using structure
to read name,roll no
& marks of a class &
also calculate the

average marks

PROGRAM 1:
WAP to print a line of text
#include<stdio.h>
#include<conio.h>
void main()
{
char name[20];
clrscr();
printf("enter your name::");
gets(name);
printf("your name is::");
puts(name);
getch();
}

OUTPUT:

PROGRAM 2:
WAP to find largest of three numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,sum;
float avg;
printf("enter three numbers");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{ if(a>c)
printf(" a =%d is largest",a);
else
printf(" c=%d is largest",c); }
else {

if(b>c)
printf("b =%d is largest",b);
else
printf("c=%d is largest",c);
getch();
}
OUTPUT:

PROGRAM 3
WAP to calculate sum and average of three numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,sum;
float avg;
clrscr();
printf("enter three numbers");
scanf("%d%d%d",&a,&b,&c);
sum=a+b+c;
avg=(sum)/3;
printf("sum of three numbers is=%d\n and average of three numbers is=
%f",sum,avg);
getch();
}

OUTPUT:

PROGRAM 4:
WAP to find whether a given number is even or odd
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("enter the number");
scanf("%d",&n);
if(n%2==0)
printf("number=%d is even");
else
printf("number=%d is odd");
getch();
}

OUTPUT:

PROGRAM 5
WAP to find sum of n natural numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0;
clrscr();
printf("enter the value of n");
scanf("%d",&n);
for(i=0;i<=n;i++)
sum=sum+i;
printf("sum of %d natural numbers is=%d\n",n,sum);
getch();
}

OUTPUT:

PROGRAM 6(i)
WAP to swap the value of two variable using third variable
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("enter two numbers you want to swap");
scanf("%d%d",&a,&b);
printf("before swap value of a=%d and b=%d ",a,b);
temp=a;
a=b;
b=temp;
printf("\nafter swap value of a=%d and b=%d ",a,b);
getch();

OUTPUT:

PROGRAM 6(ii)
WAP to swap the value of two variables without using third variable
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("enter two numbers you want to swap");
scanf("%d%d",&a,&b);
printf("before swap value of a=%d and b=%d ",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nafter swap value of a=%d and b=%d ",a,b);
getch();

OUTPUT:

PROGRAM 7
WAP to find sum of digits and reverse of a number
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,digit,sum=0;
clrscr();
printf("enter the value of n");
scanf("%d",&n);
printf("reverse of %d=",n);
for(n;n>0;n=n/10)
{
digit=n%10;
printf("%d",digit);
sum=sum+digit;

}
printf("\nsum of digits of a number is=%d",sum);
getch();}

OUTPUT:

PROGRAM 8:
WAP to find factorial of a given number
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,fact=1;
clrscr();
printf("enter the value of n");
scanf("%d",&n);
for(i=n;n>0;n--)

fact=fact*i;
printf("factorial of a number is=%d",fact);
printf("sum of digits of a number is=%d",sum);

getch();
}

OUTPUT:

PROGRAM 9:
WAP to find sum of two given matrices
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,r1,c1;
clrscr();
printf("enter the order of matrix\n");
scanf("%d%d",&r1,&c1);
printf("enter the elements of the first matrix\n");
for(i=1;i<=r1;i++)
for(j=1;j<=c1;j++)
scanf("%d",&a[i][j]);
printf("enter the elements of the second matrix\n");

for(i=1;i<=r1;i++)
for(j=1;j<=c1;j++)
scanf("%d",&b[i][j]);
for(i=1;i<=r1;i++)
for(j=1;j<=c1;j++)
c[i][j]=a[i][j]+b[i][j];
printf("addition ofmatrices is\n");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
printf("%4d",c[i][j]);
printf("\n");
}
getch();
}

OUTPUT:

PROGRAM 10.
WAP to convert a decimal number to binary
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,a[10];
clrscr();
printf("enter the number");
scanf("%d",&n);
for(i=0;n>0;n=n/2,i++)
a[i]=n%2;
i--;
for(i;i>=0;i--)
printf("%d",a[i]);

getch();}

OUTPUT:

PROGRAM 11:
WAP to transpose a matrix using array
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],i,j,r,c;
printf("enter the order of matrix\n");
scanf("%d%d",&r,&c);
printf("enter the elements of the matrix\n");
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
scanf("%d",&a[i][j]);
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
b[j][i]=a[i][j];
printf("transposed matrix is\n");
for(i=1;i<=c;i++) {

for(j=1;j<=r;j++)
printf("%4d",b[i][j]);
printf("\n");}
getch();}

OUTPUT:

PROGRAM 12:
WAP to multiply two given matrices
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,r1,c1,r2,c2;
clrscr();
printf("enter the order of first matrix\n");
scanf("%d%d",&r1,&c1);
printf("enter the order of second matrix\n");
scanf("%d%d",&r2,&c2);
if(c1==r2)
{
printf("enter the elements of the first matrix\n");
for(i=1;i<=r1;i++)
for(j=1;j<=c1;j++)
scanf("%d",&a[i][j]);

printf("enter the elements of the second matrix\n");


for(i=1;i<=r2;i++)
for(j=1;j<=c2;j++)
scanf("%d",&b[i][j]);
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
c[i][j]=0;
for(k=1;k<=c1;k++)
c[i][j]+=a[i][k]*b[k][j];
}
}
printf("multiplication ofmatrices is\n");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c2;j++)
printf("%4d",c[i][j]);
printf("\n");
}
}
else
printf("multiplication is not possible");

getch();
}

OUTPUT:

PROGRAM 13:
WAP to use call by value
#include<stdio.h>
#include<conio.h>
void fun(int,int);
void main()
{
int a=12,b=8;
clrscr();
printf("in main function values of a=%d & b=%d",a,b);
fun(a,b);
printf("\nafter calling function values of a=%d & b=%d",a,b);
getch();
}
void fun(int p,int q)
{
p=p*2;
q=q*2;

printf("\nvalues of a=%d and b=%d in this function are",p,q);


}

OUTPUT:

PROGRAM 14:
WAP to use call by reference
#include<stdio.h>
#include<conio.h>
void fun(int*,int*);
void main()
{
int a=12,b=8;
clrscr();
printf("in main function values of a=%d & b=%d",a,b);
fun(&a,&b);
printf("\nafter calling function values of a=%d & b=%d",a,b);
getch();
}
void fun(int * p,int * q)
{
*p=*p*2;
*q=*q*2;

printf("\nvalues of a=%d and b=%d in this function are",*p,*q);


}

OUTPUT:

PROGRAM 15:
WAP to check whether a given string is pallindrom or not
#include<stdio.h>
#include<conio.h>
void main()
{
char str[20];
int i,j;
clrscr();
printf("enter string");
gets(str);
for(j=0;str[j]!='\0';j++);
for(i=0,j--;i!=j;i++,j--)
{
if(str[i]!=str[j])
break;
}
if(i==j)

printf("string entered= %s is pallindrom",str);


else
printf("not pallindrom");
getch();}

OUTPUT:

PROGRAM 16:
WAP using structure to read name,roll no and marks of a class and also
calculate the average marks
#include<stdio.h>
#include<conio.h>
void main()
{ struct student
{
int roll;
char name[20];
int marks;
};
struct student s[10];
int n,i,sum=0;
float avg;
clrscr();
printf("enter the number of students");
scanf("%d",&n);

for(i=1;i<=n;i++)
{
printf("enter the record of student%d\n",i);
printf("Roll no=");
scanf("%d",&s[i].roll);
printf("name=");
scanf("%s",&s[i].name);
printf("marks=");
scanf("%d",&s[i].marks);
sum+=s[i].marks;
}
avg=sum/n;
printf("the average marks of a class is:%5.2f",avg);
getch();
}

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy