SlideShare a Scribd company logo
1 of 18
Practical no.1

Write a C program to display hexadecimal decimal octal format of the
entered numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
intnum;
clrscr();
printf("Enter the number : ");
scanf("%d",&num);
printf("nDecimal format : %d",num);
printf("nHexaDecimal format : %x",num);
printf("nOctal format : %o",num);
getch();
}




OUTPUT:

Enter the number:12

Decimal format :12

Hexadecimal format:c

Octal format:14
Practical no.2

To demonstrate all possible formatting specifiers.

Format Specifiers for C
%c      The character format specifier.
%d      The integer format specifier.
%i      The integer format specifier (same as %d).
%f      The floating-point format specifier.
%e      The scientific notation format specifier.
%E      The scientific notation format specifier.
%g      Uses %f or %e, whichever result is shorter.
%G      Uses %f or %E, whichever result is shorter.
%o      The unsigned octal format specifier.
%s      The string format specifier.
%u      The unsigned integer format specifier.
%x      The unsigned hexadecimal format specifier.
%X      The unsigned hexadecimal format specifier.
%p      Displays the corresponding argument that is a pointer.
%n      Records the number of characters written so far.
%%      Outputs a percent sign.

printf statements is called an escape sequence:
     n (newline)
     t (tab)
     v (vertical tab)
     f (new page)
     b (backspace)
     r (carriage return)
     n (newline)
Practical no.3

Write a program to find the largest and the smallest from the given
three integers.
#include<stdio.h>

#include<conio.h>

void main()

{

int num1, num2, num3;

clrscr();

printf("Enter three numbers = ");

scanf("%d %d %d", &num1, &num2, &num3);

printf("nnThe largest number is ");

if( (num1 > num2) && (num1 > num3) )

printf("%d", num1);

else if(num2 > num3)

printf("%d", num2);

else

printf("%d", num3);

printf("nnThe Smallest number is ");

if( (num1 < num2) && (num1 < num3) )

printf("%d", num1);

else if(num2 < num3)
printf("%d", num2);

else

printf("%d",num3);

getch();

}




OUTPUT:

Enter three numbers: 12

15

67

The largest no. is :67

The smallest no.is :12
Practical no.4
Write a C program to find even or odd numbers.
#include<stdio.h>
main()
{

intnum;

printf ("Enter a number to be checked for even/odd: ");
scanf ("%d",&num);

if (num%2==0)
{
printf ("The entered number is EVEN.n");

}
else
{
printf ("The entered number is ODD.n");

}
}




OUTPUT:

Enter a number to be checked for even/odd:15

The entered number is ODD.
Practical no.5
Write a C program to display menu 1.Addition 2.Subtraction
3.Multiplication 4.Division and execute it using switch case.
#include<stdio.h>
#include<conio.h>
void main()
{
inta,b,c;
int menu;
printf("choose the arithmetic optionn");
scanf("%d",&menu);
switch(menu)
{
case 1:
printf("Enter The Two Numbers:n");
scanf("%d%d",&a,&b);
c=a+b;
printf("The addition of two numbers %dn",c);
break;

case 2:
printf("Enter THE TWO NUMBERS:n");
scanf("%d%d",&a,&b);
c=a-b;
printf("The subtraction of two numbers %dn",c);
break;

case 3:

printf("Enter THE TWO NUMBERS:n");
scanf("%d%d",&a,&b);
c=a*b;
printf("The multiplication of two numbers %dn",c);
break;

case 4:

printf("Enter THE TWO NUMBERS:n");
scanf("%d%d",&a,&b);
c=a/b;
printf("The division of two numbers %dn",c);
break;
}
getch();
}




OUTPUT:

choose the arithmetic option

2

Enter THE TWO NUMBERS:

15 6

The subtraction of two numbers :9
Practical no.6
Write a c program to perform addition all numbers from 1 to 100.
#include<stdio.h>
#include<conio.h>

void main()

{

int i=0,sum=0;

clrscr();

while(i<100)

{

sum=sum+i;

i++;

}

printf("Addition of all numbers from 1-100=%d",sum);

getch();

}




OUTPUT:

Addition of all numbers from 1-100=4950
Practical no.7

Write a C program to find smallest and largest number from array
elements.
#include<stdio.h>
#include<conio.h>
Void main()

