C Language : Solution - 01


1. Write a program to check number is even and odd taking input from users, using only if statement.

#include<stdio.h>

#include<conio.h>

void main()

{

int num;

printf("Enter any Number: ");

scanf("%d", &num);

if (num%2==0)

{

printf("%d is a Even Number.", num);

}

if (num%2!=0)

{

printf("%d is a Odd Number.", num);

}

getch();

}

-: Output :-


2. Write a program to add two 2x2 matrix without using an array.

#include<stdio.h>

#include<conio.h>

void main()

{

int row1, row2, row3, row4;

int col1, col2, col3, col4;

int sum1, sum2, sum3, sum4;

printf("Enter 2x2 Matrix Element...\n");

printf("Enter First Matrix Element:\n");

scanf("%d%d%d%d", &row1, &row2, &row3, &row4);

printf("Enter Second Matrix Element:\n");

scanf("%d%d%d%d", &col1, &col2, &col3, &col4);

printf("\nPrint Matrix Element...\n");

printf("Print First Matrix Element:\n");

printf("%d\t%d\n%d\t%d", row1, row2, row3, row4);

printf("\nPrint Second Matrix Element:\n");

printf("%d\t%d\n%d\t%d", col1, col2, col3, col4);

sum1 = row1 + col1;

sum2 = row2 + col2;

sum3 = row3 + col3;

sum4 = row4 + col4;

printf("\n\nAddition of 2x2 Matrix...\n");

printf("%d\t%d\n%d\t%d", sum1, sum2, sum3, sum4);

getch();

}

-: Output :-

Mj Mausam

Post a Comment

Previous Post Next Post