SlideShare a Scribd company logo
1 of 11
Download to read offline
/* Write a C program that uses functions to perform the following:

         i) Addition of Two Matrices

         ii) Multiplication of Two Matrices

*/



#include<stdio.h>



void main()

{

int ch,i,j,m,n,p,q,k,r1,c1,a[10][10],b[10][10],c[10][10];



printf("************************************");

printf("nttMENU");

printf("n**********************************");

printf("n[1]ADDITION OF TWO MATRICES");

printf("n[2]MULTIPLICATION OF TWO MATRICES");

printf("n[0]EXIT");

printf("n**********************************");

printf("ntEnter your choice:n");

scanf("%d",&ch);



if(ch<=2 & ch>0)

{

printf("Valid Choicen");
}



switch(ch)

{

    case 1:

    printf("Input rows and columns of A & B Matrix:");

    scanf("%d%d",&r1,&c1);

    printf("Enter elements of matrix A:n");

     for(i=0;i<r1;i++)

     {

         for(j=0;j<c1;j++)

         scanf("%d",&a[i][j]);

     }

    printf("Enter elements of matrix B:n");

     for(i=0;i<r1;i++)

     {

         for(j=0;j<c1;j++)

         scanf("%d",&b[i][j]);

     }

    printf("n =====Matrix Addition=====n");

     for(i=0;i<r1;i++)

     {

         for(j=0;j<c1;j++)

         printf("%5d",a[i][j]+b[i][j]);
printf("n");

    }

break;



case 2:

printf("Input rows and columns of A matrix:");

scanf("%d%d",&m,&n);

printf("Input rows and columns of B matrix:");

scanf("%d%d",&p,&q);

if(n==p)

{

printf("matrices can be multipliedn");

printf("resultant matrix is %d*%dn",m,q);

printf("Input A matrixn");

read_matrix(a,m,n);

printf("Input B matrixn");

/*Function call to read the matrix*/

read_matrix(b,p,q);

/*Function for Multiplication of two matrices*/

printf("n =====Matrix Multiplication=====n");

for(i=0;i<m;++i)

    for(j=0;j<q;++j)

    {

        c[i][j]=0;
for(k=0;k<n;++k)

                c[i][j]=c[i][j]+a[i][k]*b[k][j];

        }



    printf("Resultant of two matrices:n");

        write_matrix(c,m,q);

        }

        /*end if*/

    else

    {

    printf("Matrices cannot be multiplied.");

    }

    /*end else*/

    break;



    case 0:

    printf("n Choice Terminated");

    exit();

    break;



    default:

    printf("n Invalid Choice");

}
}



/*Function read matrix*/

int read_matrix(int a[10][10],int m,int n)

    {

        int i,j;

         for(i=0;i<m;i++)

                   for(j=0;j<n;j++)

                   scanf("%d",&a[i][j]);

    return 0;

    }



    /*Function to write the matrix*/

int write_matrix(int a[10][10],int m,int n)

    {

        int i,j;

         for(i=0;i<m;i++)

         {

                   for(j=0;j<n;j++)

                   printf("%5d",a[i][j]);

                   printf("n");

         }

    return 0;

    }
/* The total distance travelled by vehicle in 't' seconds is given by distance = ut+1/2at2

     where 'u' and 'a' are the initial velocity (m/sec.) and acceleration (m/sec2).

     Write C program to find the distance travelled at regular intervals of time given

     the values of 'u' and 'a'. The program should provide the flexibility to the user

     to select his own time intervals and repeat the calculations for different values of 'u' and 'a'.

*/



#include <stdio.h>

#include <math.h>



void main()

