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

ArmedPolice ForcePaper,1,ArmedPoliceForce,3,BachelorPaper,1,BBSPaper,1,Computer,3,COVID19NEPAL,7,EPSKorea,3,ExamResults,6,ExamSchedule,6,Festivals,1,LokSewaAayog,7,LokSewaAayog ModelQuestion,1,LokSewaAayogModelQuestion,1,LokSewaAayogPaper,1,ModelQuestion,2,MSExcel,1,MSPowerPoint,1,MSWord,1,NepalArmy,3,NepalBankLimited,2,NepalElectricityAuthority,2,NepalOilCorporation,1,NepalPolice,19,NepalPolicePaper,2,NepalRastraBank,2,NepalTelecom,1,News,15,NIDNepal,2,Notes,12,QuestionCollection,7,RastriyaBanijyaBank,1,RealExamPaper,5,ShortcutKey,1,SocialSecurityFund,1,Syllabus,12,TipsTricks,3,TUUniversity,1,Vacancy,6,Valentine,1,Video,1,VisitNepal,3,
ltr
item
Online Khabar Nepal: 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
Online Khabar Nepal
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 PostsNot found any postsVIEW ALLReadmoreReplyCancel replyDeleteByHomePAGESPOSTSView AllRECOMMENDED FOR YOULABELARCHIVESEARCHALL POSTSNot found any post match with your requestBack HomeSundayMondayTuesdayWednesdayThursdayFridaySaturdaySunMonTueWedThuFriSatJanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecemberJanFebMarAprMayJunJulAugSepOctNovDecjust now1 minute ago$$1$$ minutes ago1 hour ago$$1$$ hours agoYesterday$$1$$ days ago$$1$$ weeks agomore than 5 weeks agoFollowersFollowTHIS PREMIUM CONTENT IS LOCKEDSTEP 1: Share to a social networkSTEP 2: Click the link on your social networkCopy All CodeSelect All CodeAll codes were copied to your clipboardCan not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copyTable of Content