Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
26 views6 pages

IIBcom LabPrograms

Uploaded by

luckyjagadesh0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views6 pages

IIBcom LabPrograms

Uploaded by

luckyjagadesh0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Programmming with C & C++ II B.Com-III Semester St.

Joseph`s Degree College, Knl

Lab Programs

1. Program to check for palindrome number or not.

#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();

2a.) Program to demonstrate call by value.

#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

void swap(int a,int b)


{
int temp;
temp=a;
a=b;
b=temp;
}

2b.) Program to demonstrate call by reference.

#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();
}

void swap(int *a,int *b)


{
int temp;
temp=*a;
*a=*b;
*b=temp;
}

3. Program to find a factorial of a given number using Recursion.

#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);
}
}

4.Program to sort the array in descending order.

#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();
}

5.Program on pointer- Operators.

#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

You might also like