Home-Page


1./*WAP to find the largest and smallest number in anarray of 10 elements using function and display in the main function.*/

#include<stdio.h>
#include<conio.h>
int show(int *,int*);

void main()
{
int a[10],g,s,i;
printf("Enter the 10 numbers\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
s=show(&a[0],&g);
printf("Greatest number = %d \nSmallest number =%d\n",g,s);
getch();

}

int show(int *p,int *g)
{
int s,i;
s=*p;
*g=*p;
for(i=1;i<10;i++)
{
if(s>*(p+i))
{
s=*(p+i);
}
if(*g<*(p+i))
*g=*(p+i);
}
return s;
}

2/*WAP that allocates the elements for a one-dimensional array dynamically and sort it in ascending as well as in descending order using two diffenrent functions*/

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

void ascen(int*,int);
void descen(int*,int);

void main()
{
int *pa,i,n;
printf("How many numbers you want to give?\n");
scanf("%d",&n);
printf("Enter %d numbers\n",n);
pa=(int *)malloc(n*sizeof(int));
if(pa==NULL)
{
printf("Memory allcotion failed\n");
exit(1);
}
for(i=0;i<n;i++)
{
scanf("%d",pa+i);
}
ascen(pa,n);
printf("\nGiven numbers in asending order is : \n");
for(i=0;i<n;i++)
printf("%d\n",*(pa+i));
descen(pa,n);


getch();

}
void ascen(int *p,int n)
{
int i,j,temp;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(*(p+i)>*(p+j))
{
temp=*(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;
}
}
}
void descen(int *p,int n)
{
int i;

printf("\nGiven numbers in descending order is : \n");
for(i=n-1;i>=0;i--)
printf("%d\n",*(p+i));

}

3./*WAP that allocates two arrays dynamically on the basis of size read.populate them using a loop input from user and make comparison fuction to test if they are identical or not. Y have to display message from the test in the in a function*/

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

int test(int*,int*);

void main()
{
int *pa,*pb,i,n,size,result;
printf("How much size(in byte) of you want to allocate in RAM?\n");
scanf("%d",&size);
n=size/2;
printf("\nEnter %d numbers of first array\n",n);
pa=(int *)malloc(n*sizeof(int));
if(pa==NULL)
{
printf("Memory allcotion failed\n");
exit(1);
}
for(i=0;i<n;i++)
{
scanf("%d",pa+i);
}
printf("\nEnter %d numbers of first array\n",n);
pb=(int *)malloc(n*sizeof(int));
if(pb==NULL)
{
printf("Memory allcotion failed\n");
exit(1);
}
for(i=0;i<n;i++)
{
scanf("%d",pb+i);
}
for(i=0;i<n;i++)
{

result=test((pa+i),(pb+i));
if(result==0)
printf("Elements %d in two different array is not identical\n",i);
else
printf("Elements %d in two different array is identical\n",i);

}

getch();
}

int test(int *pa,int *pb)
{
if(*pa==*pb)
return 1;
else
return 0;

}

4./*WAP to check the symmetry of sqare matrix of order n .You need to have two functions as read() and process().*/

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

void read(int*,int);
void process(int*,int);

void main()
{
int a[10][10],i,r,result;

printf("\nEnter no of rows\n");
scanf("%d",&r);
printf("\nEnter the element of matrix row-wise\n");
read(&a[0][0],r);
process(&a[0][0],r);

 

getch();
}

void read(int *p,int r)
{
int i,j;

for(i=0;i<r;i++)
{
for(j=0;j<r;j++)
{
scanf("%d",p+i*10+j);
}
}

}
void process(int *a,int r)
{
int i,j,c=0;
for(i=0;i<r;i++)
{
for(j=0;j<r;j++)
{

if((*(a+i*10+j))==(*(a+j*10+i)))
{
c=1;
continue;
}
else
{
c=0;
break;
}
}


}

if(c==1)
printf("The matrix is symmetric\n");
else
printf("The matrix is not symmetric\n");


}


5./*WAP to perform multiplication of matrix of order mXn with another matrix whose elements are cube of the previous matrix.You need to have three fuctions as read(),process(),and display().*/

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

void read(int*,int,int);
void process(int*,int*,int*,int);
void display(int*,int,int);

void main()
{
int a[10][10],b[10][10],m[10][10]={0},i,j,r,c;

printf("\nEnter no of rows and columns\n");
scanf("%d%d",&r,&c);
printf("\nEnter the element of matrix 1 row-wise\n");
read(&a[0][0],r,c);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
*(&b[0][0]+i*10+j)=(*(&a[0][0]+i*10+j))*(*(&a[0][0]+i*10+j))*(*(&a[0][0]+i*10+j));
}
}

