SlideShare a Scribd company logo
Practical No : 8
/* write a program to find square,square root,cube,cube root of a number using
switch case statement */
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,choice;
clrscr();
printf("Enter a Number:") ;
scanf("%d",&n);
printf("1.Squaren2.Square Rootn3.cube4.Cube Rootn");
printf("nEnter a Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("nSquare of a number is %d",(n*n));
break;
case 2:
printf("nSquare Root of a number is %d",sqrt(n));
break;
case 3:
printf("nCube of a Number is %d",(n*n*n));
break;
case 4:
printf("nCube Root of a number is %d",pow(n,1.0/3.0));
break;
default:
printf("nWrong Choice.");
}
getch();
}
cpract.docx
Practical No : 11
/* write a program to test whether given number is prime using function */
#include<stdio.h>
#include<conio.h>
int main()
{
int n, res;
clrscr();
printf("Enter a Number:n");
scanf("%d",&n);
res=prime(n);
if(res==0)
{
printf("%d is a Prime Number", n);
}
else
{
printf("%d is not a prime Number",n);
}
getch();
}
int prime(int n)
{
int i;
for(i=2;i<=n/2;i++)
{
if(n%i!=0)
{
continue;
}
else
{
return 1;
}
}
return 0;
}
Practical No : 13
/* Write a program to demonstrate call by reference parameter passing technique
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void ascend(int *first,int *mid,int *last)
{
int a,b,c,lar,sml,middle;
a=*first;
b=*mid;
c=*last;
lar=sml=a;
if(lar<b) lar=b;
if(lar<c) lar=c;
if(sml>b) sml=b;
if(sml>c) sml=c;
middle=(a+b+c)-lar-sml;
*first=sml;
*mid=middle;
*last=lar;
}
int main()
{
int a,b,c;
clrscr();
printf("Enter three numbers:");
scanf("%d %d %d",&a,&b,&c);
ascend(&a,&b,&c);
printf("The numbers in ascending order:");
printf("%d %d %d",a,b,c);
getch();
return 0;
}
Practical No : 14
/* Write a recursive program to test whether given number is prime */
#include<stdio.h>
#include<conio.h>
int main()
{
int n,p;
clrscr();
printf("Enter any number:");
scanf("%d",&n);
p=prime(n,n/2);
if(p==1)
{
printf("%d is a prime number",n);
}
else
{
printf("%d is a composite number",n);
}
getch();
}
int prime(int n,int i)
{
if(i==1)
return 1;
if(n%i==0)
return 0;
return prime(n,i-1);
}
Practical No : 16
/* Write a program to sort an Array using Pointer */
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5],i,j,n,temp;
int *p=&a[0];
clrscr();
scanf("%d",&n);
printf("nEnter the elements in array");
for(i=0;i<n;i++)
{
scanf("%d",(p+i)); printf("nEnter the size of array:");
}
printf("nThe element of an array is:");
for(i=0;i<n;i++)
{
printf(" %d",*(p+i));
}
//Logic to sort an array using pointer
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(*(p+j) > *(p+(j+1)))
{
temp=*(p+j) ;
*(p+j)=*(p+(j+1));
*(p+(j+1))=temp;
}
}
}
printf("nArray element of an array after sorting :");
for(i=0;i<n;i++)
{
printf(" %d",*(p+i));
}
getch();
}
/* Write a program to sort an Array using Pointer */
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5],i,j,n,temp;
int *p=&a[0];
clrscr();
printf("nEnter the size of array:");
scanf("%d",&n);
printf("nEnter the elements in array");
for(i=0;i<n;i++)
{
scanf("%d",(p+i));
}
printf("nThe element of an array is:");
for(i=0;i<n;i++)
{
printf(" %d",*(p+i));
}
//Logic to sort an array using pointer
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(*(p+j) > *(p+(j+1)))
{
temp=*(p+j) ;
*(p+j)=*(p+(j+1));
*(p+(j+1))=temp;
}
}
}
printf("nArray element of an array after sorting :");
for(i=0;i<n;i++)
{
printf(" %d",*(p+i));
}
getch();
}
Practical No : 12
/* write a program to demonstrate call by value parameter passing technique */
#include<stdio.h>
#include<conio.h>
int pass(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("The value before swap is x=%d,y=%dn",x,y);
return 0;
}
int main()
{
int x=14,y=56,temp;
clrscr();
printf("Enter number to check:n");
pass(x,y);
printf("The swap value is x=%d,y=%dn",x,y);
getch();
}

