Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Develop a C program to find the transpose of a given matrix.

clrscr(); printf("\n enter the m\n"); scanf("%d",&m); #include<stdio.h> printf("\n enter the n\n"); int main(){ scanf("%d",&n); int a[3][3],b[3][3],c[3][3],i,j; printf("\n enter the matrix A elements "); printf("Enter the First matrix->"); for(i=0;i<m;i++) for(i=0;i<3;i++) for(j=0;j<3;j++) { scanf("%d",&a[i][j]); for(j=0;j<n;j++) printf("\nEnter the Second matrix->"); { for(i=0;i<3;i++) scanf("%d",&a[i][j]); for(j=0;j<3;j++) } scanf("%d",&b[i][j]); } printf("\nThe First matrix is\n"); printf("\n the matrix A elements "); for(i=0;i<3;i++){ printf("\n"); for(i=0;i<m;i++) for(j=0;j<3;j++) { printf("%d\t",a[i][j]); for(j=0;j<n;j++) } { printf("\nThe Second matrix is\n"); printf("%d",a[i][j]); for(i=0;i<3;i++){ } printf("\n"); for(j=0;j<3;j++) printf("\n"); printf("%d\t",b[i][j]); } } printf("\n enter the matrix B elements "); for(i=0;i<3;i++) for(i=0;i<m;i++) for(j=0;j<3;j++) { c[i][j]=a[i][j]+b[i][j]; for(j=0;j<n;j++) printf("\nThe Addition of two matrix is\n"); { for(i=0;i<3;i++){ printf("\n"); scanf("%d",&b[i][j]); for(j=0;j<3;j++) } printf("%d\t",c[i][j]); } } printf("\n the matrix B elements "); return 0; for(i=0;i<m;i++) } { Write a C program to perform matrix multiplication for(j=0;j<n;j++) #include<stdio.h> { #include<conio.h> printf("%d",b[i][j]); #define ROW 20 } #define COL 20 printf("\n"); void main() } { for(i=0;i<m;i++) int { a[ROW][COL],b[ROW][COL],c[ROW][CO for(j=0;j<n;j++) L]; { int i=0,j=0,k,sum=0,m,n; sum=0;

for(k=0;k<n;k++) sum=sum+a[i][k]*b[k][j]; c[i][j]=sum; } } printf("\n the product of matrices is as follow \n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("\t%d",c[i][j]); } printf("\n"); } getch(); }

printf("\n"); for next line character */ }

