#include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { int i,n; int *ptr; printf("enter the no. of elements\n"); scanf("%d",&n); ptr=(int*)malloc(n*sizeof(int)); printf("memory allocated\n"); for(i=0;i<n;i++) { ptr[i]=i+1; } printf("elements in the array are\n"); for(i=0;i<n;i++) { printf("%d\n",ptr[i]); } return 0; }
#include<stdio.h> #include<conio.h> int main() { int a[50],n,i,j,temp; printf("enter the size of an array\n"); scanf("%d",&n); printf("enter the elements in an array\n"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=1;i<n;i++) { temp=a[i]; j=i-1; while(j>=0 &&a[j]>temp) { a[j+1]=a[j]; j=j-1; } a[j+1]=temp; } for(i=0;i<n;i++) { printf("%d\t",a[i]); } return 0; }
Comments
Post a Comment