More Related Content

PDF
PCA-2 Programming and Solving 2nd Sem.pdf
Ashutoshprasad27
 
DOCX
PCA-2 Programming and Solving 2nd Sem.docx
Ashutoshprasad27
 
DOCX
Practical write a c program to reverse a given number
Mainak Sasmal
 
DOCX
Practical write a c program to reverse a given number
Mainak Sasmal
 
PDF
Data Structure using C
Bilal Mirza
 
DOCX
C lab manaual
manoj11manu
 
PDF
9.C Programming
Export Promotion Bureau
 
DOC
Basic c programs updated on 31.8.2020
vrgokila
 
PCA-2 Programming and Solving 2nd Sem.pdf
Ashutoshprasad27
 
PCA-2 Programming and Solving 2nd Sem.docx
Ashutoshprasad27
 
Practical write a c program to reverse a given number
Mainak Sasmal
 
Practical write a c program to reverse a given number
Mainak Sasmal
 
Data Structure using C
Bilal Mirza
 
C lab manaual
manoj11manu
 
9.C Programming
Export Promotion Bureau
 
Basic c programs updated on 31.8.2020
vrgokila
 

Similar to cpract.docx (20)

DOCX
DataStructures notes
Lakshmi Sarvani Videla
 
DOC
C basics
MSc CST
 
PDF
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DR B.Surendiran .
 
DOCX
Program flowchart
Sowri Rajan
 
PDF
C programs
Vikram Nandini
 
PDF
7 functions
MomenMostafa
 
PDF
Common problems solving using c
ArghodeepPaul
 
PDF
C lab programs
Dr. Prashant Vats
 
PDF
C lab programs
Dr. Prashant Vats
 
DOCX
Cpds lab
praveennallavelly08
 
DOCX
C Programming
Sumant Diwakar
 
DOCX
C programs
Minu S
 
DOCX
One dimensional operation of Array in C- language
9096308941
 
DOCX
SaraPIC
Sara Sahu
 
PPTX
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
PPT
All important c programby makhan kumbhkar
sandeep kumbhkar
 
DOCX
C file
simarsimmygrewal
 
DOCX
Chapter 8 c solution
Azhar Javed
 
PDF
Array Programs.pdf
RajKamal557276
 
DataStructures notes
Lakshmi Sarvani Videla
 
C basics
MSc CST
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DR B.Surendiran .
 
Program flowchart
Sowri Rajan
 
C programs
Vikram Nandini
 
7 functions
MomenMostafa
 
Common problems solving using c
ArghodeepPaul
 
C lab programs
Dr. Prashant Vats
 
C lab programs
Dr. Prashant Vats
 
C Programming
Sumant Diwakar
 
C programs
Minu S
 
One dimensional operation of Array in C- language
9096308941
 
SaraPIC
Sara Sahu
 
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
All important c programby makhan kumbhkar
sandeep kumbhkar
 
Chapter 8 c solution
Azhar Javed
 
Array Programs.pdf
RajKamal557276
 
Ad

Recently uploaded (20)

PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PDF
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
PPT
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
PDF
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
PDF
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
PDF
JUAL EFIX C5 IMU GNSS GEODETIC PERFECT BASE OR ROVER
Budi Minds
 
PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PDF
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PPTX
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
PDF
Zero Carbon Building Performance standard
BassemOsman1
 
PPT
Ppt for engineering students application on field effect
lakshmi.ec
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PDF
Software Testing Tools - names and explanation
shruti533256
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
JUAL EFIX C5 IMU GNSS GEODETIC PERFECT BASE OR ROVER
Budi Minds
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
Zero Carbon Building Performance standard
BassemOsman1
 
Ppt for engineering students application on field effect
lakshmi.ec
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
Software Testing Tools - names and explanation
shruti533256
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Ad

