Vous êtes sur la page 1sur 14

PracticalNo1

//Programtodisplayhexadecimal,decimalandoctalformatoftheenterednumber
#include<stdio.h>
#include<conio.h>
voidmain()
{
inti;
clrscr();
printf(\nEnterTheNumber:);
scanf(%d,&i);
printf(\nHexadecimalFormat:%x,i);
printf(\nDecimalFormat:%d,i);
printf(\nOctalFormat:%o,i);
getch();

OUTPUTOFPROGRAM:
EnterTheNumber:10
HexadecimalFormat:a
DecimalFormat:10
OctalFormat:12

PracticalNo2
//Programtodemonstrateallpossibleformattingspecifiers
#include<stdio.h>
#include<conio.h>
voidmain()
{
intac_no;
floatinterest,deposit;
charcname[20];
clrscr();
printf(\nEnterNumberandName:);
scanf(%d%s,&ac_no,name);
printf(\nEnterdepositandinterest:);
scanf(%f%f,&deposit,&interest);
printf(\nA/CNumber:%d\tName:%s \n Deposit: %f \t Interest: %f ,
ac_no,cname,deposit,interest);
getch();
}

OUTPUT OF PROGRAM:
EnterNumberandName: 4787 ABC
Enterdepositandinterest:95647.8
A/CNumber:4787
Name: ABC
Deposit:9564
Interest:7.8000

PracticalNo3
//Programtofindgreatest/smallestofthreenumbers

#include<stdio.h>
#include<conio.h>
voidmain()
{
intn1,n2,n3;
clrscr();

printf(\nEnterthreenumbers:);
scanf(%d%d%d,&n1,&n2,&n3);

if(n1==n2&&n1==n3)
{
printf(\nAllnumbersaresame);
}
elseif(n1>=n2&&n1>=n3)
{
printf(\nThegreatestnumberis%d,n1);
}
elseif(n2>=n1&&n2>=n3)
{
printf(\nThegreatestnumberis%d,n2);
}
elseif(n3>=n1&&n3>=n2)
{
printf(\nThegreatestnumberis%d,n3);
}

getch();
}

OUTPUTOFPROGRAM:

Enterthreenumbers:104534
Thegreatestnumberis45

PracticalNo4
//Programtofindeven/oddnumbers

#include<stdio.h>
#include<conio.h>

voidmain()
{
inti;
clrscr();

for(i=1;i<=10;i++)
{
if(i%2==0)

{

printf(\n%disEVENnumber,i);
}
else
{
printf(\n%disODDnumber,i);
}
}
getch();
}

OUTPUTOFPROGRAM:

1isODDnumber

2isEVENnumber

3isODDnumber

4isEVENnumber

5isODDnumber

6isEVENnumber

7isODDnumber

8isEVENnumber

9isODDnumber

10isEVENnumber

ProgramNo5
//programtodisplaymenuandexecuteitusingswitchcase
#include<stdio.h>
#include<conio.h>
voidmain()
{floatn1,n2,n3;
intc;
clrscr();
printf(\n1.Addition);
printf(\n2.Subtraction);
printf(\n3.Multiplication);
printf(\n4.Division);
printf(\nEntertwonumbers);
scanf(%f%f,&n1,&n2);
printf(\nEnteryourchoice);
scanf(%d,&c);
switch(c)
{
case1:n3=n1+n2;
print(\nAdditionis%f,n3);
break;
case2:n3=n1n2;
print(\nSubtractionis%f,n3);
break;
case3:n3=n1*n2;
print(\nMultiplicationis%f,n3);
break;
case4:n3=n1/n2;
print(\nDivisionis%f,n3);
break;
default:
print(\nWrongchoice);
}
getch();
}
OUTPUT OF PROGRAM:
1.Addition
2.Subtraction
3.Multiplication
4.Division
Entertwonumbers:52
Enteryourchoice:4
Divisionis2.5000

Practical No 6
//Program to perform addition of 1-100 numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,sum=0;
clrscr();
while(i<=100)
{
sum = sum + i;
i++;
}
printf(\n The addition of 1-100 numbers is %d,sum);
getch();
}