{

int tim_intrval, counter,time;

float accl, distance=0, velos;

clrscr();

printf("<===========PROGRAM FOR CALC TOTAL DISTANCE TRAVELED BY A
VECHIAL===========>");

printf("nnntttNO OF TIME INTERVALS : ");

scanf("%d",&tim_intrval);
for(counter = 1; counter <= tim_intrval; counter++)

{

     printf("ntttAT T%d TIME(sec) : ",counter);

     scanf("%d",&time);

     printf("tttVELOCITY AT %d sec (m/sec) : ",time);

     scanf("%f",&velos);

     printf("tttACCLERATION AT %d sec (m/sec^2): ",time);

     scanf("%f",&accl);

     distance += (velos*time + (accl*pow(time,2))/2);

}



printf("nnntTOTAL DISTANCE TRAVELLED BY VEHICLE IN %d INTERVALS OF TIME :
%f",tim_intrval,distance);

getch();

}
/* Write a C program, which takes two integer operands and one operator form the user,

    performs the operation and then prints the result.

    (Consider the operators +,-,*, /, % and use Switch Statement)

*/



#include<stdio.h>

#include<conio.h>



void main()

{

int a,b,res,ch;

clrscr();

printf("t *********************");

printf("ntMENUn");

printf("t********************");

printf("nt(1)ADDITION");
printf("nt(2)SUBTRACTION");

printf("nt(3)MULTIPLICATION");

printf("nt(4)DIVISION");

printf("nt(5)REMAINDER");

printf("nt(0)EXIT");

printf("nt********************");

printf("nntEnter your choice:");

scanf("%d",&ch);



if(ch<=5 & ch>0)

{

printf("Enter two numbers:n");

scanf("%d%d",&a,&b);

}



switch(ch)

{

case 1:

res=a+b;

printf("n Addition:%d",res);

break;



case 2:

res=a-b;
printf("n Subtraction:%d",res);

break;



case 3:

res=a*b;

printf("n Multiplication:%d",res);

break;



case 4:

res=a/b;

printf("n Division:%d",res);

break;



case 5:

res=a%b;

printf("n Remainder:%d",res);

break;



case 0:

printf("n Choice Terminated");

exit();

break;



default:
printf("n Invalid Choice");

}

getch();

}

More Related Content

What's hot

C programming Lab 1
C programming Lab 1C programming Lab 1
C programming Lab 1Zaibi Gondal
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given numberMainak Sasmal
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solutionAnimesh Chaturvedi
 
Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in cBUBT
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2Zaibi Gondal
 
Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in cBUBT
 
C programs
C programsC programs
C programsMinu S
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in CSaket Pathak
 
Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C BUBT
 
Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CBUBT
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentalsZaibi Gondal
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2Animesh Chaturvedi
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]ecko_disasterz
 

What's hot (20)

C programming Lab 1
C programming Lab 1C programming Lab 1
C programming Lab 1
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Pslb lab manual
Pslb lab manualPslb lab manual
Pslb lab manual
 
C Programming
C ProgrammingC Programming
C Programming
 
Lab manualsahu[et&amp;t]
Lab manualsahu[et&amp;t]Lab manualsahu[et&amp;t]
Lab manualsahu[et&amp;t]
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
 
Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in c
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
Ansi c
Ansi cAnsi c
Ansi c
 
Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
 
C important questions
C important questionsC important questions
C important questions
 
C programs
C programsC programs
C programs
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 
Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C
 
Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in C
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]
 

Viewers also liked (8)

week-2x
week-2xweek-2x
week-2x
 
week-4x
week-4xweek-4x
week-4x
 
week-5x
week-5xweek-5x
week-5x
 
C code examples
C code examplesC code examples
C code examples
 
week-1x
week-1xweek-1x
week-1x
 
ch14
ch14ch14
ch14
 
week-10x
week-10xweek-10x
week-10x
 
week-11x
week-11xweek-11x
week-11x
 

Similar to week-3x (20)

C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
C programs
C programsC programs
C programs
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
C-programs
C-programsC-programs
C-programs
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
C file
C fileC file
C file
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programs
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
C basics
C basicsC basics
C basics
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1
 

More from KITE www.kitecolleges.com (20)

DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENTDISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
 
BrainFingerprintingpresentation
BrainFingerprintingpresentationBrainFingerprintingpresentation
BrainFingerprintingpresentation
 
ch6
ch6ch6
ch6
 
PPT (2)
PPT (2)PPT (2)
PPT (2)
 
week-18x
week-18xweek-18x
week-18x
 
ch16
ch16ch16
ch16
 
holographic versatile disc
holographic versatile discholographic versatile disc
holographic versatile disc
 
week-22x
week-22xweek-22x
week-22x
 
week-16x
week-16xweek-16x
week-16x
 
week-6x
week-6xweek-6x
week-6x
 
ch8
ch8ch8
ch8
 
Intro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.ukIntro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.uk
 
ch17
ch17ch17
ch17
 
ch4
ch4ch4
ch4
 
week-7x
week-7xweek-7x
week-7x
 
week-9x
week-9xweek-9x
week-9x
 
week-14x
week-14xweek-14x
week-14x
 
AIRBORNE
AIRBORNEAIRBORNE
AIRBORNE
 
ch2
ch2ch2
ch2
 
week-23x
week-23xweek-23x
week-23x
 

Recently uploaded

Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfTechSoup
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphNetziValdelomar1
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxraviapr7
 
UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationMJDuyan
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17Celine George
 
Practical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxPractical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxKatherine Villaluna
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...Nguyen Thanh Tu Collection
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptxSandy Millin
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfYu Kanazawa / Osaka University
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxDr. Asif Anas
 
How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17Celine George
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxraviapr7
 
Human-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesHuman-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesMohammad Hassany
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and stepobaje godwin sunday
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfMohonDas
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxMYDA ANGELICA SUAN
 

Recently uploaded (20)

Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a Paragraph
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptx
 
UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive Education
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17
 
Practical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxPractical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptx
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptx
 
Prelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quizPrelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quiz
 
How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptx
 
Human-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesHuman-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming Classes
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and step
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdf
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptx
 

