0% found this document useful (0 votes)
9 views11 pages

BCA Pract REc C Prog

The document describes 10 programming experiments involving writing C code to solve problems like finding the greatest of three numbers, checking if a number is prime, calculating factorials recursively, and more. For each experiment, the hardware and software specifications of the computer are also listed, along with the C code for the solution and the name and roll number of the student.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

BCA Pract REc C Prog

The document describes 10 programming experiments involving writing C code to solve problems like finding the greatest of three numbers, checking if a number is prime, calculating factorials recursively, and more. For each experiment, the hardware and software specifications of the computer are also listed, along with the C code for the solution and the name and roll number of the student.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Expt1:

Write a program to find out the greatest number among any three numbers

Hardware Specification of Computer:


 CPU: Intel Dual Core with 1.2GHz Clock Speed
 RAM: 2GB RAM
 Hard Disk: 500 GB
 Input Device: USB Key Board and Mouse
 Monitor: LED Monitor
Software Specification of Computer:
 Operating System: Windows 7
 Programming Language: Turbo C 3.0
 Program Editor: Own editor of C IDE
Coding:
# include <stdio.h>
# include <conio.h>
void main()
{
float a,b,c;
clrscr();
printf ("Enter any three numbers:");
scanf("%f %f %f",&a,&b,&c);
if(a==b && b==c)
{
printf("The numbers are equal");
}
else if(a>b && a>c)
{
printf("The greatest number is: %0.2f",a);
}
else if(b>c)
{
printf("The greatest number is: %0.2f",b);
}
else
{
printf("The greatest number is: %0.2f",c);
}
getch();
}

Name:
Roll No. :
Class:
Output:
Expt2:
Write a program to find out the greatest number among any N numbers

Hardware Specification of Computer:


 CPU: Intel Dual Core with 1.2GHz Clock Speed
 RAM: 2GB RAM
 Hard Disk: 500 GB
 Input Device: USB Key Board and Mouse
 Monitor: LED Monitor
Software Specification of Computer:
 Operating System: Windows 7
 Programming Language: Turbo C 3.0
 Program Editor: Own editor of C IDE
Coding:
# include <stdio.h>
# include <conio.h>
void main()
{
int n;
float x,gt;
clrscr();
printf ("Enter how many numbers:");
scanf("%d",&n);
printf("Enter the 1st number:");
scanf("%f",&x);
gt=x;
for(int i=2;i<=n;i++)
{
printf("Enter the next number:");
scanf("%f",&x);
if(gt<x)
gt=x;
}
printf("The greatest number is:%0.2f",gt);
getch();
}

Name:
Roll No. :
Class:
Output:
Expt3:
Write a program to check whether the given number is prime or composite

Hardware Specification of Computer:


 CPU: Intel Dual Core with 1.2GHz Clock Speed
 RAM: 2GB RAM
 Hard Disk: 500 GB
 Input Device: USB Key Board and Mouse
 Monitor: LED Monitor
Software Specification of Computer:
 Operating System: Windows 7
 Programming Language: Turbo C 3.0
 Program Editor: Own editor of C IDE
Coding:
# include <stdio.h>
# include <conio.h>
# include <math.h>
void main()
{
int n,div=2;
float sqt;
clrscr();
printf ("Enter a number to check prime or composite:");
scanf("%d",&n);
sqt=sqrt(n);
while(div<=sqt)
{
if(n%div==0)
break;
else
div++;
}
if(div<=sqt)
printf("The number is composite");
else
printf("The number is prime");
getch();
}

Name:
Roll No. :
Class:

Output:
Expt4:
Write a program to find the greatest common divisor (GCD) of any two numbers

Hardware Specification of Computer:


 CPU: Intel Dual Core with 1.2GHz Clock Speed
 RAM: 2GB RAM
 Hard Disk: 500 GB
 Input Device: USB Key Board and Mouse
 Monitor: LED Monitor
Software Specification of Computer:
 Operating System: Windows 7
 Programming Language: Turbo C 3.0
 Program Editor: Own editor of C IDE
Coding:
# include <stdio.h>
# include <conio.h>
void main()
{
int m,n,small,div=1,gcd;
clrscr();
printf ("Enter any two numbers for finding the GCD:");
scanf("%d %d",&m,&n);
if(m<n)
small=m;
else
small=n;
while(div<=small)
{
if(n%div==0 && m%div==0)
gcd=div;
div++;
}
printf("The GCD of %d and %d is: %d",m,n,gcd);
getch();
}

Name:
Roll No. :
Class:

Output:
Expt5:
Write a program to find the sum of digits of a number

Hardware Specification of Computer:


 CPU: Intel Dual Core with 1.2GHz Clock Speed
 RAM: 2GB RAM
 Hard Disk: 500 GB
 Input Device: USB Key Board and Mouse
 Monitor: LED Monitor
Software Specification of Computer:
 Operating System: Windows 7
 Programming Language: Turbo C 3.0
 Program Editor: Own editor of C IDE
Coding:
# include <stdio.h>
# include <conio.h>
void main()
{
int n,s=0;
clrscr();
printf ("Enter an integer to find the sum of its digits:");
scanf("%d",&n);
while(n>0)
{
s=s+n%10;
n=n/10;
}
printf("The sum of digits is: %d",s);
getch();
}

Name:
Roll No. :
Class:

Output:
Expt6:
Write a program to check a string is palindrome or not

Hardware Specification of Computer:


 CPU: Intel Dual Core with 1.2GHz Clock Speed
 RAM: 2GB RAM
 Hard Disk: 500 GB
 Input Device: USB Key Board and Mouse
 Monitor: LED Monitor
