Skip to main content

Posts

C Program to add two matrices using pointers.

  #include<stdio.h> main() { int a[5][5],b[5][5],c[5][5],i,j,m,n; printf("\n Enter the Dimension of the Matrix:\n"); scanf("%d%d",&m,&n); printf("\nEnter the Elements of the first matix:"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",(*(a+i)+j)); } } printf("\nEnter the elements of the second matrix:\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",(*(b+i)+j)); } } for(i=0;i<m;i++) { for(j=0;j<n;j++) { *(*(c+i)+j)=*(*(a+i)+j)+ *(*(b+i)+j); } } printf("\nResultantMatrix:\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%5d",*(*(c+i)+j)); } printf("\n"); } getch(); } Output:  Enter the Dimension of the Matrix: 2  2 Enter the Elements of the first matix: 1   2   3   4 Enter the elements of the second matrix: 9   8   7  6 ResultantMatrix:  
Recent posts

C Program to input the name of the branches, total sales of the company into an array of structures

   Program to input  the name of the branches, total sales of the company into an array of structures, display the branch name and sales of branch who had highest sales.   #include<stdio.h> struct branch { char name[25]; long sale; }; main() { struct branch b[100]; int n,i,m; long max; clrscr(); printf("\nEnter the no. of Branches"); scanf("%d",&n); for(i=0;i<n;i++) { printf("\nEnter the details of branch %d",i+1); printf("\nEnter the branch name\n"); scanf("%s",b[i].name); printf("\nEnter the total sales:\n"); scanf("%ld",&b[i].sale); } max=b[0].sale; m=0; for(i=1;i<n;i++) { if(b[i].sale>max) { max=b[i].sale; m=i; } printf("\nBranch with highest Sales:"); printf("\nName:%s",b[i].name); printf("\nSales: %d\n",b[i].sale);       } getch(); }

C Program to create a data file to store student information

  Program to create a data file to store student information Such as Roll. No., name, Class and total marks. Copy those Records to where total marks is more than 400 to another File. Display the contents of both.         #include<stdio.h> main() { FILE *f1,*f2; char ans,name[25],class[8]; int rno,i,tot; clrscr(); f1=fopen("STUD.DAT","w"); do { printf("\nEnter the Roll No.:\n"); scanf("%d",&rno); printf("\nEnter the name\n"); scanf("%s",name); printf("\nEnter the class\n"); scanf("%s",class); printf("\nEnter the Marks:\n"); scanf("%d",&tot); fprintf(f1,"\n%d%s%s%d",rno,name,class,tot); fflush(stdin); printf("\nContinue Input?"); scanf("%c",&ans); }while(ans=='Y'||ans=='y'); fclose(f1); f1=fopen("STUD.DAT","r"); f2=fopen("MARKS.DAT

C Program to create a sequential file containing integer numbers.

  Program to create a sequential file containing integer  numbers. Read these numbers and write all odd numbers into a file ODD, and even numbers into a file EVEN.  Display the contents from each. #include<stdio.h> main() { FILE *f1,*f2,*f3; int n; clrscr(); f1=fopen("NUM.DAT","w"); printf(" Enter series of integers\n"); do { scanf("%d",&n); putw(n,f1); } while(n!=0); fclose(f1); f1=fopen("NUM.DAT","r"); f2=fopen("EVEN.DAT","w"); f3=fopen("ODD.DAT","w"); while((n=getw(f1))!=EOF) { if(n%2==0) putw(n,f2); else putw(n,f3); } fclose(f1); fclose(f2); fclose(f3); printf("\nContents of NUM.DAT"); f1=fopen("NUM.DAT","r"); while((n=getw(f1))!=EOF) printf("%5d",n); fclose(f1); printf("\nContents of EVEN.DAT"); f2=fopen("EVEN.DAT","r"); while((n=getw(f2))!=EOF) printf("%5d",n); fclose(f2);