0% found this document useful (0 votes)
10 views3 pages

C Programs Solutions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

C Programs Solutions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C Programming Questions and Solutions

1) Display Pyramid Pattern

#include <stdio.h>

void displayPattern(int n) {

for (int i = 1; i <= n; i++) {

for (int j = 1; j <= i; j++)

printf("%d ", j);

for (int j = i - 1; j >= 1; j--)

printf("%d ", j);

printf("\n");

int main() {

int rows;

printf("Enter number of rows: ");

scanf("%d", &rows);

displayPattern(rows);

return 0;

2) Check Character Type

#include <stdio.h>

int main() {

char c;

printf("Enter a character: ");


scanf(" %c", &c);

if (c >= 'A' && c <= 'Z')

printf("Uppercase letter\n");

else if (c >= 'a' && c <= 'z')

printf("Lowercase letter\n");

else

printf("Special character\n");

return 0;

3) Matrix Addition

#include <stdio.h>

void readMatrix(int mat[4][4], int rows, int cols) {

for (int i = 0; i < rows; i++)

for (int j = 0; j < cols; j++)

scanf("%d", &mat[i][j]);

void printMatrix(int mat[4][4], int rows, int cols) {

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++)

printf("%d ", mat[i][j]);

printf("\n");

int main() {

int A[4][4], B[4][4], C[4][4];

int M, N, P, Q;
printf("Enter dimensions of matrix A (MxN): ");

scanf("%d %d", &M, &N);

printf("Enter dimensions of matrix B (PxQ): ");

scanf("%d %d", &P, &Q);

if (M != P || N != Q) {

printf("Addition not possible\n");

return 0;

printf("Enter elements of matrix A:\n");

readMatrix(A, M, N);

printf("Enter elements of matrix B:\n");

readMatrix(B, M, N);

for (int i = 0; i < M; i++)

for (int j = 0; j < N; j++)

C[i][j] = A[i][j] + B[i][j];

printf("Matrix A:\n");

printMatrix(A, M, N);

printf("Matrix B:\n");

printMatrix(B, M, N);

printf("Resultant Matrix C:\n");

printMatrix(C, M, N);

return 0;

You might also like