Saturday 9 March 2013

Click this link to download cp lab manual - 2

Wednesday 5 December 2012

CPL PROGRAM 15 CODING

                             
                       MATRIX MULTIPLICATION USING FUNCTION
                                             
CODING:                                                    
                                            
#include<stdio.h>
#include<conio.h>
void main()
{
    int a[10][10],i,j,k,b[10][10],c[10][10],r1,c1,r2,c2;
    printf("Enter number of rows and columns of first matrix \n");
    scanf("%d %d",&r1,&c1);
    printf("Enter number of rows and columns of second matrix \n");
    scanf("%d %d",&r2,&c2);
    if(r2==c1)
    {
        printf("Enter rows and columns of First matrix \n");
        for(i=0;i<r1;i++)
        {
         for(j=0;j<c1;j++)
         {
      scanf("%d",&a[i][j]);
     }
    }
   
    printf("Enter rows and columns of Second matrix \n");
    for(i=0;i<r2;i++)
    {
     for(j=0;j<c2;j++)
     {
      scanf("%d",&b[i][j]);
     }
    }
   
    printf("Multiplication of the Matrices:\n");
    for(i=0;i<r1;i++)
    {
     for(j=0;j<c2;j++)
     {
          c[i][j]=0;
          for(k=0;k<r1;k++)
          c[i][j]+=a[i][k]*b[k][j];
      printf("%d\t",c[i][j]);
     }
     printf("\n");
       }
    }
    else
    printf("Matrix multiplication cannot be done");
getch();
}

CPL PROGRAM 14c CODING

              PROGRAM USING UNIONS
                                                      
CODING:                                                           
                                                                                                           
#include<stdio.h>
#include<conio.h>
union student
{
 int rollno;
 char grade;
 float percent;
 double average;
}b;
void main()
{
 clrscr();
 printf("Enter the Integer value ");
 scanf("%d",&b.rollno);
 printf("Enter the Character value ");
 scanf("%c",&b.grade);
 printf("Enter the Float value ");
 scanf("%f",&b.percent);
 printf("Enter the Double value ");
 scanf("%f",&b.average);
 printf("size of union =%d",sizeof(b));
 getch();
}

CPL PROGRAM 14b CODING

                         ARRAY OF STRUCTURES                                           
CODING:                                                  
                                                                                                                 
#include<stdio.h>
#include<conio.h>
struct student
{
 int rollno;
 char name[10],grade;
 float percent;
}a[10];
void main()
{
 int i,n;
 clrscr();
 printf("\n Enter the No.of students");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("Enter students information.....");
  printf("\n Enter Student Roll NO : ");
  scanf("%d",&a[i].rollno);
  printf("\n Enter the Student Name : ");
  scanf("%s",&a[i].name);
  printf("\n Enter the percentage : ");
  scanf("%f",&a[i].percent);
  printf("\n Enter the student grade : ");
  scanf("%c",&a[i].grade);
 }
 for(i=0;i<=n;i++)
 {
  printf("\n Roll no :%d",a[i].rollno);
  printf("\n Name    :%s",a[i].name);
  printf("\n Percent :%f",a[i].percent);
  printf("\n Grade   :%c",a[i].grade);
 }
 getch();
}

CPL PROGRAM 14a CODING

               SIMPLE STRUCTURE PROGRAM
                                                     
CODING:                                                            
                                                                                                        
#include<stdio.h>
#include<conio.h>
struct student
{
 int rollno;
 char name[10],grade;
 float percent;
}a;
void main()
{
 clrscr();
 printf("\n Enter the Student information");
 printf("\n Enter Student Roll NO : ");
 scanf("%d",&a.rollno);
 printf("\n Enter the Student Name : ");
 scanf("%s",&a.name);
 printf("\n Enter the percent : ");
 scanf("%f",&a.percent);
 printf("\n Enter the student grade : ");
 scanf("%c",&a.grade);
 printf("\n Roll no :%d",a.rollno);
 printf("\n Name    :%s",a.name);
 printf("\n Percent :%f",a.percent);
 printf("\n Grade   :%c",a.grade);
 printf("\n Size of :%d",sizeof(a));
getch();
}

CPL PROGRAM 13 CODING

            SORTING THE ARRAY ELEMENTS
                                                        
CODING:                                                               
                                                                                                          
#include<stdio.h>
#include<conio.h>
void main()
{
  clrscr();
  int a[10],i,n,t,j;
  printf("Enter the limit");
  scanf("%d",&n);
  printf("Enter the array values");
  for(i=0;i<n;i++)
  {
   scanf("%d",&a[i]);
  }
  for(i=0;i<n-1;i++)
  {
   for(j=i+1;j<n;j++)
   {
    if(a[i]>a[j])
    {
     t=a[i];
     a[i]=a[j];
     a[j]=t;
    }
   }
  }
  printf("sorted elements are");
  for(i=0;i<n;i++)
  {
   printf("%d",a[i]);
  }
  getch();
}

CPL PROGRAM 12c CODING

             BIGGEST OF THREE NUMBERS                                                       
                                                                    
CODING:                                                             
                                            
#include<stdio.h>
#include<conio.h>
void main()
{
 int a,b,c;
 clrscr();
 printf("Enter Any 3 Number");
 scanf("%d %d %d",&a,&b,&c);
 if((a>b)&&(a>c))
 {
  printf("\n %d is the greatest number",a);
 }
 else if(b>c)
 {
  printf("\n %d is the greatest Number",b);
 }
 else
 {
  printf("%d is the greatest number",c);
 }
 getch();
}