Posts

Showing posts from February, 2016

C Program to Create Employee Record and Update it

    /*      * C Program to Create Employee Record and Update it      */     #include <stdio.h>     #include <stdlib.h>     #include <string.h>     #define size 200      struct emp     {         int id;         char *name;     }*emp1, *emp3;          void display();     void create();     void update();          FILE *fp, *fp1;     int count = 0;          void main(int argc, char **argv)     {         int i, n, ch;             printf("1] Create a Record\n");      ...

C Program to sort numbers using counting sort and save the o/p in a file using FILE handling

/********************************************************************* * Program to sort numbers using counting sort and save * the o/p in a file using FILE handling **********************************************************************/ #include<stdio.h> #include<stdlib.h> #define MAXSIZE 500 void selection(int elements[], int maxsize); int elements[MAXSIZE],maxsize; void main() { int i; FILE *f; printf("\nHow many elements you want to sort: "); scanf("%d",&maxsize); printf("\nEnter the values one by one: "); for (i = 0; i < maxsize; i++) { printf ("\nEnter element %i :",i); scanf("%d",&elements[i]); } f=fopen("a.txt","w"); if(f==NULL) { printf("\nUnable to write in to the file\n"); exit(1); } //fprintf(f,"\nArray before sorting:\n"); //for (i = 0; i < maxsize; i++) //fprintf(f,"[%i], ",elements[i]); //fprintf (f,"\n"); selection(elements,maxsize); /...

C program to Add Two Complex Number

//C program to Add Two Complex Number using structures #include <stdio.h> typedef struct complex{     float real;     float imag; }complex; complex add(complex n1,complex n2); int main(){     complex n1,n2,temp;     printf("For 1st complex number \n");     printf("Enter real and imaginary respectively:\n");     scanf("%f%f",&n1.real,&n1.imag);     printf("\nFor 2nd complex number \n");     printf("Enter real and imaginary respectively:\n");     scanf("%f%f",&n2.real,&n2.imag);     temp=add(n1,n2);     printf("Sum=%.1f+%.1fi",temp.real,temp.imag);     return 0; } complex add(complex n1,complex n2){       complex temp;       temp.real=n1.real+n2.real;       temp.imag=n1.imag+n2.imag;       r...

Write a C program to write all the members of an array of strcures to a file using fwrite(). Read the array from the file and display on the screen.

//Write a C program to write all the members of an array of strcures to a file //using fwrite(). Read the array from the file and display on the screen. #include <stdio.h> struct s { char name[50]; int height; }; int main(){     struct s a[5],b[5];       FILE *fptr;     int i;     fptr=fopen("file.txt","wb");     for(i=0;i<5;++i)     {         fflush(stdin);         printf("Enter name: ");         gets(a[i].name);         printf("Enter height: ");         scanf("%d",&a[i].height);     }     fwrite(a,sizeof(a),1,fptr);     fclose(fptr);     fptr=fopen("file.txt","rb");     fread(b,sizeof(b),1,fptr);  ...

C program to read name and marks of n number of students from user and store them in a file. If the file previously exits, add the information of n students.

//Write a C program to read name and marks of n number of students from //user and store them in a file. If the file previously exits, add the //information of n students. #include <stdio.h> int main(){    char name[50];    int marks,i,n;    printf("Enter number of students: ");    scanf("%d",&n);    FILE *fptr;    fptr=(fopen("C:\\student.txt","a"));    if(fptr==NULL){        printf("Error!");       // exit(1);    }    for(i=0;i<n;++i)    {       printf("For student%d\nEnter name: ",i+1);       scanf("%s",name);       printf("Enter marks: ");       scanf("%d",&marks);       fprintf(fptr,"\nName: %s \nMarks=%d \n",name,marks);    }    fclose(fptr);    return 0; } ...

Write a C program to read name and marks of n number of students from user and store them in a file.

//Write a C program to read name and marks of n number of students from //user and store them in a file #include <stdio.h> int main(){    char name[50];    int marks,i,n;    printf("Enter number of students: ");    scanf("%d",&n);    FILE *fptr;    fptr=(fopen("C:\\student.txt","w"));    if(fptr==NULL){        printf("Error!");        //exit(1);    }    for(i=0;i<n;++i)    {       printf("For student%d\nEnter name: ",i+1);       scanf("%s",name);       printf("Enter marks: ");       scanf("%d",&marks);       fprintf(fptr,"\nName: %s \nMarks=%d \n",name,marks);    }    fclose(fptr);    return 0; }

Write the c program to calculate the sum of element of lower triangle of nXn matrix

//Write the c program to calculate the sum of element of lower triangle of //nXn matrix #include<stdio.h> #include<conio.h> void main() { int a[10][10],r,c; int i=0,j=0,sum=0; clrscr(); printf("\n enter the r and c"); scanf("%d%d",&r,&c); printf("\n enter the array\n"); for(i=0;i<r;i++) { for(j=0;j<c;j++) { scanf("%d",&a[i][j]); } } printf("\n enter the array\n"); for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("\t%d",a[i][j]); } printf("\n"); } printf("\n sum of lower triangle\n"); for(i=0;i<r;i++) { for(j=0;j<c;j++) { if(i>=j) sum=sum+a[i][j]; } } printf("\n sum of lower tringle=%d",sum); getch(); }

C Program to find matrix addition, subtraction, multiplication, transpose and symmetric operations in C Programming

//Code for Program to find matrix addition, subtraction, multiplication, //transpose and symmetric operations in C Programming  # include<stdio.h>        void display(int [][3]);        void main()        {            int c;            void func1();            void func2();            void func3();            void func4();            void func5();                      printf("\n- : Matrix Manipulation Functions (for 3 X 3 Matrix) : -");            pr...

PROGRAM TO PRINT LOWER TRIANGULAR MATRIX

//PROGRAM TO PRINT LOWER TRIANGULAR MATRIX #include<stdio.h> void main() { int m,n,i,j,a[10][10]; printf("Enter the order of a square matrix: "); scanf("%d%d",&m,&n); if(m==n) { printf("Enter %d elements in the matrix:\n",m*n); for(i=0;i<m;i++) { for(j=0;j<n;j++) scanf("%d",&a[i][j]); } printf("You have entered the following matrix:\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) printf("%4d",a[i][j]); printf("\n"); } printf("Lower triangular matrix for the given matrix is:\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(i<j) a[i][j]=0; printf("%4d",a[i][j]); } printf("\n"); } } else printf("Matrix should be a square matrix,So enter a valid order"); }