process(&m[0][0],&a[0][0],&b[0][0],r,c);
display(&m[0][0],r,c);
getch();

}

void read(int *p,int r,int c)
{
int i,j;

for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",p+i*10+j);
}
}

}
void process(int *m,int *a,int *b,int r,int c)
{
int i,j,k;

if(r!=c)
{
printf("Cannot Perform a Task\n");
exit(1);
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
for(k=0;k<r;k++)
{
*(m+i*10+j)+=(*(a+i*10+k)**(b+k*10+j));

}



}
}

}
void display(int *m,int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d ",*(m+i*10+j));
}
printf("\n");
}

}

 

6./*WAP that takes three variables(a,b,c) and rotates stored such that value of 'a' goes to b ,'b' to 'c' and 'c' to 'a'.Use pointers for rotation.*/

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

 

void main()
{
int a,b,c,*pa,*pb,*pc,temp;
pa=&a;
pb=&b;
pc=&c;
printf("Enter the A :\n");
scanf("%d",&a);
printf("Enter the B :\n");
scanf("%d",&b);
printf("Enter the C :\n");
scanf("%d",&c);
temp=*pc;
*pc=*pb;
*pb=*pa;
*pa=temp;
printf("\nThe rotated Value are :\nA = %d\nB = %d\nC = %d\n",a,b,c);


getch();

}

7./*WAP that will read marks of one subject for 24 students.pass these numbers to using pointer to a fuction and return their average marki , In the calling function, Display the averave marks*/

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

float average(float *n);

void main()
{
int i;
float mark[24],avg,*mp;
mp=&mark[0];
for(i=0;i<24;i++)
{
printf("\nEnter the mark of the student %d\n",i+1);
scanf("%f",&mark[i]);
}
avg=average(mp);
printf("The average mark is %0.2f",avg);
getch();
}

float average(float *n)
{
int i;
float sum=0;
for(i=0;i<24;i++)
{
sum=*(n+i)+sum;
}
return (sum/24);
}

 

8./*WAP to read a line of characters,Now pass this to a function that finds the number of vowels,consonants,digits,white spaces(space and tab character) and other characters in the line. Your function must return these numbers to the calling function at once(use pointer).In the calling fuction,display those numbers.*/

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

void count(char *,int*,int*,int*,int*,int*,int);

void main()
{
char line[50],*pl;

int l,cv=0,cc=0,cd=0,cs=0,co=0,*pcv,*pcc,*pcd,*pcs,*pco;
pl=&line[0];
pcv=&cv;
pcc=&cc;
pcd=&cd;
pcs=&cs;

pco=&co;

printf("Enter the Sentence\n");
gets(line);
l=strlen(line);

count(pl,pcv,pcc,pcd,pcs,pco,l);
printf("Numbers of\nvowels = %d\nconsonants = %d\ndigits = %d\nspaces = %d\nothers = %d\n",cv,cc,cd,cs,co);
getch();

}
void count(char *pl,int *pv,int *pc,int *pd,int *ps,int *po,int l)
{
int i;

for(i=0;i<l;i++)
{
if(isalnum(*(pl+i))==0)
{
if(isspace(*(pl+i))==0)
(*po)++;
else
(*ps)++;
}
else
{
if(isalpha(*(pl+i))==0)
{
(*pd)++;
}
else
{
if(((*(pl+i))=='a')||((*(pl+i))=='e')||((*(pl+i))=='i')||((*(pl+i))=='o')||((*(pl+i))=='u'))
(*pv)++;
else
(*pc)++;
}
}
}

}

 

 

