Sunday, June 22, 2014

CSIT 2nd Sem DSA Assignment #1



Click here to Download Assignment#1 | Click here to Download Cover Page

ONLINE PREVIEW:


STATEMENT:A PROGRAM TO FIND SUM AND AVERAGE VALUES OF ANY 20 NUMBERS USING ARRAY WITH FUNCTION.
ALGORITHM:
Step1
Start
Step2
Initialize sum as 0
Step3
Ask user to enter 20 different numbers
Step4
Call the integer function fxsum()
Step5
Display sum of numbers as ‘sum’ and their average as ‘sum/20’
Step6
Stop

Step1
Start of userdefined integer function fxsum()
Step2
Initialize b=0 and i=0
Step3
Is i<20?
YES
Goto Step4
NO
Goto Step8
Step4
Ask the value for a[i]
Step5
Increase the value of b by a[i]
Step6
Increase the value of i by 1
Step7
Goto Step3
Step8
Return the value of b to the calling function
Step9
Stop




SOURCE CODE:
#include <stdio.h>
#include <conio.h>
void main()
{
int fxsum();
int sum=0;
clrscr();
printf("Enter 20 diferent numbers:\n\n");
sum=fxsum();
printf("\nThe Sum of numbers is : %d \nand their average is: %f",sum,(float)sum/20);
getch();
}
int fxsum()
{
int a[20],i,b=0;
for(i=0;i<20;i++)
            {
            scanf("%d",&a[i]);
            b=b+a[i];
            }
return b;
}




OUTPUT SCREEN:





RESULT:
The result of this program is the sum total of 20 different integer numbers and their average as a floating point number.

CONCLUSION:
The sum of multiple numbers can be easily and conveniently found with the use of array.


STATEMENT:A PROGRAM TO FIND MULTIPLICATION OF ANY 3X3 MATRIX. 
ALGORITHM:
Step1
Start
Step2
Initialize x=4 and y=0 as global variables
Step3
Ask user to enter 3x3 matrix A
Step4
Call a userdefined function askmat with parameter a
Step5
Ask user to enter 3x3 matrix B
Step6
Call a userdefined function askmat with parameter b
Step7
Call a userdefined function mulmat with parameter a,b
Step8
Stop

Step1
Start of userdefined function askmat()
Step2
Increase the value of y by 4
Step3
Initialize i=0
Step4
Is i<3?
YES
Goto Step5
NO
Goto Step17
Step5
Initialize j=0
Step6
Is j<3?
YES
Goto Step7
NO
Goto Step12
Step7
Change cursor position to xth column and yth row on the screen
Step8
Ask user to enter the value of a[i][j]
Step9
Increase value of x by 2
Step10
Increase value of j by 1
Step11
Goto Step6
Step12
Change the cursor position to next line
Step13
Increase the value of y by 2
Step14
Reset the value of x=4
Step15
Increase the value of i by 1
Step16
Goto Step4`
Step17
Stop

Step1
Start of userdefined function mulmat()
Step2
Initialize the value of i=0
Step3
Is i<3?
YES
Goto Step4
NO
Goto Step12
Step4
Initialize the value of j=0
Step5
Is j<3?
YES
Goto Step6
NO
Goto Step9
Step6
Calculate c[i][j]=a[i][0]*b[0][j]+a[i][1]*b[1][j]+a[i][2]*b[2][j]
Step7
Increase the value of j by 1
Step8
Goto Step5
Step9
Change the cursor position to next line
Step10
Increase the value of i by 1
Step11
Goto Step3
Step12
Call the userdefined function showmat()
Step13
Stop

Step1
Start
Step2
Initialize the value of i=0
Step3
Is i<3?
YES
Goto Step4
NO
Goto Step12
Step4
Initialize the value of j=0
Step5
Is j<3?
YES
Goto Step6
NO
Goto Step9
Step6
Display c[i][j] and leave a tab space
Step7
Increase value of j by 1
Step8
Goto Step5
Step9
Change the cursor position to next line
Step10
Increase value of I by 1
Step11
Goto Step3
Step12
Stop




SOURCE CODE:
#include <stdio.h>
#include <conio.h>
int x=4,y=0;
void main()
{
int a[3][3],b[3][3],i,j;
void askmat(int a[][3]);
void mulmat(int a[][3],int b[][3]);
clrscr();
            printf("\nEnter 3x3 matrix A:\n");
            askmat(a);
            printf("\nEnter 3x3 matrix B:\n");
            askmat(b);
            mulmat(a,b);
getch();
}
void askmat(int a[][3])
{
int i,j;
y=y+4;
            for(i=0;i<3;i++)
            {
                        for(j=0;j<3;j++)
                        {
                        gotoxy(x,y);
                        scanf("%d",&a[i][j]);
                        x=x+2;
                        }
            printf("\n");
            y=y+2;
            x=4;
            }
}
void mulmat(int a[][3],int b[][3])
{
int i,j,c[3][3];
            void showmat(int a[][3]);

            for(i=0;i<3;i++)
            {
                        for(j=0;j<3;j++)
                        {
                        c[i][j]=a[i][0]*b[0][j]+a[i][1]*b[1][j]+a[i][2]*b[2][j];
                        }
            printf("\n");
            }
            showmat(c);
}
void showmat(int a[][3])
{
int i,j;
printf("The product of 3x3 matrices is:\n");
for(i=0;i<3;i++)
{
            for(j=0;j<3;j++)
            {
            printf("%d\t",a[i][j]);
            }
            printf("\n");
}
}




OUTPUT SCREEN:

RESULT:
The result of this program is the product of two 3x3 matrices found by computing two matrices.

CONCLUSION:
The product of any two 3x3 matrices can be found and represented easily in the form of two dimensional arrays.



COMMENTS:


Blogger Comments:


Emoticon Emoticon

Most read this week!