{

       int a[20],min,max;

       intn,i;

clrscr();

       printf("enter the num of elementst:");

       scanf("%d",&n);



       printf("enter the elementsn");

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

       {

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

                 if(i==0)

                 {

                       min=max=a[i];



                 }

                 if(a[i]<min)

                       min=a[i];

                 else if(a[i]>max)
max=a[i];

       }

       printf("largest element is %d n Smallest element is %d ",max,min);

getch();

}




OUTPUT:

enter the num of elements:5

enter the element:12

56

23

10

78

largest element is 78

Smallest element is 10
Practical no.8
Write a C program to enter elements for 3*3matrix and display them.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],i,j;
clrscr();
printf("ENTER ELEMENTSn");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("THE ELEMENTS IN 3*3 MATRIX FORM ISn");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",a[i][j]);
}
printf("n");
}
getch();
}




OUTPUT:

ENTER ELEMENTS
1
2
3
4
5
6
7
8
9
THE ELEMENTS IN 3*3 MATRIX FORM IS
1      2      3
4      5      6
7      8      9
Practical no.9
Write a C program to demonstrate output of standard library
functions. Strlent( ),strcpy( ),strcat( ),strcmp( ).
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[10],s2[10],s3[30];
int a;
clrscr();
printf("enter the two stringsn");
scanf("%s%s",&s1,&s2);
printf("1st String=%sn2ndString=%s",s1,s2);
if(strcmpi(s1,s2) == 0 )
printf("Entered strings are equal.n");
else
printf("Entered strings are not equal.n");

a=strlen(s1);
printf("nLength=%d",a);
strcat(s1,s2);
printf("nconcatinated string=%s",s1);
strcpy(s1,s2);
printf("ncopied string=%s",s1);

getch();
}
OUTPUT:

enter the two strings
Good
Morning
1st String=Good
2ndString=Morning
Entered strings are not equal.
Length=4
concatinated string=GoodMorning
copied string=Morning
Practical no.10
Write a C program to calculatefactorial of any number using
recursion.
#include<stdio.h>
#include<conio.h>
int fact(int );
int main()
{
  intnum,res;
  printf("Enter any number: ");
  scanf("%d", &num);
  res = fact(num);
  printf("Factorial value is: %d",res);
  getch();
  return 0;
}
int fact(int n)
{
  int f;
  if(n==1)
    return(1);
  else
    f = n*fact(n-1);
  return(f);
}



OUTPUT:

Enter any number:5

Factorial value is:120
Practical no.11
Write a C program to demonstrate call by value and call by reference.
//CALL BY VALUE
#include<stdio.h>
#include<conio.h>
int swap(int,int);
void main()
{
inta,b;
printf("nenter two values:");
scanf("%d%d",&a,&b);
printf("Before swapping:n");
printf("A=%dn B=%d",a,b);
swap(a,b);
getch();
}


int swap(intx,int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("After swapping:n A=%dnB=%d",x,y);
return(0);
}



OUPUT:
enter two values
30
20
Before swapping:
A=30
B=20
After swapping:
A=20
B=30
//CALL BY REFERENCE
#include<stdio.h>
#include<conio.h>
int swap(int *,int *);
void main()
{
inta,b;
printf("nenter two values:");
scanf("%d%d",&a,&b);
printf("Before swapping:n");
printf("A=%dn B=%d",a,b);
swap(&a,&b);
getch();
}
int swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
printf("After swapping:n A=%dnB=%d",*x,*y);
return(0);
}
OUPUT:
enter two values
30
20
Before swapping:
A=30
B=20
After swapping:
A=20
B=30

More Related Content

What's hot

C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
vinay arora
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
vinay arora
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
vinay arora
 

What's hot (20)

All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
C programms
C programmsC programms
C programms
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
Pushover analysis force analogy method with force control based on timoshenko...
Pushover analysis force analogy method with force control based on timoshenko...Pushover analysis force analogy method with force control based on timoshenko...
Pushover analysis force analogy method with force control based on timoshenko...
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
C Programming
C ProgrammingC Programming
C Programming
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
 

Viewers also liked (6)

Research ppr
Research pprResearch ppr
Research ppr
 
Spangram
SpangramSpangram
Spangram
 
Can We Really Run Our Businesses On Open Source Software
Can We Really Run Our Businesses On Open Source SoftwareCan We Really Run Our Businesses On Open Source Software
Can We Really Run Our Businesses On Open Source Software
 
לוגו
לוגולוגו
לוגו
 
