Copying The Elements of One Character Array To Another: Nivetha
Copying The Elements of One Character Array To Another: Nivetha
COPYING THE ELEMENTS OF ONE CHARACTER ARRAY TO ANOTHER #include<stdio.h> void copy(char a[10], char b[10],int n) { int i; for(i=0;i<n;i++) b[i]=a[i]; } main() { char a[10],b[10]; int i,n; printf("enter the number of elements"); scanf("%d",&n); printf("\n n=%d\n",n); printf("enter the elements of A\n"); for(i=0;i<n;i++) { getchar(); a[i]=getchar(); } copy(a,b,n); printf("the elements of B are :\n"); for(i=0;i<n;i++) printf("\n%c\n",b[i]); } OUTPUT: nivetha@ubuntu:~$ ./a.out enter the number of elements 3 enter the elements of A a s d the elements of B are a s d
NIVETHA MATRIX ADDITION AND SUBRACTION USING FUNCTIONS #include<stdio.h> int a[10][10],b[10][10],c[10][10],i,j,r1,r2,c1,c2; matadd() { for(i=0;i<r1;i++) for(j=0;j<c1;j++) c[i][j]=a[i][j]+b[i][j]; printf("\nResultant C matrix after addition is \n"); for(i=0;i<r1;i++) { printf("\n"); for(j=0;j<c1;j++) printf("%3d", c[i][j]); printf(""); } } matsub() { for(i=0;i<r1;i++) for(j=0;j<c1;j++) c[i][j]=a[i][j]-b[i][j]; printf("\nResultant C matrix after subtraction is \n"); for(i=0;i<r1;i++) { printf("\n"); for(j=0;j<c1;j++) printf("%3d", c[i][j]); printf(""); } } main() { printf("\nEnter the number of rows and columns of A"); scanf("%d%d",&r1,&c1); printf("\nEnter the number of rows and columns of B"); scanf("%d%d",&r2,&c2); printf("\nEnter the elements of matrix A"); for(i=0;i<r1;i++) { for(j=0;j<c1;j++) { scanf("%d",&a[i][j]); } } printf("\nEnter the elements of matrix B");
for(i=0;i<r2;i++) { for(j=0;j<c2;j++) { scanf("%d",&b[i][j]); } } if(r1==r2 && c1==c2) { matadd(); matsub(); } else printf("matrix addition or subtraction cannot be done"); } OUTPUT: nivetha@ubuntu:~$ ./a.out Enter the number of rows and columns of A 33 Enter the number of rows and columns of B 33 Enter the elements of matrix A 1 1 1 1 1 1 1 1 1 Enter the elements of matrix B 333 333 333 Resultant C matrix after addition is 444 444 444 Resultant C matrix after subtraction is 222 222 222
NIVETHA
MULTIPLICATION AND DIVISION USING FUNCTIONS #include<stdio.h> float mult(float a,float b) { return a*b; } float div(float a,float b) { return a/b; } int main() { float c,d; printf("Enter 2 values"); scanf("%f%f",&c,&d); printf("\nThe multiplication of the 2 nos is:%f",mult(c,d)); printf("\nThe division of the 2 nos is:%f",div(c,d)); } OUTPUT: nivetha@ubuntu:~$ ./a.out Enter 2 values 5.5 6.9 The multiplication of the 2 nos is: 37.95 The division of the 2 nos is: 0.7971014492754