You are on page 1of 6

NAME:OMUHINDA JADEN MSAFIRI

REG NO:SIT/1176/2022

UNIT NAME:FUNDAMENTALS OF PROGRAMMING

UNIT CODE:BIT 113

LECTURER:MR YOHANA AND BENJAMIN KIPRONO

TASK:PROGRAMMING ASSIGNMENT

1
Programming assignment
1 program for displaying multiplication of two matrices.
#include<stdio.h>
int main()
{
int m,n,p,q,c,d,k, sum=0;
int first[10][10],second [10][10],multiply[10][10];
printf("Enter the number of rows and column of the first matrix\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of the first matrix\n");
for(c=0;c<m;c++)
for(d=0;d,n;d++)
scanf("%d",&first[c][d]);
printf("Enter the number of rows and column of the second matrix\n");
scanf("%d%d",&p,&q); if(n!=p)
printf("Matrices with entered order cant be multiplied with each
other.\n");
else
{
printf("Enter the elements of second matrix \n");
for(c=0;c<p;c++)
for(d=0;d<q;d++)
scanf("%d",&second[c][d]);
for(c=0;c<m;c++)
{
for(d=0;d<q;d++)
{
2
for(k=0;k<p;k++)
{ sum=sum+first[c][k]*second[k][d]; }
multiply[c][d]=sum;
sum=0; } }
printf("Product of entered matrices:-\n");
for(c=0;c<m;c++) {
for(d=0;d<q;d++)
printf("%d\t",multiply[c][d]);
printf("\n"); } }
return 0;
}
2 Array program to display a 2by 2 matrix and show its determinant.
#include<stdio.h>
int main () {
int a[2][2],i,j;
long determinant;
Printf(“\nEnter 4 elements of array”);
for(i=0;i<2;i++)
for(j=0;j<2;j++){
printf(“%d\t”,a[i][j]; }
printf(“\n”); }
determinant=a[0][0]*a[1][1]-a[1][0]*a[0][1];
printf(“Determinant is :%d-%d=%d”,a[0][0]*a[1][1]-a[1][0]*a[0]
[1],determinant);
Return 0;
}

3
3 If/else program to give grades.
#include<stdio.h>
int main() {
int marks ;
Printf (“Enter marks”);
Scanf(“%d”,& marks);
Printf (“Marks is %d”,marks);
if (marks >=70) {
printf (“Grade is A”); }
else if( marks >= 60){
Printf (“Grade is B”) ; }
else if (marks>=50); {
printf (“Grade is C”); }
else if(marks >=40){
printf (“Grade is D”); }
else ( marks<40);{
printf (“Grade is failed “);}
return 0;
}

4
4 Switch case program to display grades.
#include<stdio.h>
int main () {
int mark;
printf (“Enter marks”);
scanf(“%d”,&marks);
printf (“marks is %d”,marks);
Switch (marks/10) {
Case 10:
Case 9:
Case 8:
Case 7:
Printf(“Grade is A\n”);
break;
Case 6:
Printf(“Grade is B \n”);
break;
Case 5:
Printf(“Grade is C \n”);
break;
Case 4:
Printf(“Grade is D\n”);
break;
Case 3:
Case 2:
Case 1:

5
Printf (“Grade is failed”);
Break;
default:
Printf (“Your grade is %d”,grade); }
Return 0;
}

5 Program to display 10 by 10 multiplication table.


#include<stdio.h>
int main () {
int i, n;
Printf (“Enter any number:\n”);
Scanf (“%d”,&n);
For(i= 1;i<=10;i++){
Printf (“%d *%d=%d\n”,i,n,n*i); }
Return 0;
}

You might also like