Posts

Showing posts from March, 2015

Program for accepting values in array and sort them in ascending order.

Program for accepting values in array and sort them in ascending order. /*Program for accepting values in array and sort them in ascending order.*/ #include<stdio.h> #include<conio.h> void main() { int a[5],i,j,t; clrscr(); printf("\nEnter 5 values in array: "); for(i=0;i<=4;i++) { scanf("%d",&a[i]); } printf("\nBefore arranging array values are:"); for(i=0;i<=4;i++) { printf("%d\t",a[i]); } for(i=0;i<=4;i++) { for(j=i+1;j<=4;j++) { if(a[i]>a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; } } } printf("\nAfter arranging in accending order array values are: \n"); for(i=0;i<=4;i++) printf("%d\t",a[i]) ; getch(); }

Program for accepting values in an array and finding greatest and smallest value in that array.

Program for accepting values in an array and finding greatest and smallest value in that array. /*Program for finding greatest and smallest value in an array.*/ #include<stdio.h> #include<conio.h> void main() { int a[5],i,g,s; clrscr(); printf("\nEnter 5 values in array: \n"); for(i=0;i<=4;i++) { scanf("\n%d",&a[i]); } g=s=a[0]; printf("\n Accepted array values are:"); for(i=0;i<=4;i++) { if(g<a[i]) g=a[i]; if(s>a[i]) s=a[i]; printf("%d\t",a[i]); } printf("\n Greatest value is=%d",g); printf("\n\n Smallest value is=%d",s); getch(); }

A Program for accepting values to 2-Dimensional array and finding the sum of all the elements of 2-Dimensional array.

A Program for accepting values to 2-Dimensional array and finding the sum of all the elements of 2-Dimensional array. Just copy and paste the code below and compile and run the program. #include<stdio.h> #include<conio.h> void main() { int a[3][3],i,j,s=0; clrscr(); for(i=0;i<3;i++) { for(j=0;j<3;j++)     {       printf("\nEnter a value:");       scanf("%d",&a[i][j]);     }   } printf("\nYour array\n"); for(i=0;i<3;i++) {   for(j=0;j<3;j++)   {   s=s+a[i][j];   printf("%d\t",a[i][j]);   } } printf("\nSum of array elements=%d",s); getch(); }