IIBcom LabPrograms
IIBcom LabPrograms
Lab Programs
#include<stdio.h>
#include<conio.h>
main()
{
int num, reverse = 0, temp;
clrscr();
printf("Enter a number to check if it is a palindrome or not: ");
scanf("%d",&num);
temp = num;
while( num>0)
{
reverse = reverse * 10; reverse =
reverse + num%10; num =
num/10;
}
if ( temp == reverse )
printf("%d is a palindrome number.\n",temp); else
printf("%d is not a palindrome number.\n",temp); getch();
#include<stdio.h>
#include<conio.h>
void swap(int,int);
main()
{
int n1=10,n2=20;
clrscr();
printf("Values of n1=%d and n2=%d before function call",n1,n2);
swap(n1,n2);
printf("\nValue of n1=%d and n2=%d after function call",n1,n2);
getch();
}
1
Programmming with C & C++ II B.Com-III Semester St. Joseph`s Degree College, Knl
#include<stdio.h>
#include<conio.h>
void swap(int *,int *);
main()
{
int n1=10,n2=20;
clrscr();
printf("Values of n1=%d and n2=%d before functioncall",n1,n2);
swap(&n1,&n2);
printf("\nValue of n1=%d and n2=%d after function call",n1,n2);
getch();
}
#include<stdio.h>
int fact(int);
int main()
{
int x,f;
clrscr();
printf(“Enter the number whose factorial you want to calculate”);
2
Programmming with C & C++ II B.Com-III Semester St. Joseph`s Degree College, Knl
scanf(“%d”,&x);
f=fact(x);
printf(“Factorial=%d”,f);
}
Int fact(int n)
{
If(n==0)
{
return 0;
}
else if(n==1)
{
return 1;
}
else
{
return n *fact(n-1);
}
}
#include<stdio.h>
#include<conio.h>
int main()
{
int arr[100];
int size, i, j, temp;
clrscr();
printf("Enter size of array: ");
scanf("%d", &size);
printf("Enter elements in array: "); for(i=0;
i<size; i++)
{
scanf("%d", &arr[i]);
}
for(i=0; i<size; i++)
{
for(j=i+1; j<size; j++)
{
3
Programmming with C & C++ II B.Com-III Semester St. Joseph`s Degree College, Knl
if(arr[i] < arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
printf("Elements of array in sorted descending order: \n");
for(i=0; i<size; i++)
{
printf("%d\t", arr[i]);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10;
int *p,*q; //pointer declaration
p=&a; //Assigning a value to the pointer
clrscr();
printf("\n The value of a=%d”,a);
printf("\n The address of a=%u”,p);
printf(“\n Displaying value of a using value-at operators”);
printf("\n The value of a=%d”,*p);
printf(“\n Displaying address of variable a using address of
operators”);
printf("\n The address of a=%u”,&a);
printf("\n The value of p=%u”,p);
printf("\n Increment and Decrement operators on pointer”);
printf("\n p=%u \t p+1=%u \t p-1=%u”,p,p+1,p-1);
printf("\n p=%u \t p++=%u \t p--=%u”,p,p+1,p-1);
printf(“\n Assignment operator on pointers”);
q=p;
printf(“\n Comparison operator on pointers”);
if(p==q)
printf(“/n p&q pointers are pointing to variable a”);
4
Programmming with C & C++ II B.Com-III Semester St. Joseph`s Degree College, Knl
else
printf(“/n p&q pointers are pointing to different variables”);
}
5
Programmming with C & C++ II B.Com-III Semester St. Joseph`s Degree College, Knl