Wednesday, April 1, 2015

C program to create student structure

Write a ‘C’ program to create student structure having field roll no, stud name,
class, pass this entire structure to function and display the structure elements.

#include<stdio.h>
#include<conio.h>
struct student
{
int rollno;
char sname[20];
char sclass[10];
};
void disp(struct student);
void main()
{
struct student s;
clrscr();
printf("enter the rollno,sname&sclass");
scanf("%d%s%s",&s.rollno,&s.sname,&s.sclass);
disp(s);
getch();
}
void disp(struct student s)
{
printf("%d%s%s",s.rollno,s.sname,s.sclass);
}

Write a ‘C’ program to reverse an array elements using dynamic memory allocation.

Write a ‘C’ program to reverse an array elements using dynamic memory allocation.

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
void main()
{
int n,i;
int *p;
clrscr();
printf("enter the size");
scanf("%d",&n);
p=(int*)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
{
scanf("%d",&p[i]);
}
for(i=n-1;i>=0;i--)
{
printf("%d",p[i]);
}
getch();
}

Data structure using C .Write C program for Quick sort.

Data structure using C
Write C program for Quick sort.

#include<stdio.h>
#include<conio.h>
int split(int lp,int up);
void quick(int lp,int up);
int a[20];
void main()
{
 int n,i,lp,up;
 clrscr();
 printf("\n Enter how many number u want:-");
 scanf(" %d",&n);
 printf("\n Enter %d numbers:-",n);
 for(i=0;i<n;i++)
 {
  scanf(" %d",&a[i]);
 }
 printf("\n Before sorting numbers are:-");
 for(i=0;i<n;i++)
 {
  printf("\n%d",a[i]);
 }
 quick(0,n-1);
 printf("\n After sorting numbers are:-");
 for(i=0;i<n;i++)
 {
  printf("\n%d",a[i]);
 }
 getch();
}
void quick(int lp,int up)
{
 int i;
 if(up>lp)
 {
  i=split(lp,up);
  quick(lp,i-1);
  quick(i+1,up);
 }
}
int split(int lp,int up)
{
 int k,p,q,t;
 p=lp+1;
 q=up;
 k=a[lp];
 while(q>=p)
 {
  while(a[p]<k)
  {
   p++;
  }
  while(a[q]>k)
  {
   q--;
  }
  if(q>p)
  {
   t=a[p];
   a[p]=a[q];
   a[q]=t;
  }
 }
 t=a[lp];
 a[lp]=a[q];
 a[q]=t;
 return(q);
}

/*
 Enter how many number u want:-5                                              
                                                                               
 Enter 5 numbers:-2                                                            
6                                                                              
1                                                                              
0                                                                              
9                                                                              
                                                                               
 Before sorting numbers are:-                                                  
2                                                                              
6                                                                              
1                                                                              
0                                                                              
9                                                                              
 After sorting numbers are:-                                                  
0                                                                              
1                                                                              
2                                                                              
6                                                                              
9                      */

Write a C program to sort an array elements using Insert Sort technique.

Write a ‘C’ program to sort an array elements using Insert Sort technique.

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[20],t,n,i,j,k;
 clrscr();
 printf("\n enter how many number=");
 scanf(" %d",&n);
 printf("\n Enter %d numbres:-",n);
 for(i=0;i<n;i++)
 {
  scanf("%d",&a[i]);
 }
 printf("\n Before sorting numbers are:-");
 for(i=0;i<n;i++)
 {
  printf("\n %d",a[i]);
 }

   for(j=0;j<n;j++)
   {
    k=a[j];
    if(j==0)
    {
     a[j]=k;
    }
    else
    {
     for(t=j-1;t>=0&&k<a[t];t--)
     {
      a[t+1]=a[t];
     }
     a[t+1]=k;
    }
  }

 printf("\n after sorting numbers are=\n");
 for(i=0;i<n;i++)
 {
  printf("\n%d",a[i]);
 }
 getch();
}
/*
 enter how many number=5
                                                                               
 Enter 5 numbres:-5
 1                                                                            
 6                                                                            
 0                                              
 -8                                      
                                                                               
 Before sorting numbers are:-        
 5                                                    
 1                                        
 6                                              
 0                                            
 -8                                                  
 after sorting numbers are=                          
                                                                               
-8                                
0                                                                            
1
5
6            */  

Write a C program to sort an array elements using Select Sort technique.

Write a ‘C’ program to sort an array elements using Select Sort technique.

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[20],n,i,j,t,s ;
 clrscr();
 printf("\n\n Enter how many number u want:-\n\n");
 scanf(" %d",&n);
 printf("\n\n Enter %d numbers:-",n);
 for(i=0;i<n;i++)
 {
  scanf(" %d",&a[i]);
 }
 printf("\n\n Before sorting numbers are:-\n\n");
 for(i=0;i<n;i++)
 {
  printf("\n %d",a[i]);
 }
 for(i=0;i<n-1;i++)
 {
  s=i;
  for(j=i+1;j<n;j++)
  {
   if(a[s]>a[j])
   {
    s=j;
   }
  }
  if(i!=s)
  {
   t=a[i];
   a[i]=a[s];
   a[s]=t;
  }

}
 printf("\n\n After sorting numbers are:-\n\n");
 for(i=0;i<n;i++)
 {
  printf("\n %d",a[i]);
 }
 getch();
}

/*                   OUTPUT

 Enter how many number u want:-

 5


 Enter 5 numbers:-5
 6
 1
 0
 10


 Before sorting numbers are:-


 5
 6
 1
 0
 10

 After sorting numbers are:-


 0
 1
 5
 6
 10   */

Write a ‘C’ program to sort an array elements using Merge Sort technique.

Write a ‘C’ program to sort an array elements using Merge Sort technique.


#include<stdio.h>
#include<conio.h>
int n;
void display(int a[])
{
  int i;
  printf("\n");
  for(i=0;i<n;i++)
    printf("\t%d",a[i]);
}
void merge(int a[],int low,int mid,int high)
{
  int i,j,k,b[20];
  i=low;
  j=mid+1;
  k=0;
  while ((i<=mid) && (j<=high))
  {
    if (a[i]<=a[j])
b[k++]=a[i++];
    else
b[k++]=a[j++];
  }
  while (i<=mid)
b[k++]=a[i++];
  while (j<=high)
b[k++]=a[j++];
  //copy merged element from b to a
  for(j=low,k=0;j<=high;j++,k++)
a[j]=b[k];
}
void mergesort(int a[],int low,int high)
{
  int mid;
  if(low<high)
  {
    mid=(low+high)/2;
    mergesort(a,low,mid);
    mergesort(a,mid+1,high);
    merge(a,low,mid,high);
  }
}
void main()
{
 int a[20],i;
 clrscr();
 printf("\nHow many numbers: ");
 scanf("%d",&n);
 printf("\nEnetr the unsorted numbers: ");
 for(i=0;i<n;i++)
    scanf("%d",&a[i]);
 mergesort(a,0,n-1);
 display(a);
 getch();
}

Write a C program for multiplication of two m*n matrices.

Write a ‘C’ program for multiplication of two m*n matrices.

#include<stdio.h>
#include<conio.h>
void main()
{
   int m,n,p,q,i=0,j=0;
   int a[10][10],b[10][10],c[10][10];
   clrscr();
   printf("enter the number of row: ");
   scanf("%d",&m);
   printf("enter the number of column :");
   scanf("%d",&n);
   printf("enter the first matrix elements\n");
   for(i=0;i<m;i++)
   {
      for(j=0;j<n;j++)
      {
scanf("%d",&a[i][j]);
      }
   }
   printf("enter the number of row: ");
   scanf("%d",&p);
   printf("enter the number of column :");
   scanf("%d",&q);
   printf("enter the second matrix elements\n");
   for(i=0;i<p;i++)
   {
      for(j=0;j<q;j++)
      {
scanf("%d",&b[i][j]);
      }
   }
   for(i=0;i<m;i++)
   {
      for(j=0;j<q;j++)
      {
  c[i][j]=a[i][j]*b[j][i];
      }
   }
   printf("multiplication of matrix is \n");
   for(i=0;i<m;i++)
   {
      for(j=0;j<q;j++)
      {
printf("%d  ",c[i][j]);
      }
      printf("\n");
   }
   getch();
}

What is Next JS?

 What is Next JS? Next.js is a powerful React framework developed by Vercel that simplifies building modern web applications. Its key featur...