Search This Blog

Showing posts with label c programming tutorial. Show all posts
Showing posts with label c programming tutorial. Show all posts

April 20, 2019

WELCOME BACK CODERS, HERE IS OUR NEW BLOG ON ADDITION OF 2 MATRIX .

IN THIS PROGRAM THE USER NEEDS TO ENTER 2 MATRIX THEN THE PROGRAM WILL ADD BOTH THE MATRIX AND DISPLAY THE RESULT.

Matrix addition in C: C program to add two matrices, i.e., compute the sum of two matrices and then print it. Firstly a user will be asked to enter the order of matrix (number of rows and columns) and then two matrices. For example, if a user input order as 2, 2, i.e., two rows and two columns and matrices as
First matrix:
1 2
3 4

Second matrix:
4 5
-1 5

then the output of the program (Summation of the two matrices) is:
5 7
2 9

CODE
#include<stdio.h>

int main()
{
int m, n, c, d, first[10][10], second[10][10], sum[10][10];

printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of first matrix\n");

for (= 0; c < m; c++)
for (= 0; d < n; d++)
scanf("%d", &first[c][d]);

printf("Enter the elements of second matrix\n");

for (= 0; c < m; c++)
for (= 0 ; d < n; d++)
scanf("%d", &second[c][d]);

printf("Sum of entered matrices:-\n");

for (= 0; c < m; c++) {
for (= 0 ; d < n; d++) {
sum[c][d] = first[c][d] + second[c][d];
printf("%d\t", sum[c][d]);
}
printf("\n");
}

return 0;
}

OUTPUT

April 20, 2019

WELCOME BACK CODERS , HOPE YOU ARE ENJOYING OUR BLOGS , WILL LOVE TO SEE YOU AGAIN ON OUR BLOGS.

leap year is a year which has 366 days. The extra day is the 29th February. There is a leap year every four years.

IN THIS PROGRAM THE USER NEEDS TO ENTER A YEAR AND THEN THE PROGRAM WILL FIND IF A GIVEN YEAR IS A LEAP YEAR.

Problem Solution
1. Take a year as input.
2. Check whether a given year is divisible by 400.
3. Check whether a given year is divisible by 100.
4. Check whether a given year is divisible by 4.
5. If the condition at step 2 and 4 becomes true, then the year is a leap year.
6. If the condition at step 3 becomes true, then the year is not a leap year.

CODE

void main()
{

int year;

printf("Enter a year \n");
scanf("%d", &year);
if ((year % 400) == 0)
printf("%d is a leap year \n", year);
else if ((year % 100) == 0)
printf("%d is a not leap year \n", year);
else if ((year % 4) == 0)
printf("%d is a leap year \n", year);
else
printf("%d is not a leap year \n", year);
}

OUTPUT

April 20, 2019

WELCOME BACK TO codejunction.in , hope you are enjoying our blogs , just give more time to check out some of our latest blogs .

IN THIS PROGRAM THE USER NEEDS TO ENTER 3 NUMBERS AND THE PROGRAM WILL FIND THE BIGGEST OF 3 NUMBERS.

Problem Solution
1. Take the three numbers as input.
2. Check the first number if it greater than other two.
3. Repeat the step 2 for other two numbers.
4. Print the number which is greater among all and exit.

CODE

#include <stdio.h>
void main()
{
int num1, num2, num3;

printf("Enter the values of num1, num2 and num3\n");
scanf("%d %d %d", &num1, &num2, &num3);
printf("num1 = %d\tnum2 = %d\tnum3 = %d\n", num1, num2, num3);
if (num1 > num2)
{
if (num1 > num3)
{
printf("num1 is the greatest among three \n");
}
else
{
printf("num3 is the greatest among three \n");
}
}
else if (num2 > num3)
printf("num2 is the greatest among three \n");
else
printf("num3 is the greatest among three \n");
}

OUTPUT