OUTPUT OF PROGRAM:
The addition of 1-100 numbers is 5050

PracticalNo7
//Programtofindsmallest/largestnumberfromarrayelements.
#include<stdio.h>
#include<conio.h>
voidmain()
{intarr[5],great,small,i;
clrscr();
printf(\nEntertheArrayelements:);
for(i=0;i<=4;i++)
{
scanf(%d,&arr[i]);
}
small=arr[0];
for(i=1;i<=4;i++)
{
if(a[i]<=small)
{
small=a[i];
}
}
printf(\nThesmallestnumberis:%d,small);
great=arr[0];
for(i=1;i<=4;i++)
{
if(a[i]>=great)
{
great=a[i];
}
}
printf(\nTheGreatestnumberis:%d,great);
getch();
}

OUTPUTOFPROGRAM:
EntertheArrayelements:102536579
Thesmallestnumberis:5
TheGreatestnumberis:79

Practical No 8
// program to calculate multiplication of 2 dimensional matrix.
#include<stdio.h>
#include<conio.h>
void main()
{ int a1[2][2], a2[2][2], a3[2][2], i, j;
clrscr();
printf(\n Enter first matrix: );
for( i = 0 ; i < = 1 ; i+ +)
{
for( j = 0; j < = 1; j + +)
{
scanf( %d , & a1[i][j] );
}
}
printf(\n Enter second matrix: );
for( i = 0 ; i < = 1 ; i+ +)
{
for( j = 0; j < = 1; j + +)
{
scanf( %d , & a2[i][j] );
}
}
a3[0][0] = a1[0][0]*a2[0][0] + a1[0][1]*a2[1][0];
a3[0][1] = a1[0][0]*a2[0][1] + a1[0][1]*a2[1][1];
a3[1][0] = a1[1][0]*a2[0][0] + a1[1][1]*a2[1][0];
a3[1][1] = a1[1][0]*a2[0][1] + a1[1][1]*a2[1][1];
printf(\n Multiplication of matrices is: \n);
for( i = 0 ; i < = 1 ; i+ +)
{
for( j = 0; j < = 1; j + +)
{
printf( %d \t , a3[i][j] );
}
printf(\n);
}
getch();
}
OUTPUT OF PROGRAM:
Enter first matrix: 1
1
Enter second matrix: 1
1
Multiplication of matrices is:
2
2
2
2

1
1

Practical No 9
// program to demonstrate output of standard library string functions
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{ char str1[10], str2[10];
int c , l1 ,l2 ;
clrscr();
puts("\n Enter first string:");
gets(str1);
puts("\n Enter second string:");
gets(str2);
l1 = strlen(str1);
l2 = strlen(str2);
printf("\n length of first string is: %d \n length of second string is : %d", l1, l2);
c = strcmp( str1, str2 );
if(c = = 0)
{
printf("\n Strings are equal");}
else
{
printf("\n Strings are not equal");
}
strcat( str1, str2);
printf("\nStrings after concatenation are, \n str1 = %s \n str2 = %s", str1, str2);
strcpy( str2, str1);
printf("\nStrings after copying are, \n str1 = %s \n str2 = %s",str1,str2);
getch();
}
OUTPUT OF PROGRAM: Enter first string: ABC
Enter second string: PQRST
length of first string is: 3
length of second string is : 5
Strings are not equal
Strings after concatenation are,
str1 = ABCPQRST
str2 = PQRST
Strings after copying are,
str1 = PQRST
str2 = PQRST

Practical No.10
// program to find factorial of any given number using recursion
#include<stdio.h>
#include<conio.h>
void main()
{
long int fact(int), f ;
int n;
clrscr();
printf("\n Enter number: ");
scanf("%d",&n);
f = fact (n);
printf("\n Factorial is: %d",f);
getch();
}
long int fact (int x)
{
long int y ;
if(x==1)
{
return 1;
}
else
{
y = x * fact (x-1) ;
return y ;
}
}
OUTPUT OF PROGRAM:
Enter number: 5
Factorial is: 120