Software Specification of Computer:
 Operating System: Windows 7
 Programming Language: Turbo C 3.0
 Program Editor: Own editor of C IDE
Coding:
# include <stdio.h>
# include <conio.h>
# include <string.h>
void main()
{
int Ln;
char s1[81],s2[81];
clrscr();
printf ("Enter a string for the checking of palindrome\n");
gets(s1);
Ln=strlen(s1);
for(int i=Ln-1,j=0;i>=0;i--,j++)
{
s2[j]=s1[i];
}
s2[j]='\0';
if(strcmp(s1,s2)==0)
printf("The string is palindrome");
else
printf("The string is not palindrome");
getch();
}

Name:
Roll No. :
Class:

Output:
Expt7:
Write a program to find the sum of the series: x - x2 + x3 - x4 + ….  xn

Hardware Specification of Computer:


 CPU: Intel Dual Core with 1.2GHz Clock Speed
 RAM: 2GB RAM
 Hard Disk: 500 GB
 Input Device: USB Key Board and Mouse
 Monitor: LED Monitor
Software Specification of Computer:
 Operating System: Windows 7
 Programming Language: Turbo C 3.0
 Program Editor: Own editor of C IDE
Coding:
# include <stdio.h>
# include <conio.h>
# include <math.h>
void main()
{
float x,s=0;
int n,i;
clrscr();
printf("Enter how many terms:");
scanf("%d",&n);
printf("Enter the value for X:");
scanf("%f",&x);
for(i=1;i<=n;i++)
{
s=s+pow(x,i)*pow(-1,i+1);
}
printf("The sum of the series is:%0.2f",s);
getch();
}

Name:
Roll No. :
Class:

Output:
Expt8:
Write a program to find the sum of the series:

Hardware Specification of Computer:


 CPU: Intel Dual Core with 1.2GHz Clock Speed
 RAM: 2GB RAM
 Hard Disk: 500 GB
 Input Device: USB Key Board and Mouse
 Monitor: LED Monitor
Software Specification of Computer:
 Operating System: Windows 7
 Programming Language: Turbo C 3.0
 Program Editor: Own editor of C IDE
Coding:
# include <stdio.h>
# include <conio.h>
# include <math.h>
void main()
{
float x,p,f,s=0;
int n,i,j;
clrscr();
printf("Enter how many terms:");
scanf("%d",&n);
printf("Enter the value for X:");
scanf("%f",&x);
for(i=1;i<=n;i++)
{
p=pow(x,i);
f=1;
for(j=1;j<=i;j++)
f=f*j;
s=s+p/f;
}
printf("The sum of the series is:%0.2f",s);
getch();
}

Name:
Roll No. :
Class:

Output:
Expt9:
Write a program to print the ‘*’ pyramid with left alignment for n rows in the screen of monitor

Hardware Specification of Computer:


 CPU: Intel Dual Core with 1.2GHz Clock Speed
 RAM: 2GB RAM
 Hard Disk: 500 GB
 Input Device: USB Key Board and Mouse
 Monitor: LED Monitor
Software Specification of Computer:
 Operating System: Windows 7
 Programming Language: Turbo C 3.0
 Program Editor: Own editor of C IDE
Coding:
# include <stdio.h>
# include <conio.h>
void main()
{
int n,i,j;
clrscr();
printf("Enter how many rows:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("*");
printf("\n");
}
getch();
}

Name:
Roll No. :
Class:

Output:
Expt10:
Write a program to find the factorial of a number using recursion function

Hardware Specification of Computer:


 CPU: Intel Dual Core with 1.2GHz Clock Speed
 RAM: 2GB RAM
 Hard Disk: 500 GB
 Input Device: USB Key Board and Mouse
 Monitor: LED Monitor
Software Specification of Computer:
 Operating System: Windows 7
 Programming Language: Turbo C 3.0
 Program Editor: Own editor of C IDE
Coding:
# include <stdio.h>
# include <conio.h>
void main()
{
int n;
long int fct;
long int fact(int x);
clrscr();
printf("Enter an integer for factorial:");
scanf("%d",&n);
fct=fact(n);
printf("The factorial is: %ld",fct);
getch();
}

long int fact(int x)


{
long int f=x;
if(x==0)
return 1;
else
f=f*fact(x-1);
return f;
}

Name:
Roll No. :
Class:

Output:
Expt11:
Write a program to arrange any N numbers in ascending order

Hardware Specification of Computer:


 CPU: Intel Dual Core with 1.2GHz Clock Speed
 RAM: 2GB RAM
 Hard Disk: 500 GB
 Input Device: USB Key Board and Mouse
 Monitor: LED Monitor
Software Specification of Computer:
 Operating System: Windows 7
 Programming Language: Turbo C 3.0
 Program Editor: Own editor of C IDE
Coding:
# include <stdio.h>
# include <conio.h>
void main()
{
int i,j,tmp,n,x[100]; clrscr();
printf("Enter how many numbers to arrange in ascending order:"); scanf("%d",&n);
printf("Enter the 1st number:"); scanf("%d",&x[0]);
for(i=1;i<n;i++)
{
printf("Enter the next number:"); scanf("%d",&x[i]);
}
for(i=0;i<n;i++)
{
for(j=i;j<=n;j++)
{
if(x[i]>x[j])
{
tmp=x[i]; x[i]=x[j]; x[j]=tmp;
}
}
}
clrscr(); printf("The ascending order is:");
for(i=0;i<n;i++)
printf("\n%d",x[i]);
getch();
}

Name:
Roll No. :
Class:
Output:

You might also like