Lesson 8 Memory Storage And Management
Lesson 8 Memory Storage And ManagementLesson 8 Memory Storage And Management
Lesson 8 Memory Storage And Management
 
OSOS SEM 4 Chapter 1
OSOS SEM 4 Chapter 1OSOS SEM 4 Chapter 1
OSOS SEM 4 Chapter 1
 

Similar to SaraPIC

C basics
C basicsC basics
C basics
MSc CST
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
Vishal Singh
 

Similar to SaraPIC (20)

C basics
C basicsC basics
C basics
 
Arrays
ArraysArrays
Arrays
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
C file
C fileC file
C file
 
C-programs
C-programsC-programs
C-programs
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
 
Ds
DsDs
Ds
 
C programming codes for the class assignment
C programming codes for the class assignmentC programming codes for the class assignment
C programming codes for the class assignment
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 
array.ppt
array.pptarray.ppt
array.ppt
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
C lab
C labC lab
C lab
 
Progr3
Progr3Progr3
Progr3
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 

SaraPIC

  • 1. Practical no.1 Write a C program to display hexadecimal decimal octal format of the entered numbers. #include<stdio.h> #include<conio.h> void main() { intnum; clrscr(); printf("Enter the number : "); scanf("%d",&num); printf("nDecimal format : %d",num); printf("nHexaDecimal format : %x",num); printf("nOctal format : %o",num); getch(); } OUTPUT: Enter the number:12 Decimal format :12 Hexadecimal format:c Octal format:14
  • 2. Practical no.2 To demonstrate all possible formatting specifiers. Format Specifiers for C %c The character format specifier. %d The integer format specifier. %i The integer format specifier (same as %d). %f The floating-point format specifier. %e The scientific notation format specifier. %E The scientific notation format specifier. %g Uses %f or %e, whichever result is shorter. %G Uses %f or %E, whichever result is shorter. %o The unsigned octal format specifier. %s The string format specifier. %u The unsigned integer format specifier. %x The unsigned hexadecimal format specifier. %X The unsigned hexadecimal format specifier. %p Displays the corresponding argument that is a pointer. %n Records the number of characters written so far. %% Outputs a percent sign. printf statements is called an escape sequence: n (newline) t (tab) v (vertical tab) f (new page) b (backspace) r (carriage return) n (newline)
  • 3. Practical no.3 Write a program to find the largest and the smallest from the given three integers. #include<stdio.h> #include<conio.h> void main() { int num1, num2, num3; clrscr(); printf("Enter three numbers = "); scanf("%d %d %d", &num1, &num2, &num3); printf("nnThe largest number is "); if( (num1 > num2) && (num1 > num3) ) printf("%d", num1); else if(num2 > num3) printf("%d", num2); else printf("%d", num3); printf("nnThe Smallest number is "); if( (num1 < num2) && (num1 < num3) ) printf("%d", num1); else if(num2 < num3)
  • 4. printf("%d", num2); else printf("%d",num3); getch(); } OUTPUT: Enter three numbers: 12 15 67 The largest no. is :67 The smallest no.is :12
  • 5. Practical no.4 Write a C program to find even or odd numbers. #include<stdio.h> main() { intnum; printf ("Enter a number to be checked for even/odd: "); scanf ("%d",&num); if (num%2==0) { printf ("The entered number is EVEN.n"); } else { printf ("The entered number is ODD.n"); } } OUTPUT: Enter a number to be checked for even/odd:15 The entered number is ODD.
  • 6. Practical no.5 Write a C program to display menu 1.Addition 2.Subtraction 3.Multiplication 4.Division and execute it using switch case. #include<stdio.h> #include<conio.h> void main() { inta,b,c; int menu; printf("choose the arithmetic optionn"); scanf("%d",&menu); switch(menu) { case 1: printf("Enter The Two Numbers:n"); scanf("%d%d",&a,&b); c=a+b; printf("The addition of two numbers %dn",c); break; case 2: printf("Enter THE TWO NUMBERS:n"); scanf("%d%d",&a,&b); c=a-b; printf("The subtraction of two numbers %dn",c); break; case 3: printf("Enter THE TWO NUMBERS:n"); scanf("%d%d",&a,&b); c=a*b; printf("The multiplication of two numbers %dn",c); break; case 4: printf("Enter THE TWO NUMBERS:n"); scanf("%d%d",&a,&b); c=a/b; printf("The division of two numbers %dn",c); break; }
  • 7. getch(); } OUTPUT: choose the arithmetic option 2 Enter THE TWO NUMBERS: 15 6 The subtraction of two numbers :9
  • 8. Practical no.6 Write a c program to perform addition all numbers from 1 to 100. #include<stdio.h> #include<conio.h> void main() { int i=0,sum=0; clrscr(); while(i<100) { sum=sum+i; i++; } printf("Addition of all numbers from 1-100=%d",sum); getch(); } OUTPUT: Addition of all numbers from 1-100=4950
  • 9. Practical no.7 Write a C program to find smallest and largest number from array elements. #include<stdio.h> #include<conio.h> Void main() { int a[20],min,max; intn,i; clrscr(); printf("enter the num of elementst:"); scanf("%d",&n); printf("enter the elementsn"); for( i=0;i<n;i++) { scanf("%d",&a[i]); if(i==0) { min=max=a[i]; } if(a[i]<min) min=a[i]; else if(a[i]>max)
  • 10. max=a[i]; } printf("largest element is %d n Smallest element is %d ",max,min); getch(); } OUTPUT: enter the num of elements:5 enter the element:12 56 23 10 78 largest element is 78 Smallest element is 10
  • 11. Practical no.8 Write a C program to enter elements for 3*3matrix and display them. #include<stdio.h> #include<conio.h> void main() { int a[3][3],i,j; clrscr(); printf("ENTER ELEMENTSn"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("THE ELEMENTS IN 3*3 MATRIX FORM ISn"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d",a[i][j]); } printf("n"); } getch(); } OUTPUT: ENTER ELEMENTS 1 2 3 4 5 6 7 8 9 THE ELEMENTS IN 3*3 MATRIX FORM IS 1 2 3 4 5 6 7 8 9
  • 12. Practical no.9 Write a C program to demonstrate output of standard library functions. Strlent( ),strcpy( ),strcat( ),strcmp( ). #include<stdio.h> #include<conio.h> #include<string.h> void main() { char s1[10],s2[10],s3[30]; int a; clrscr(); printf("enter the two stringsn"); scanf("%s%s",&s1,&s2); printf("1st String=%sn2ndString=%s",s1,s2); if(strcmpi(s1,s2) == 0 ) printf("Entered strings are equal.n"); else printf("Entered strings are not equal.n"); a=strlen(s1); printf("nLength=%d",a); strcat(s1,s2); printf("nconcatinated string=%s",s1); strcpy(s1,s2); printf("ncopied string=%s",s1); getch(); }
  • 13. OUTPUT: enter the two strings Good Morning 1st String=Good 2ndString=Morning Entered strings are not equal. Length=4 concatinated string=GoodMorning copied string=Morning
  • 14. Practical no.10 Write a C program to calculatefactorial of any number using recursion. #include<stdio.h> #include<conio.h> int fact(int ); int main() { intnum,res; printf("Enter any number: "); scanf("%d", &num); res = fact(num); printf("Factorial value is: %d",res); getch(); return 0; } int fact(int n) { int f; if(n==1) return(1); else f = n*fact(n-1); return(f); } OUTPUT: Enter any number:5 Factorial value is:120
  • 15. Practical no.11 Write a C program to demonstrate call by value and call by reference. //CALL BY VALUE #include<stdio.h> #include<conio.h> int swap(int,int); void main() { inta,b; printf("nenter two values:"); scanf("%d%d",&a,&b); printf("Before swapping:n"); printf("A=%dn B=%d",a,b); swap(a,b); getch(); } int swap(intx,int y) { int temp; temp=x; x=y; y=temp;
  • 16. printf("After swapping:n A=%dnB=%d",x,y); return(0); } OUPUT: enter two values 30 20 Before swapping: A=30 B=20 After swapping: A=20 B=30
  • 17. //CALL BY REFERENCE #include<stdio.h> #include<conio.h> int swap(int *,int *); void main() { inta,b; printf("nenter two values:"); scanf("%d%d",&a,&b); printf("Before swapping:n"); printf("A=%dn B=%d",a,b); swap(&a,&b); getch(); } int swap(int *x,int *y) { int temp; temp=*x; *x=*y; *y=temp; printf("After swapping:n A=%dnB=%d",*x,*y); return(0); }
  • 18. OUPUT: enter two values 30 20 Before swapping: A=30 B=20 After swapping: A=20 B=30