cpract.docx

  • 1. Practical No : 8 /* write a program to find square,square root,cube,cube root of a number using switch case statement */ #include<stdio.h> #include<conio.h> #include<math.h> int main() { int n,choice; clrscr(); printf("Enter a Number:") ; scanf("%d",&n); printf("1.Squaren2.Square Rootn3.cube4.Cube Rootn"); printf("nEnter a Choice:"); scanf("%d",&choice); switch(choice) { case 1: printf("nSquare of a number is %d",(n*n)); break; case 2: printf("nSquare Root of a number is %d",sqrt(n)); break; case 3: printf("nCube of a Number is %d",(n*n*n)); break; case 4: printf("nCube Root of a number is %d",pow(n,1.0/3.0)); break; default: printf("nWrong Choice."); } getch(); }
  • 3. Practical No : 11 /* write a program to test whether given number is prime using function */ #include<stdio.h> #include<conio.h> int main() { int n, res; clrscr(); printf("Enter a Number:n"); scanf("%d",&n); res=prime(n); if(res==0) { printf("%d is a Prime Number", n); } else { printf("%d is not a prime Number",n); } getch(); } int prime(int n) { int i; for(i=2;i<=n/2;i++) { if(n%i!=0) { continue; } else { return 1; } } return 0; }
  • 4. Practical No : 13 /* Write a program to demonstrate call by reference parameter passing technique */ #include<stdio.h> #include<conio.h> #include<math.h> void ascend(int *first,int *mid,int *last) { int a,b,c,lar,sml,middle; a=*first; b=*mid; c=*last; lar=sml=a; if(lar<b) lar=b; if(lar<c) lar=c; if(sml>b) sml=b; if(sml>c) sml=c; middle=(a+b+c)-lar-sml; *first=sml; *mid=middle; *last=lar; } int main() { int a,b,c; clrscr(); printf("Enter three numbers:"); scanf("%d %d %d",&a,&b,&c); ascend(&a,&b,&c); printf("The numbers in ascending order:"); printf("%d %d %d",a,b,c); getch(); return 0; }
  • 5. Practical No : 14 /* Write a recursive program to test whether given number is prime */ #include<stdio.h> #include<conio.h> int main() { int n,p; clrscr(); printf("Enter any number:"); scanf("%d",&n); p=prime(n,n/2); if(p==1) { printf("%d is a prime number",n); } else { printf("%d is a composite number",n); } getch(); } int prime(int n,int i) { if(i==1) return 1; if(n%i==0) return 0; return prime(n,i-1); }
  • 6. Practical No : 16 /* Write a program to sort an Array using Pointer */ #include<stdio.h> #include<conio.h> int main() { int a[5],i,j,n,temp; int *p=&a[0]; clrscr(); scanf("%d",&n); printf("nEnter the elements in array"); for(i=0;i<n;i++) { scanf("%d",(p+i)); printf("nEnter the size of array:"); } printf("nThe element of an array is:"); for(i=0;i<n;i++) { printf(" %d",*(p+i)); } //Logic to sort an array using pointer for(i=0;i<n-1;i++) { for(j=0;j<n-i-1;j++) { if(*(p+j) > *(p+(j+1))) { temp=*(p+j) ; *(p+j)=*(p+(j+1)); *(p+(j+1))=temp; } } } printf("nArray element of an array after sorting :"); for(i=0;i<n;i++) { printf(" %d",*(p+i)); } getch(); } /* Write a program to sort an Array using Pointer */ #include<stdio.h> #include<conio.h> int main() { int a[5],i,j,n,temp; int *p=&a[0]; clrscr(); printf("nEnter the size of array:"); scanf("%d",&n);
  • 7. printf("nEnter the elements in array"); for(i=0;i<n;i++) { scanf("%d",(p+i)); } printf("nThe element of an array is:"); for(i=0;i<n;i++) { printf(" %d",*(p+i)); } //Logic to sort an array using pointer for(i=0;i<n-1;i++) { for(j=0;j<n-i-1;j++) { if(*(p+j) > *(p+(j+1))) { temp=*(p+j) ; *(p+j)=*(p+(j+1)); *(p+(j+1))=temp; } } } printf("nArray element of an array after sorting :"); for(i=0;i<n;i++) { printf(" %d",*(p+i)); } getch(); }
  • 8. Practical No : 12 /* write a program to demonstrate call by value parameter passing technique */ #include<stdio.h> #include<conio.h> int pass(int x,int y) { int temp; temp=x; x=y; y=temp; printf("The value before swap is x=%d,y=%dn",x,y); return 0; } int main() { int x=14,y=56,temp; clrscr(); printf("Enter number to check:n"); pass(x,y); printf("The swap value is x=%d,y=%dn",x,y); getch(); }