9./*WAP that asks the user to enter number of students.Once the number is enterd allocate just enough storage space to store marks of one subject for the number of students entered by nuser.Read the data and display them.After display free the reserved memory space*/

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

 

void main()
{
int i,n;
float *pm;

printf("Enter the Number of student\t");
scanf("%d",&n);
pm=(float*)malloc(n*sizeof(int));
if(pm==NULL)
{
printf("\nMemory allocation failed\n");
exit(1);
}
for(i=0;i<n;i++)
{
printf("\nEnter the marks secured by student %d:\t",i+1);
scanf("%f",pm+i);
}
for(i=0;i<n;i++)
{
printf("\nEnter the marks secured by student %d is %0.2f",i+1,*(pm+i));

}
free(pm);
getch();
}

10./*WAP that dynamically allocates three different string and pass them to a funtion where previous two string are reversed and
then merged on the character basis to form the third string. Display the resultant string in the main function. You not allowed to
use string function*/

 

11./*Check whether dynamically allocated string entered by user is a palindrome or not display a proper message.*/

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

 

void main()
{
int n=0,i;
char ch,*ps1,*rev;

 

ps1=(char *)malloc((n+1)*sizeof(char));

if(ps1==NULL)
{
printf("\nMemory allocation failed\n");
exit(1);
}
printf("Enter the first string\n");
while(ch!=13)
{
ch=getche();
*(ps1+n)=ch;
n++;
ps1=(char *)realloc(ps1,(n+1)*sizeof(char));
if(ps1==NULL)
exit(1);

}
*(ps1+(n-1))='\0';
rev=(char *)malloc(n*sizeof(char));
if(rev==NULL)
{
printf("\nMemory allocation failed\n");
exit(1);
}
for(i=0;i<n-1;i++)
{
*(rev+i)=*(ps1+(n-2-i));
}
*(rev+i)='\0';
if (strcmpi(rev,ps1)==0)
printf("\nGiven string is Palindrome\n");
else
printf("\nGiven string is Not Palindrome\n");

getch();

}

12./*Write a program to find the frequency of characters in the entered string*/

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

void main()
{
char str[25];
int l,i,j,k,count=1;
printf("Enter the string\n");
gets(str);
l=strlen(str);
for(i=0;i<l;i++)
{
count=1;
for(j=i+1;j<l;j++)
{
if(str[i]==str[j])
{
count++;
for(k=j;k<l;k++)
{
str[k]=str[k+1];
}
j--;
l--;

}


}
printf("number of %c in given string is %d\n",str[i],count);

}
}

 

13./*Write a program that converts the hexadecimal numbers in equivalent decimal number and vice versa*/

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

void main()
{
int i,j,n,r,dec=0,hex=0,k;

printf("Enter the Hexadecimal no : \n");
scanf("%x",&n);
j=n;
i=0;
while(n!=0)
{
r=n%16;
dec=dec+r*pow(16,i);
n=n/16;
i++;


}
printf("The decimal no of %x is %d\n",j,dec);


printf("\n\nEnter the decimal value to get equivalent Hexadecimal\n");
scanf("%d",&n);
k=n;
i=0;
while(n!=0)
{
r=n%10;
hex=hex+r*pow(10,i);
n=n/10;
i++;
}
printf("Enter the Hexadecimal value of Decimal %d is %x\n",k,hex);
getch();

}