C Programming Part 1

C Programming Notes

C Programming:

1) Sum of first 100 odd Number
2) Find maximum and minimum
3) Matrix Multiplication
4) Addition and Subtraction of two matrix


/* 1. Sum of first 100 odd numbers */ 
/* Program Coded By Chetan Thapa Magar. */ 
#include<stdio.h>
#include<conio.h>
void main()
{
int i, k, sum=0, l;
printf("Enter how many odd numbers:\n");
scanf("%d", &k);
l=2*k-1;
for(i=1; i<=l; i+=2)
sum=sum+i;
printf("\nThe sum of odd numbers from 1 to %d is %d", l, sum);
getch();
}
Output / Execution:
Enter how many odd numbers:
100

The sum of odd numbers from 1 to 199 is 10000

/* Find maximum and minimum */ 
/* Program Coded By Chetan Thapa Magar */ 


#include<stdio.h>
#include<conio.h>
#include<math.h>
int max(int a[], int, int);
int min(int b[], int, int);
void main()

{

int i, n, a[50], big, small;
printf("Enter how many numbers:\t");
scanf("%d", &n);
printf("\nEnter the number one by one:\n");
for(i=0; i<n; i++)
scanf("%d", &a[i]);
big=a[0];
small=a[n-1];
printf("\nThe maximum value is %d", max(a, n, big));
printf("\nThe minimum value is %d", min(a, n, small));
getch();
}

int max(int a[], int n, int big)
{
if(n==0)
return big;
else
n--;
if(a[n]>big)
big=a[n];
return(max(a,n,big));
}
int min(int a[], int n, int small)
{
if(n==0)
return small;
else
n--;
if(a[n]<small)
small=a[n];
return min(a, n, small);
}

Output / Execution:

Enter how many numbers: 5
Enter the numbers one by one

14
56
34
63
45

The maximum value is 63
The minimum value is 14



/* Matrix Multiplication */ 
/* Program Coded By Chetan Thapa Magar */ 


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()

{
int m, n, p, q, i, j, k, a[10][10], b[10][10], c[10][10];
printf("Enter the order of A matrix (m*n):\n");
scanf("%d%d", &m, &n);
printf("\nEnter the order of B matrix (p*q):\n");
scanf("%d%d", &p, &q);
if(n==p)
{
printf("\nMatrix can be multiplied.\n");
printf("\nEnter the value of matrix A:\n");
for(i=0; i<m; i++)
for(j=0; j<n; j++)
scanf("%d", &a[i][j]);
printf("\nEnter the value of matrix B:\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<m; j++)
{
c[i][j]=0;
for(k=0; k<n; k++)
c[i][j]=c[i][j]+a[i][j]*b[k][j];
}
printf("\nThe resultant matrix is:\n");
for(i=0; i<m; i++)
{
for(j=0; j<q; j++)
printf("\t%d", c[i][j]);
printf("\n");
}
}
else
{
printf("\nMatrix multiplication not possible");
printf("\nColumn of A should be equal to row of B\n");
}
getch();
}

Output / Execution:
Enter the order of A matrix (m*n):
2
2
Enter the order of B matrix (p*q):
2
2
Matrix can be multiplied.
Enter the value of Matrix A:
1
3
5
7
Enter the value of Matrix B:
7
5
3
1

The resultant matrix is:
10 18
50 42


/* Addition and Subtraction of two matrix */ 
/* Program Coded By Chetan Thapa Magar */ 


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int m, n, i, j, a[10][10], b[10][10], add[10][10], sub[10][10];
printf("Enter the numbers for rows:\t");
scanf("%d", &m);
printf("\nEnter the number of columns:\t");
scanf("%d", &n);
printf("\nEnter the element of matrix A:\n");
for(i=0; i<m; i++)
for(j=0; j<n; j++)
scanf("%d", &a[i][j]);
printf("\nEnter the elements of matrix B:\n");
for(i=0; i<m; i++)
for(j=0; j<n; j++)
scanf("%d", &b[i][j]);
printf("\nThe Addition of Two Matrix is:\n");
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
add[i][j]=a[i][j]+b[i][j];
printf("%d\t", add[i][j]);
}
printf("\n");
}
printf("\nThe Subtraction of Two Matrix is:\n");
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
sub[i][j]=a[i][j]-b[i][j];
printf("%d\t", sub[i][j]);
}
printf("\n");
}
getch();
}
Output / Execution:
Enter the number of rows: 3
Enter the number of columns: 3
Enter the elements of matrix A:
1
2
3
4
5
6
7
8
9
Enter the elements of matrix B:
9
8
7
6
5
4
3
2
1
The Addition of Two Matrix is:
10 10 10
10 10 10
10 10 10

The Subtraction of Two Matrix is:
-8 -6 -4
-2  0  2
 4  6  8

COMMENTS

BLOGGER
Name

ArmedPoliceForce,5,ArmedPoliceForcePaper,1,BachelorPaper,1,BBSPaper,1,Computer,6,COVID19NEPAL,7,CProgramming,2,EPSKorea,3,ExamResults,8,ExamSchedule,4,Excel,1,Festivals,1,Hardware,1,LokSewaAayog,9,LokSewaAayogModelQuestion,2,LokSewaAayogPaper,1,ModelQuestion,3,NepalArmy,3,NepalBankLimited,2,NepalElectricityAuthority,2,NepalOilCorporation,1,NepalPolice,20,NepalPolicePaper,2,NepalRastraBank,2,NepalTelecom,1,News,23,NIDNepal,2,Notes,14,PowerPoint,1,QuestionCollection,7,RastriyaBanijyaBank,1,RealExamPaper,5,ShortcutKey,1,SocialSecurityFund,1,Syllabus,12,TipsTricks,3,TUUniversity,1,University,4,Vacancy,6,Valentine,1,Video,1,VisitNepal,3,Word,1,
ltr
item
Chetan Thapa Magar: C Programming Part 1
C Programming Part 1
C Programming Notes
https://1.bp.blogspot.com/-RGmEMG-49eA/XtCQx7D6wJI/AAAAAAAABOU/6CDCGlQx6zc-9F6FLCshm76vStbNq6pmACLcBGAsYHQ/s200/Part%2B1.jpg
https://1.bp.blogspot.com/-RGmEMG-49eA/XtCQx7D6wJI/AAAAAAAABOU/6CDCGlQx6zc-9F6FLCshm76vStbNq6pmACLcBGAsYHQ/s72-c/Part%2B1.jpg
Chetan Thapa Magar
https://www.chetanthapamagar.com.np/2020/05/c-programming-part-1.html
https://www.chetanthapamagar.com.np/
https://www.chetanthapamagar.com.np/
https://www.chetanthapamagar.com.np/2020/05/c-programming-part-1.html
true
2012862999246101061
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy