You are on page 1of 19


#include<stdio.h> #define max 5 void main() { int a[max]={1,2,3,4,5}; int b[max],i; printf("enter the element of b"); for(i=0;i<max;i++) { scanf("%d",&b[i]); } printf("element of array a:\n"); for(i=0;i<max;i++) printf("%d\t",a[i]); printf("\n element of b:\n"); for(i=0;i<max;i++) printf("%d\t",b[i]); getch(); }

i++) { for(j=0.j<2.&a[i][j]).TWO DIMENTIONAL ARRAY #include<stdio. } getch(). } printf("\n"). printf("\n\n"). } printf("enter number for another row\n").j<2. printf("enter the element of array:"). for(i=0.h> main() { int a[2][2]. } . } printf("the elements are").a[i][j]).i++) { for(j=0.i<2.i<2. for(i=0.j.j++) { scanf("%d".j++) { printf("%d".i.

h> #define max 3 main() { int a[max][max][max].i.i++) for(j=0. printf("number of zeros in given array are%d". printf("enter the elements of array a(3*3*3):\n"). for(i=0.k<max.THREE DIMENTIONAL ARRAY #include<stdio. } .count=0.j.k<max.k++) scanf("%d".i++) for(j=0.j<max.j<max.i<max.k++) if(a[i][j][k]==0) count++.&a[i][j][k]).k.j++) for(k=0. getch().count).i<max.j++) for(k=0. for(i=0.

} printf("sum of the array element are:%d\n". sum=sum+b[i]. } printf("element of array are:\n").i++) { printf("%d".sum).b[i]). for(i=0. printf("enter the element of b"). } .i.i<max.h> #define max 5 void main() { int sum=0. getch().&b[i]).i++) { scanf("%d". int b[max].i<max.SUM OF ARRAY #include<stdio. for(i=0.

} } for(j=size.item.i++) scanf("%d". scanf("%d". for(i=0.i<size.j--) { a[j]=a[j-1]. size++. break.h> void main() { int a[5]. } a[j]=item. } getch(). printf("enter the element in sorted order").i<6.INSERT ARRAY #include<stdio.&a[i]).&item). printf("enter the element to be inserted").i++) { printf("%d".i<size.size=6. } .j>pos. for(i=0.i++) { if(item<a[i]) { pos=i. for(i=0.a[i]).pos.j. printf("array elements are").i.

j++) { a[j]=a[j+1].i++) { if(item==a[i]) { pos=i. printf("enter the item that u want to be deleted").i++) { printf("%d".i<size. for(i=0.a[i]). for(i=0.i<size.h> main() { int a[5].&item).i<6. } .h> #include<conio.i.i++) scanf("%d". printf("array elements are").size=6. for(i=0.j<size-1. } } for(j=pos. printf("enter the element in sorted order"). } size--.DELETE ELEMENT FROM ARRAY #include<stdio. scanf("%d". } getch(). break.&a[i]).j.pos.item.

&n).m.i<n&&j<m.h> #define max 10 main() { int a[max]. } . printf("enter the array of the a:\n"). scanf("%d". getch().c[i]). for(i=0.n.i++) scanf("%d".&a[i]).k=0.c[2*max].MERGING ARRAY #include<stdio. printf("\n enter the size of array b:"). for(i=0. for(i=0.i.&b[i]).&m).j=0. for(i=0.i++) scanf("%d". while(i<n) c[k++]=a[i++]. printf("the array of 3rd merged array c:\n").i<n.k. printf("enter the element of the array b:\n"). else c[k]=b[j++].b[max].j. scanf("%d".i<m.i++) printf("%d". printf("enter the size of the array a"). while(j<m) c[k++]=b[j++].k++) if(a[i]<b[j]) c[k]=a[i++].i<(n+m).

a[i][j]).i++) { printf("\n"). for(i=0.i++) for(j=0. } printf("\n product of two matrix").i<m.i++) for(j=0. for(i=0.j<q. scanf("%d%d".m.PRODUCT OF TWO MATRIX #include<stdio. for(j=0. printf("enter the row & column of first matrix b:").b[max][max].j.j++) { c[i][j]=0.&a[i][j]).k++) c[i][j]=c[i][j]+a[i][k]*b[k][j].k<n.j<n.&b[i][j]).j++) scanf("%d". for(i=0.b[i][j]). } . for(i=0. printf("enter the row & column of first matrix a:").j++) printf("%d".i<p.k.i.i<m.q. printf("enter the elements of a matrix b:\n").h> #define max 10 main() { int a[max][max].&n). for(i=0. printf("matrix a is").j<n.p.i<m.&q). } printf("\n matrix b is:").&p.j<q. for(j=0. for(j=0.i<p.c[i][j]).&m.j<q. if(n==p) { printf("enter the elements of matrix a:\n"). for(k=0. scanf("%d%d".c[max][max].j++) printf("%d".i++) { printf("\n"). printf("%d".j++) scanf("%d".i++) { printf("\n").n.

} getch().} } else { printf("\n matrix are compatible for multiplication"). } .

SEARCHING ELEMENT IN ARRAY #include<stdio. for(i=0. } } else { if(flag==1) printf("element not found %d".arr[i]). printf("enter the element of array\n"). scanf("%d".flag=0.i<max. } } getch().i++) { if(arr[i]==item) { if(flag==0) { s=arr[i].item. printf("element found%d".i<max.arr[i]).i.&arr[i]).h> #define max 5 main() { int arr[5].i++) { scanf("%d". } printf("enter element to search").&item).s. for(i=0. } .

i<5. } for(i=0. } . getch().&a[i]).i++) { if(c<a[i]) { c=a[i]. } } printf("greatest no is%d".i<5. for(i=0.c).i.h> #define max 3 main() { int a[5]. printf("enter any element").GREATEST NUMBER IN AN ARRAY #include<stdio.c=0.i++) { scanf("%d".

b).h> main() { int a=10.CALL BY VALUE #include<stdio. t=x. y=t.a).x). printf("x=%d\n". x=y.y). printf("the value of b is %d". } . getch().b).int y) { int t. printf("y=%d\n". swap(a. printf("the value of a is %d". }swap(int x. int b=20.

&b).int b=20. printf("the value of a is %d". } swap(int *x.b). } . swap(&a. getch().CALL BY REFRENCE #include<stdio. printf("the value of b is %d". *y=t. *x=*y.h> main() { int a=10. t=*x.a).int *y) { int t.

author). printf("enter author's name").author). main() { struct book b1. printf("\n the details of book is").b1. getch().price).b1. } . int pages. printf("enter pages").pages).h> struct book { char author[10].STRUCTURES #include<stdio. scanf("%d".price).b1. printf("enter book price").h> #include<conio. }. printf("\n author name is %s". printf("\n price is %f".pages).&b1. scanf("%s". scanf("%f". float price.&b1.&b1. printf("\n pages are %d".

} . p=&a.POINTERS #include<stdio.&p). int *p. printf("\n the value on address hold by pointer is %d".p).a).h> main() { int a=10. printf("\n the address of a is %d".&a). printf("\n the value of pointer variable is %d". getch(). printf("\n the value of a is %d".

int i.&b1[i].price is %f". } printf("\n\n values are").b1[i].price").i<2.b1[i].i<2.pages.price).i++) { printf("enter the name.pages. printf("\n\n\n").h> struct book { char author[10]. main() { struct book b1[2]. for(i=0. scanf("%s%d%f" { printf("\n\n author name is %s. } . int pages.price).author.b1[i].&b1[i]. }.ARRAY OF STRUCTURE #include<stdio. } getch(). for(i=0.pages are %d. float price.&b1[i].

result).b1.marks). printf("enter the marks and result of student\n\n\n"). }a1.h> struct a { int marks.marks. scanf("%d%s".STRUCTURE WITH IN STRUCTURE #include<stdio. getch().&a1.&a1. printf("\nthe marks of the student is %d". printf("\nthe result of the student is %s". main() { struct b b1. struct b { char result[10].b1.a1.&a1. }b1. } .result).

STRUCTURE WITH IN POINTER #include<stdio. display(eptr).e->salary)."john smith".9500}. eptr=&emp. main() { struct employee emp={101. } . printf("employee salary %d\n".h> struct employee { int emp_no. char emp_name[25]. printf("employee name: %s\n". getch(). int salary. }. } display(struct employee *e) { printf("employee no %d\n".e->emp_name). struct employee *eptr.e->emp_no).

99.j--) { temp=arr[i]. main() { int arr[max]={22. int i. for(i=0.j=max-1.temp.i++) printf("%d\t".}. } void reverse(int arr[]. arr[i]=arr[j]. for(i=0.arr[i]).i<max. printf("the list before reversing :\n").j.101.67.j. arr[j] n) { int i. for(i=0.arr[i]).PASSING ARRAY TO FUNCTIONS #include<stdio. printf("\n the list after reversing:\n").max). } } . reverse(arr.i<max/2.i<max.5.i++) printf("%d\t".int).i++. getch().h> #define max 10 void reverse(int[].73.