Principle of Electronics by V.K. Metha Book Free Download
To download click on the download icon..
Welcome to Rm official Blog
A unique, educational and most informative sub-domain
Thursday, May 10, 2018
Sunday, April 15, 2018
Problem Solve Chapter 11(Pointer) || ANSI C E. BALAGURUSWAMY
Chapter 11(Pointer)
ANSI C E. BALAGURUSWAMY
Problem No: 01:
#include <stdio.h>
#define LIMIT 10
void reverseInt(int*);
void dispInt(int*);
int main()
{
int p[LIMIT],i;
printf("Enter %d Numbers \n",LIMIT);
for(i=0;i<LIMIT;i++)
scanf("%d",p+i);
printf("Current Order: \n");
dispInt(p);
reverseInt(p);
printf("Reverse Order: \n");
dispInt(p);
return 0;
}
void reverseInt(int* p)
{
int i;
for(i=0;i<(LIMIT/2);i++)
{
int temp = *(p+i);
*(p+i) = *(p + (LIMIT-i-1));
*(p + (LIMIT-i-1)) = temp;
}
}
void dispInt(int* p)
{
int i;
for(i=0;i<LIMIT;i++)
printf("%d ",*(p+i));
printf("\n");
}
Problem No: 02:
#include <stdio.h>
#include <math.h>
#define A *(a)
#define B *(a+1)
#define C *(a+2)
void
calcRoot(int*,float*);
void getValue(int* a)
{
printf("Enter The Coeff. A B C: ");
scanf("%d %d %d",a,a+1,a+2);
}
int main()
{
int coeff[3];
float roots[2];
getValue(coeff);
calcRoot(coeff,roots);
printf("Roots are: %.2f %.2f
\n",*(roots),*(roots+1));
return 0;
}
void calcRoot(int*
a,float* roots)
{
*roots = (-(B) + (sqrt(B*B - 4*A*C)) )/(float)(2 * A);
*(roots+1) = (-(B) - (sqrt(B*B - 4*A*C)) )/(float)(2 *
A);
}
Problem No: 03:
#include <stdio.h>
#define LIMIT 10
void addValue(int*,int);
void disp(int*,int);
int main()
{
int arr[LIMIT+1] = {1,2,3,5,6,8,10,28,45,100};
int num;
printf("Before Insertion \n");
disp(arr,LIMIT);
printf("Enter A Value To Insert: ");
scanf("%d",&num);
printf("After Insertion \n");
addValue(arr,num);
disp(arr,LIMIT+1);
return 0;
}
void addValue(int*
arr,int key)
{
int i=0;
while(*(arr+i) < key) i++;
int temp = *(arr+i);
*(arr+i) = key;
while(i++ <= LIMIT)
{
key = *(arr+i);
*(arr+i) = temp;
temp = key;
}
}
void disp(int* a,int len)
{
int i=0;
for(i=0;i<len;i++)
printf("%d ",*(a+i));
printf("\n");
}
Problem No: 04:
#include <stdio.h>
#define LIMIT 3
void inputMat(int
a[][3]);
void addMat(int
a[][3],int b[][3],int c[][3]);
void printMat(int
a[][3]);
int main()
{
int i,j;
int
matA[LIMIT][LIMIT],matB[LIMIT][LIMIT],matC[LIMIT][LIMIT];
printf("Enter The Value of Matrix A (%dx%d)
\n",LIMIT,LIMIT);
inputMat(matA);
printf("Enter The Value of Matrix B (%dx%d)
\n",LIMIT,LIMIT);
inputMat(matB);
addMat(matA,matB,matC);
printf("ANS: \n");
printMat(matC);
return 0;
}
void addMat(int
a[][LIMIT],int b[][LIMIT],int c[][LIMIT])
{
int i,j;
for(i=0;i<LIMIT;i++)
for(j=0;j<LIMIT;j++)
*(*(c+i)+j) =
*(*(a+i)+j) + *(*(b+i)+j);
}
void inputMat(int
matA[][LIMIT])
{
int i,j;
for(i=0;i<LIMIT;i++)
for(j=0;j<LIMIT;j++)
scanf("%d",(*(matA+i)+j));
}
void printMat(int
matA[][LIMIT])
{
int i,j;
for(i=0;i<LIMIT;i++)
{
for(j=0;j<LIMIT;j++)
printf("%d
",*(*(matA+i)+j));
printf("\n");
}
}
Problem No: 05:
#include <stdio.h>
#include <string.h>
char*
makeStr(char*,char);
int main()
{
char text[100],ch;
printf("Enter The String: ");
scanf("%s",text);
getchar();
printf("Enter the Character to Delete: ");
ch = getchar();
makeStr(text,ch);
printf("Ans: \n%s \n",text);
return 0;
}
char* makeStr(char*
text,char key)
{
char temp[100];
int j,i = 0;
int len = strlen(text);
for(j=0,i=0;i<=len;i++)
{
if(*(text+i) != key)
{
*(temp+j) = *(text+i);
j++;
}
else
continue;
}
*(temp+j) = '\0';
strncpy(text,temp,j);
return text;
}
Problem No: 06:
#include <stdio.h>
char* day_name(int);
int main()
{
int num;
printf("Enter A Number: ");
scanf("%d",&num);
char* ans = day_name(num);
printf("%s\n",ans);
return 0;
}
char* day_name(int n)
{
static
char name[8][20] =
{"Monday","Tuesday","Wednesday","Thrusday","Friday", "Saturday","Sunday","INVALID"};
if(n < 8)
return (*(name+n-1)+0);
return (*(name+7)+0);
}
Problem No: 07:
#include <stdio.h>
#include <string.h>
#define LIMIT 10
void sortName(char
name[][20]);
void dispName(char
name[][20]);
int main()
{
int i;
char name[LIMIT][20];
printf("Enter %d Names \n",LIMIT);
for(i=0;i<LIMIT;i++)
scanf("%s",*(name+i)+0);
sortName(name);
printf(" \nSorted Names \n");
dispName(name);
return 0;
}
void sortName(char
name[][20])
{
int i,j;
for(i=0;i<LIMIT;i++)
{
for(j=0;j<LIMIT;j++)
{
if(strcmp(*(name+i),*(name+j))
< 0)
{
char temp[20];
strcpy(temp,*(name+i));
strcpy(*(name+i),*(name+j));
strcpy(*(name+j),temp);
}
}
}
}
void dispName(char
name[][20])
{
int i;
for(i=0;i<LIMIT;i++)
printf("%s \n",*(name+i));
}
Problem No: 08:
#include <stdio.h>
#include <string.h>
#define LIMIT 10
void sortName(char
name[][20]);
void dispName(char
name[][20]);
int main()
{
int i;
char name[LIMIT][20];
printf("Enter %d Names \n",LIMIT);
for(i=0;i<LIMIT;i++)
scanf("%s",*(name+i)+0);
sortName(name);
printf(" \nSorted Names \n");
dispName(name);
return 0;
}
void sortName(char
name[][20])
{
int i,j;
for(i=0;i<LIMIT;i++)
{
for(j=0;j<LIMIT;j++)
{
if(strcmp(*(name+i),*(name+j))
< 0)
{
char temp[20];
strcpy(temp,*(name+i));
strcpy(*(name+i),*(name+j));
strcpy(*(name+j),temp);
}
}
}
}
void dispName(char
name[][20])
{
int i;
for(i=0;i<LIMIT;i++)
printf("%s
\n",*(name+i));
}
Problem No: 09:
#include <stdio.h>
#define LIMIT 10
void reverseInt(int*);
void dispInt(int*);
int main()
{
int p[LIMIT],i;
printf("Enter %d Numbers \n",LIMIT);
for(i=0;i<LIMIT;i++)
scanf("%d",p+i);
printf("Current Order: \n");
dispInt(p);
reverseInt(p);
printf("Reverse Order: \n");
dispInt(p);
return 0;
}
void reverseInt(int* p)
{
int i;
for(i=0;i<(LIMIT/2);i++)
{
int temp = *(p+i);
*(p+i) = *(p + (LIMIT-i-1));
*(p + (LIMIT-i-1)) = temp;
}
}
void dispInt(int* p)
{
int i;
for(i=0;i<LIMIT;i++)
printf("%d ",*(p+i));
printf("\n");
}
Problem No: 10:
#include <stdio.h>
#define LIMIT 10
void comp(int*,int*);
int main()
{
int arr1[LIMIT] = {1,2,3,4,5,6,7,8,9};
int arr2[LIMIT] = {1,2,3,4,5,6,7,8,9};
int arr3[LIMIT] = {1,2,3,4,5,7,9,8,6};
printf("Comparing 1 and 2 \n");
comp(arr1,arr2);
printf("Comparing 2 and 3 \n");
comp(arr2,arr3);
return 0;
}
void comp(int* a,int* b)
{
int i;
for(i=0;i<LIMIT;i++)
{
if(*(a+i) == *(b+i))
continue;
else
{
printf("DIFF.\n");
return;
}
}
printf("SAME!!! \n");
}
- Click Download button to download this File as pdf.
Go ahead by honesty--->Rm
Subscribe to:
Posts (Atom)
Principle of Electronics by V.K. Metha Book Free Download
Principle of Electronics by V.K. Metha Book Free Download To download click on the download icon.. Download
-
Review Question’s Answer Chapter No-03(Operators and Expressions) =======================================================...
-
Chapter 11(Pointer) ANSI C E. BALAGURUSWAMY Problem No: 01: #include <stdio.h> #define LIMIT 10 void reverseInt(int*); ...
-
Review Question’s Answer Chapter No-01(Overview of C) ========================================================================...