c progamming 2022 Makeup Solution
2) Write a program to check if two matrices are equal or not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#include<stdio.h> int main(){ int a[100][100],b[100][100]; int r1,c1,r2,c2,i,j,flag=0; printf(“enter rows and columns of first and second matrix\n”); scanf(“%d%d%d%d”,&r1,&c1,&r2,&c2); printf(“enter elements of first matrix”); for(i=0;i<r1;i++){ for(j=0;j<c1;j++){ scanf(“%d”,&a[i][j]); } } printf(“enter elements of second matrix”); for(i=0;i<r1;i++){ for(j=0;j<c1;j++){ scanf(“%d”,&b[i][j]); } } if((r1 == r2) && (c1 == c2)){ for(i=0;i<r1;i++){ for(j=0;j<c1;j++){ if(a[i][j] ! == b[i][j]){ flag = 1; } } } if(flag == 1) printf("they are not equal"); else printf("they are equal"); } else{ printf("they are not equal"); } } |
4)Write a program using pointer to input 10 numbers and store it in array and sort in ascending order using pointer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
int main(){ int array[100],n,i,j; int *ptr; printf("enter size of array\n"); scanf("%d",&n); printf("enter %d elements ",n); for(i=0;i<n;i++){ scanf("%d",&a[i]); } ptr = &a; for(i=0;i<n;i++){ for(j=i+1;j<n;j++){ if(*(ptr+i) > *(ptr+j)){ temp = *(ptr + i); *(ptr + i) = *(ptr + j); *(ptr + j) = temp; } } } printf("the array in sorted order is :"); for(i=0;i<n;i++){ printf("%d",a[i]); } } |
5) write a program that reads 2 numbers from user and calculate sum and write it in a file name “sum.dat” […]
Continue Reading