week-3x

  • 1. /* Write a C program that uses functions to perform the following: i) Addition of Two Matrices ii) Multiplication of Two Matrices */ #include<stdio.h> void main() { int ch,i,j,m,n,p,q,k,r1,c1,a[10][10],b[10][10],c[10][10]; printf("************************************"); printf("nttMENU"); printf("n**********************************"); printf("n[1]ADDITION OF TWO MATRICES"); printf("n[2]MULTIPLICATION OF TWO MATRICES"); printf("n[0]EXIT"); printf("n**********************************"); printf("ntEnter your choice:n"); scanf("%d",&ch); if(ch<=2 & ch>0) { printf("Valid Choicen");
  • 2. } switch(ch) { case 1: printf("Input rows and columns of A & B Matrix:"); scanf("%d%d",&r1,&c1); printf("Enter elements of matrix A:n"); for(i=0;i<r1;i++) { for(j=0;j<c1;j++) scanf("%d",&a[i][j]); } printf("Enter elements of matrix B:n"); for(i=0;i<r1;i++) { for(j=0;j<c1;j++) scanf("%d",&b[i][j]); } printf("n =====Matrix Addition=====n"); for(i=0;i<r1;i++) { for(j=0;j<c1;j++) printf("%5d",a[i][j]+b[i][j]);
  • 3. printf("n"); } break; case 2: printf("Input rows and columns of A matrix:"); scanf("%d%d",&m,&n); printf("Input rows and columns of B matrix:"); scanf("%d%d",&p,&q); if(n==p) { printf("matrices can be multipliedn"); printf("resultant matrix is %d*%dn",m,q); printf("Input A matrixn"); read_matrix(a,m,n); printf("Input B matrixn"); /*Function call to read the matrix*/ read_matrix(b,p,q); /*Function for Multiplication of two matrices*/ printf("n =====Matrix Multiplication=====n"); for(i=0;i<m;++i) for(j=0;j<q;++j) { c[i][j]=0;
  • 4. for(k=0;k<n;++k) c[i][j]=c[i][j]+a[i][k]*b[k][j]; } printf("Resultant of two matrices:n"); write_matrix(c,m,q); } /*end if*/ else { printf("Matrices cannot be multiplied."); } /*end else*/ break; case 0: printf("n Choice Terminated"); exit(); break; default: printf("n Invalid Choice"); }
  • 5. } /*Function read matrix*/ int read_matrix(int a[10][10],int m,int n) { int i,j; for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); return 0; } /*Function to write the matrix*/ int write_matrix(int a[10][10],int m,int n) { int i,j; for(i=0;i<m;i++) { for(j=0;j<n;j++) printf("%5d",a[i][j]); printf("n"); } return 0; }
  • 6. /* The total distance travelled by vehicle in 't' seconds is given by distance = ut+1/2at2 where 'u' and 'a' are the initial velocity (m/sec.) and acceleration (m/sec2). Write C program to find the distance travelled at regular intervals of time given the values of 'u' and 'a'. The program should provide the flexibility to the user to select his own time intervals and repeat the calculations for different values of 'u' and 'a'. */ #include <stdio.h> #include <math.h> void main() { int tim_intrval, counter,time; float accl, distance=0, velos; clrscr(); printf("<===========PROGRAM FOR CALC TOTAL DISTANCE TRAVELED BY A VECHIAL===========>"); printf("nnntttNO OF TIME INTERVALS : "); scanf("%d",&tim_intrval);
  • 7. for(counter = 1; counter <= tim_intrval; counter++) { printf("ntttAT T%d TIME(sec) : ",counter); scanf("%d",&time); printf("tttVELOCITY AT %d sec (m/sec) : ",time); scanf("%f",&velos); printf("tttACCLERATION AT %d sec (m/sec^2): ",time); scanf("%f",&accl); distance += (velos*time + (accl*pow(time,2))/2); } printf("nnntTOTAL DISTANCE TRAVELLED BY VEHICLE IN %d INTERVALS OF TIME : %f",tim_intrval,distance); getch(); }
  • 8. /* Write a C program, which takes two integer operands and one operator form the user, performs the operation and then prints the result. (Consider the operators +,-,*, /, % and use Switch Statement) */ #include<stdio.h> #include<conio.h> void main() { int a,b,res,ch; clrscr(); printf("t *********************"); printf("ntMENUn"); printf("t********************"); printf("nt(1)ADDITION");
  • 9. printf("nt(2)SUBTRACTION"); printf("nt(3)MULTIPLICATION"); printf("nt(4)DIVISION"); printf("nt(5)REMAINDER"); printf("nt(0)EXIT"); printf("nt********************"); printf("nntEnter your choice:"); scanf("%d",&ch); if(ch<=5 & ch>0) { printf("Enter two numbers:n"); scanf("%d%d",&a,&b); } switch(ch) { case 1: res=a+b; printf("n Addition:%d",res); break; case 2: res=a-b;
  • 10. printf("n Subtraction:%d",res); break; case 3: res=a*b; printf("n Multiplication:%d",res); break; case 4: res=a/b; printf("n Division:%d",res); break; case 5: res=a%b; printf("n Remainder:%d",res); break; case 0: printf("n Choice Terminated"); exit(); break; default: