Posts

Showing posts from June, 2021

write a program for insertion sort with example .

Image
#include<stdio.h> #include<conio.h> int main() { int a[50],n,i,j,temp; printf("enter size of an array\n"); scanf("%d",&n); printf("\nenter element in 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("\t%d\n",a[i]); } return 0; }

write a program for bubble sort with example .

write a program to print prime number between 1 to 50.

Image
#include<stdio.h> #include<conio.h> int main() { int i,j,ans; printf("Prime Number between 1 to 50\n"); for(j=1;j<=50;j++) { ans=0; for(i=2;i<=j/2; i++) { if(j%i==0) { ans++; } } if(ans==0&&j!=1) { printf("%d\n",j); } } return 0; }

write a program to find the product or multiplication of two matrices.

Image
#include<stdio.h> #include<conio.h> int main() { int a[3][3],b[3][3],c[3][3],sum=0,i,j,k; printf("enter value of first matrix\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) scanf("%d",&a[i][j]); } printf("enter value of second matrix\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) scanf("%d",&b[i][j]); } for(i=0;i<3;i++) { for(j=0;j<3;j++) { sum=0; for(k=0;k<3;k++) sum=sum+a[i][k]*b[k][j]; c[i][j]=sum; } } printf("multiplication of two matrix\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d\t",c[i][j]); printf("\n"); } return 0; }

write a program to store the information of student by using union.

Image
#include<stdio.h> #include<conio.h> union student { char name[10]; int rollno; }; main() { union student stu; printf("enter student name\n"); scanf("%s",&stu.name); printf("student name is %s\n",stu.name); printf("enter student rollno\n"); scanf("%d",&stu.rollno); printf("student rollno is %d\n",stu.rollno); return 0; }