際際滷

際際滷Share a Scribd company logo
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
Ad

Recommended

Data Structure using C
Data Structure using C
Bilal Mirza
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
C lab manaual
C lab manaual
manoj11manu
C Programming Example
C Programming Example
PRATHAMESH DESHPANDE
C Programming Example
C Programming Example
University of Potsdam
Practical File of C Language
Practical File of C Language
RAJWANT KAUR
Common problems solving using c
Common problems solving using c
ArghodeepPaul
c-programming-using-pointers
c-programming-using-pointers
Sushil Mishra
All important c programby makhan kumbhkar
All important c programby makhan kumbhkar
sandeep kumbhkar
C PROGRAMS
C PROGRAMS
Malikireddy Bramhananda Reddy
C programms
C programms
Mukund Gandrakota
C programming array & shorting
C programming array & shorting
argusacademy
Cpds lab
Cpds lab
praveennallavelly08
Data Structures Using C Practical File
Data Structures Using C Practical File
Rahul Chugh
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
Pushover analysis force analogy method with force control based on timoshenko...
Pushover analysis force analogy method with force control based on timoshenko...
Salar Delavar Qashqai
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DR B.Surendiran .
Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...
Salar Delavar Qashqai
C Prog. - Structures
C Prog. - Structures
vinay arora
4. chapter iii
4. chapter iii
Chhom Karath
Practical 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)
vinay arora
Chapter 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 number
Mainak Sasmal
DataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
C Programming
C Programming
Sumant Diwakar
C Prog - Strings
C Prog - Strings
vinay arora
ADA FILE
ADA FILE
Gaurav Singh
Research ppr
Research ppr
Sara Sahu
Spangram
Spangram
Mik Endale

More Related Content

What's hot (20)

All important c programby makhan kumbhkar
All important c programby makhan kumbhkar
sandeep kumbhkar
C PROGRAMS
C PROGRAMS
Malikireddy Bramhananda Reddy
C programms
C programms
Mukund Gandrakota
C programming array & shorting
C programming array & shorting
argusacademy
Cpds lab
Cpds lab
praveennallavelly08
Data Structures Using C Practical File
Data Structures Using C Practical File
Rahul Chugh
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
Pushover analysis force analogy method with force control based on timoshenko...
Pushover analysis force analogy method with force control based on timoshenko...
Salar Delavar Qashqai
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DR B.Surendiran .
Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...
Salar Delavar Qashqai
C Prog. - Structures
C Prog. - Structures
vinay arora
4. chapter iii
4. chapter iii
Chhom Karath
Practical 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)
vinay arora
Chapter 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 number
Mainak Sasmal
DataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
C Programming
C Programming
Sumant Diwakar
C Prog - Strings
C Prog - Strings
vinay arora
ADA FILE
ADA FILE
Gaurav Singh
All important c programby makhan kumbhkar
All important c programby makhan kumbhkar
sandeep kumbhkar
C programming array & shorting
C programming array & shorting
argusacademy
Data Structures Using C Practical File
Data Structures Using C Practical File
Rahul Chugh
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
Pushover analysis force analogy method with force control based on timoshenko...
Pushover analysis force analogy method with force control based on timoshenko...
Salar Delavar Qashqai
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DR B.Surendiran .
Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...
Salar Delavar Qashqai
C 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 number
Mainak Sasmal
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
vinay arora
Chapter 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 number
Mainak Sasmal
C Prog - Strings
C Prog - Strings
vinay arora

Viewers also liked (6)

Research ppr
Research ppr
Sara Sahu
Spangram
Spangram
Mik Endale
Can We Really Run Our Businesses On Open Source Software
Can We Really Run Our Businesses On Open Source Software
Digium
temani10
Lesson 8 Memory Storage And Management
Lesson 8 Memory Storage And Management
Laguna State Polytechnic University
OSOS SEM 4 Chapter 1
OSOS SEM 4 Chapter 1
Syahriha Ruslan
Research ppr
Research ppr
Sara Sahu
Can We Really Run Our Businesses On Open Source Software
Can We Really Run Our Businesses On Open Source Software
Digium
Ad

Similar to SaraPIC (20)

some basic C programs with outputs
some basic C programs with outputs
KULDEEPSING PATIL
C BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHF
C BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHF
AbcdR5
C file
C file
simarsimmygrewal
Simple C programs
Simple C programs
ab11cs001
Muzzammilrashid
Muzzammilrashid
muzzammilrashid
C code examples
C code examples
Industrial Electric, Electronic Ind. And Trade Co. Ltd.
Najmul
Najmul
Najmul Ashik
C important questions
C important questions
JYOTI RANJAN PAL
C language
C language
Priya698357
C Programming lab
C Programming lab
Vikram Nandini
Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
C-programs
C-programs
SSGMCE SHEGAON
Fuzail_File_C.docx
Fuzail_File_C.docx
SyedFuzail14
C programs
C programs
Vikram Nandini
Functions
Functions
Swarup Kumar Boro
Introduction to Basic C programming 01
Introduction to Basic C programming 01
Wingston
C
C
Mukund Trivedi
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
KavyaSharma65
B.Com 1year Lab programs
B.Com 1year Lab programs
Prasadu Peddi
Hargun
Hargun
Mukund Trivedi
Ad

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