/* '\n' used

for(i=0 ; i<3 ; i++) { for(j=0 ; j<2 ; j++) { B[i][j] = A[j][i]; } }

printf(" After Transpose\n"); for(i=0 ; i<3 ; i++) { for(j=0 ; j<2 ; j++) { printf("%d\t" , B[i][j] ); } printf("\n"); } Write a C program to compute the transpose of a matrix getch(); } Write a C program to find the greatest of N numbers using arrays #include<stdio.h> void main() { int maximum(int a[],int n); int max,i,n; int a[50]; printf("Enter n number:"); scanf("%d",&n); printf("Enter the numbers:"); for(i=0;i<n;i++) scanf("%d",&a[i]); max=maximum(a,n); printf("The largest number is %d",max); } int maximum(int a[],int n) { int i,m=0; for(i=0;i<n;i++) { if(a[i]>m) m=a[i]; } return m;

#include<stdio.h> #include<conio.h> void main() { int A[2][3] , B[3][2]; int i, j; /* 'i' used for rows and 'j' used for columns */ clrscr(); printf(" Enter the elements of A\n"); for(i=0 ; i<2 ; i++) { for(j=0 ; j<3 ; j++) { scanf("%d" , &A[i][j] ); } } printf(" Matrix is\n"); for(i=0 ; i<2 ; i++) { for(j=0 ; j<3 ; j++) { printf("%d\t" , A[i][j] ); used for Tab */ }

/* '\t'

} Write a C program to sort N numbers. Use pointers #include <stdio.h> #include <conio.h> void main(){ int *arr,i,j,tmp,n; clrscr(); printf("Enter how many data you want to sort : "); scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",arr+i); for(i=0;i<n;i++) { for(j=i+1;j<n;j++){ if( *(arr+i) > *(arr+j)){ tmp = *(arr+i); *(arr+i) = *(arr+j); *(arr+j) = tmp; } } } printf("\n\nAfter Sort\n"); for(i=0;i<n;i++) printf("%d\n",*(arr+i)); getch(); } Write a C program using pointers to read in an array of integers and print its elements in reverse order #include #include #include int main() { int *ptr,i,n; clrscr(); printf(Enter the no of elements:); scanf(%d,&n); ptr=(int *)malloc(sizeof(int)*n); if(ptr==NULL) {

printf(Not enough memory); exit(1); } for(i=0; i<n; i++) { printf(Enter %d element : ,i+1); scanf(%d,&ptr[i]); } printf(Array in original order\n); for(i=0; i<n; i++) { printf(%d\n,ptr[i]); } printf(Array in reverse order\n); for(i=n-1; i>=0; i) { printf(%d\n,ptr[i]); } getch(); return 0; } Develop a C function that will scan a character string passed as an argument and convert all lower-case characters to their upper-case equivalents. #include #include void upper(char[]); int main() { char str[20]; clrscr(); printf(Enter string : ); gets(str); upper(str); getch(); return 0; } void upper(char str[20]) { int i; printf(%s in upper case is ,str); for(i=0;str[i];i++)

{ if(str[i]>96 && str[i]<123) str[i]-=32; } printf(%s,str); } Develop a C program to copy the contents of one file into another #include<stdio.h> #include<conio.h> void main() { FILE *fp1,*fp2; char ch,fname1[20],fname2[20]; printf("\n enter sourse file name"); gets(fname1); printf("\n enter sourse file name"); gets(fname2); fp1=fopen(fname1,"r"); fp2=fopen(fname2,"w"); if(fp1==NULL||fp2==NULL) { printf("unable to open"); exit(0); } do { ch=fgetc(fp1); fputc(ch,fp2); } while(ch!=EOF); fcloseall(); getch(); } Develop a C program to print the number of vowels in a given paragraph #include<stdio.h> #include<conio.h> void main() { char str[50];

int vowels = 0, i = 0; clrscr(); printf(\n\n\t ENTER A STRING: ); gets(str); while(str[i] != \0) { if(str[i]==A || str[i]==a || str[i]==E || str[i]==e || str[i]==I || str[i]==i || str[i]==O || str[i]==o || str[i]==U || str[i]==u') vowels++; i++; } printf(\n\n\t THE TOTAL NUMBER OF VOWELS IS: %d, vowels); getch(); } Write a C program to sort N numbers. Use functions #include<stdio.h> #include<conio.h> void sort(int*,int); void main() { int a[10]; int i,n; clrscr(); printf("how many numbers u want to enter in 1st array : "); scanf("%d",&n); printf("enter numbers :\n"); for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,n); for(i=0;i<n;i++) printf("%d",a[i]); getch(); } void sort(int *a,int m) { int i,j,temp; for(i=0;i<m-1;i++) { for(j=i+1;j<m;j++) {

if(a[i]>a[j]) { temp=a[j]; a[j]=a[i]; a[i]=temp; } } } } Write a C program to sort N names alphabetically. Use pointers. #include <stdio.h> #include <conio.h> #include <math.h> #include <alloc.h> void main() { char *a[10],dum[10],s; int i,k,j,n; clrscr(); printf("enter the no of std...."); scanf("%d",&n); printf("enter the name of students "); for(k=0;k<n;k++) scanf("%s",a[k]); for(i=1;i<n;i++) { for(j=1;j<n-i;j++) {if(strcmp(a[j-1],a[j])>0) {strcpy(*dum,*a[j-1]); strcpy(*a[j-1],*a[j]); strcpy(*a[j],*dum); } } } for(i=0;i<n;i++) printf("%s",a[i]); getch(); } Develop a C program to find the transpose of a given matrix. Use function #include<stdio.h> #include<conio.h> #define MAX 3 void input_mat(int [MAX][MAX], int, int); void show_mat(int [MAX][MAX], int, int); void trns_mat(int [MAX][MAX],int [MAX][MAX],int,int); int main()

{ int x[MAX][MAX],z[MAX][MAX]; int row,col; printf("Enter no. of rows and columns : "); scanf("%d%d",&row, &col); printf("Enter values of %d X %d matrix :\n",row,col); input_mat(x,row,col); printf("\nYour entered matrix is : \n"); show_mat(x,row,col); trns_mat(x,z,row,col); printf("\nTranspose of entered matrix is :\n"); show_mat(z,row,col); return 0; } void input_mat(int matA[MAX][MAX], int r, int c) { int i,j; for(i=0; i<r; i++) { for(j=0;j<c; j++) scanf("%d",&matA[i][j]); } }

void trns_mat(int matA[MAX][MAX],int matT[MAX][MAX],int r,int c) { int i,j; for(i=0; i<r; i++) { for(j=0;j<c; j++) matT[j][i] = matA[i][j]; } }

void show_mat(int mat[MAX][MAX], int r, int c) { int i,j; for(i=0; i<r; i++) { for(j=0;j<c; j++) printf(" %d",mat[i][j]); printf("\n"); } }

Develop a C program to compute the roots of a quadratic equation #include <stdio.h> #include <conio.h> #include<math.h> void main() { int a,b,c,d;/* d is a discriminent */ float x1,x2;/* here x1 is root1 and x2 is root2 */ printf("enter the value of a,b & c\n"); scanf("%d%d%d",&a,&b,&c); d=b*b-4*a*c; if(d==0) { printf("Both roots are equal\n"); x1=-b/(2*a); x2=x1; printf("First Root x1= %f\n",x1); printf("Second Root x2= %f\n",x2); } else if(d>0) { printf("Both roots are real and diff-2\n"); x1=(-b+sqrt(d))/(2*a); x2=(-b-sqrt(d))/(2*a); printf("First Root x1= %f\n",x1); printf("Second Root x2= %f\n",x2); } else printf("Root are imeginary\n No Solution \n"); Write a C program to perform matrix addition. Use functions. #include<stdio.h> #include<conio.h> void read_mat(int,int[10][10]); void add_mat(int,int[10][10],int[10][10]); main() { int a[10][10],b[10][10],n; clrscr(); printf("Enter Matrix size:"); scanf("%d",&n); printf("Your choosen %d*%d Matrix:\n",n,n); }

printf("Enter elements into First Matrix:"); read_mat(n,a); printf("Enter elements into Second Matrix:"); read_mat(n,b); printf("Addition of the Matrix is :\n"); add_mat(n,a,b); getch();

/*Function Starts Main follow Me*/ void read_mat(int x,int a[10][10]) { int i,j; for(i=0;i<x;i++) for(j=0;j<x;j++) scanf("%d",&a[i][j]); } void add_mat(int x,int a[10][10],int b[10][10]) { int i,j,c[10][10]; for(i=0;i<x;i++) for(j=0;j<x;j++) c[i][j]=a[i][j]+b[i][j]; for(i=0;i<x;i++) { for(j=0;j<x;j++) printf("%d ",c[i][j]); printf("\n"); } }

You might also like