Practical No 11
// program to demonstrate Call by value
#include<stdio.h>
#include<conio.h>
void main()
{
int add(int,int),n1,n2,a;
clrscr();
printf(\n------------Program for Call by Value----------);
printf(\n Enter two numbers:);
scanf(%d%d,&n1,&n2);
a = add(n1,n2);
printf(\n Addition is %d,a);
getch();
}
int add(int x, int y)
{
return (x+y);
}
OUTPUT OF PROGRAM:
------------Program for Call by Value---------Enter two numbers: 5 10
Addition is 15
// program to demonstrate Call by reference
#include<stdio.h>
#include<conio.h>
void main()
{
int add(int *,int *),n1,n2,a;
clrscr();
printf(\n------------Program for Call by Reference----------);
printf(\n Enter two numbers:);
scanf(%d%d,&n1,&n2);
a = add(&n1,&n2);
printf(\n Addition is %d,a);
getch();
}
int add(int *x, int *y)
{
return (*x+*y);
}
OUTPUT OF PROGRAM:
------------Program for Call by Reference---------Enter two numbers: 5 10
Addition is 15

Practical no 12
// program to maintain and manipulate student data using structure
# include<stdio.h>
# include<conio.h>
struct student
{ int rollno;
char name[20];
float percentage;
};
void main()
{
struct student s;
clrscr();
printf(\n Enter student data:);
printf(\n Enter student roll number:);
scanf(%d,&s.rollno);
printf(\n Enter student name:);
scanf(%s,&s.name);
printf(\n Enter student percentage:);
scanf(%f,&s.percentage);
printf(\n\n The student data is:);
printf(\n The student roll number is: %d,s.rollno);
printf(\n The student name is: %s,s.name);
printf(\n The student percentage are: %f,s.percentage);
getch();
}

OUTPUT OF PROGRAM:
Enter student data:
Enter student roll number: 1
Enter student name: abc
Enter student percentage: 70.89
The student data is:
The student roll number is: 1
The student name is: abc
The student percentage are: 70.8900

// program to demonstrate array of structure


# include<stdio.h>
# include<conio.h>
struct student
{ int rollno;
char name[20]
};
void main()
{
struct student s[3];
int i;
clrscr();
for(i=0;i<=2;i++)
{
printf(\n Enter student roll number:);
scanf(%d,&s[i].rollno);
printf(\n Enter student name:);
scanf(%s,&s[i].name);
}
printf(\n\n The student data is:);
for(i=0;i<=2;i++)
{
printf(\n The student roll number is: %d,s[i].rollno);
printf(\n The student name is: %s,s[i].name);
}
getch();
}

OUTPUT OF PROGRAM:
Enter student roll number: 1
Enter student name: abc
Enter student roll number: 2
Enter student name: pqr
Enter student roll number: 3
Enter student name: xyz
The student data is:
The student roll number is: 1
The student name is: abc
The student roll number is: 2
The student name is: pqr
The student roll number is: 3
The student name is: xyz

Practical No 13
// program to perform 4 arithmetic functions on pointers.
#include<stdio.h>
#include<conio.h>
void main()
{
int *p1,*p2;
int a=10,b=5;
clrscr();
p1 = &a;
p2 = &b;
printf(\n Addition of pointers: %d, (*p1) + (*p2));
printf(\n Subtraction of pointers: %d, (*p1) - (*p2));
printf(\n Multiplication of pointers: %d, (*p1) * (*p2));
printf(\n Division of pointers: %d, (*p1) / (*p2));
printf(\n\n p1++ is : %u and p1 is :%u, ++p1,p1);
printf(\n p1- - is : %u and p1 is :%u, - -p1,p1);
getch();
}

OUTPUT OF PROGRAM:
Addition of pointers: 15
Subtraction of pointers: 5
Multiplication of pointers: 50
Division of pointers: 2
p1++ is : 65526 and p1 is : 65524
p1- - is : 65524 and p1 is : 65526

Vous aimerez peut-être aussi