#include #define MAX 50 void mergeSort(int arr[],int low,int mid,int high); void partition(int arr[],int low,int high); int main(){ int merge[MAX],i,n; printf("Enter the total number of elements: "); scanf("%d",&n); printf("Enter the elements which to be sort: "); for(i=0;imid){ for(k=m;k<=high;k++){ temp[i]=arr[k]; i++; } } else{ for(k=l;k<=mid;k++){ temp[i]=arr[k]; i++; } } for(k=low;k<=high;k++){ arr[k]=temp[k]; } } Sample output: Enter the total number of elements: 5 Enter the elements which to be sort: 2 5 0 9 1 After merge sorting elements are: 0 1 2 5 9
Correct Answer: #include int main(){ int num,i,f,r,sum=0,temp; printf("Enter a number: "); scanf("%d",&num); temp=num; while(num){ i=1,f=1; r=num%10; while(i<=r){ f=f*i; i++; } sum=sum+f; num=num/10; } if(sum==temp) printf("%d is a strong number",temp); else printf("%d is not a strong number",temp); return 0; } Sample output: Enter a number: 145 145 is a strong number
Correct Answer: #include int main(){ int a[10],i,n,m,c=0,l,u,mid; printf("Enter the size of an array: "); scanf("%d",&n); printf("Enter the elements in ascending order: "); for(i=0;i
Correct Answer: #include int main() { int a[5][5], b[5][5], c[5][5], i, j, k, sum = 0, m, n, o, p; printf( "\nEnter the row and column of first matrix" ); scanf( "%d %d", &m, &n ); printf( "\nEnter the row and column of second matrix" ); scanf( "%d %d", &o, &p ); if(n!=o) { printf( "Matrix mutiplication is not possible" ); printf( "\nColumn of first matrix must be same as row of second matrix" ); } else { printf( "\nEnter the First matrix" ); for( i=0; i
8. Write a c program to copy a data of file to other file.
Correct Answer: #include int main(){ FILE *p,*q; char file1[20],file2[20]; char ch; printf("\nEnter the source file name to be copied:"); gets(file1); p=fopen(file1,"r"); if(p==NULL){ printf("cannot open %s",file1); exit(0); } printf("\nEnter the destination file name:"); gets(file2); q=fopen(file2,"w"); if(q==NULL){ printf("cannot open %s",file2); exit(0); } while((ch=getc(p))!=EOF) putc(ch,q); printf("\nCOMPLETED"); fclose(p); fclose(q); return 0; }
9. What will be output of following c code? void main() { struct india { char c; float d; }; struct world { int a[3]; char b; struct india orissa; }; struct world st ={{1,2,3},'P','q',1.4}; clrscr(); printf("%dt%ct%ct%f",st.a[1],st.b,st.orissa.c,st.orissa.d); getch(); }