Skip to main content

Posts

Types of Function in C language return type function (argument) use

 Function use example: 1. Function with no argument (parameters) & no return value: Basic example program addition #include<stdio.h> void add(void); int main() { add(); } void add() { int x,y=56,z=45; x=y+z; printf("ADD=%d",x); } Output are: ADD=101 2. Function with no argument but return type: Here called function is independent and are initialized . The value aren't passed by The calling function .Here the calling function and called function are communicated party with each other.   Basic example program addition #include<stdio.h> int  add(void); int main() { add(); } int add(void) { int x,y=56,z=45; x=y+z; printf("ADD=%d",x); } Output are: ADD=101 3. Function with argument but no return value Here the function have argument so the calling function send date to the called function but called function dose not return value. Here the result obtained by the called function.   Basic example program addition #include<stdio.h> void add(int y,...

Bubble sort descending order

Bubble sort descending order   #include"stdio.h" int main() { int a[100],n,l,k,swap; printf("Enter the of Elements:"); scanf("%d",&n); for(k=0;k<n;k++) { printf("Enter a[%d] :",k); scanf("%d",&a[k]); } printf("Elements are :\n "); for(k=0;k<n;k++) { printf("%d\t",a[k]); } // sorting // for(k=0;k<n;k++) { for(l=0;l<n;l++) { if(a[l]<a[l+1]) { swap = a[l+1]; a[l+1]= a[l]; a[l]=swap; } } } printf("\nDescending order are:\n"); for(k=0;k<n;k++) { printf("%d \t",a[k]); } } Output are: Enter the of Elements:5 Enter a[0] :12 Enter a[1] :987 Enter a[2] :456 Enter a[3] :320 Enter a[4] :72 Elements are :  12     987     456     320     72 Descending order are: 987     456     320     72      12

Bubble sort ascending order

 Bubble sort ascending order #include"stdio.h" int main() { int a[100],n,l,k,swap; printf("Enter the of Elements:"); scanf("%d",&n); for(k=0;k<n;k++) { printf("Enter a[%d] :",k); scanf("%d",&a[k]); } printf("Elements are :\n "); for(k=0;k<n;k++) { printf("%d\t",a[k]); } // sorting // for(k=0;k<n;k++) { for(l=0;l<n;l++) { if(a[l]>a[l+1]) { swap = a[l+1]; a[l+1]= a[l]; a[l]=swap; } } } printf("\nAscending order are:\n"); for(k=1;k<n+1;k++) { printf("%d \t",a[k]); } } Output are: Enter the of Elements:5 Enter a[0] :12 Enter a[1] :48 Enter a[2] :75 Enter a[3] :16 Enter a[4] :30 Elements are :  12     48      75      16      30 Ascending order are: 12      16      30      48      75