21 December 2023

C Program to Check a Given Number is a Armstrong or not

An Armstrong number (also known as a narcissistic number, pluperfect number, or pluperfect digital invariant) is a number that is the sum of its own digits each raised to the power of the number of digits. For example, 153 is an Armstrong number . Here’s a simple C program to check if a given number is an Armstrong number: Program : #include<stdio.h>#include<conio.h>void main(){int a,n,b=0,t;printf(“Enter the number : “);scanf(“%d”,&n);t=n;while(n>0){a=n%10;b=b+a*a*a;n=n/10;}if(b==t){printf(“%d is a Armstrong Number.”,t);}else{printf(“%d is not an Armstrong Number.”,t);}} Output :

C Program to Check a Given Number is a Armstrong or not Read More »

C Program to Implements Matrix Calculation

Below is a simple C program that creates a menu-driven program to implement matrix addition, subtraction, and multiplication. This program assumes that the matrices are square matrices of the same size for addition and subtraction, and suitable for matrix multiplication. Program : #include<stdio.h> #include<conio.h>   int sum(int x[100][100], int y[100][100], int result[100][100], int v, int q) { int i,j; for(i=0;i<v;i++)     for(j=0;j<q;j++)     result[i][j] = x[i][j] + y[i][j]; } int sub(int x[100][100], int y[100][100], int result[100][100], int v, int q) { int i,j; for(i=0;i<v;i++)     for(j=0;j<q;j++)     result[i][j] = x[i][j] – y[i][j]; } int mul(int x[100][100], int y[100][100], int result[100][100], int v, int q) { int i,j; for(i=0;i<v;i++)     for(j=0;j<q;j++)     result[i][j] = x[i][j] * y[i][j]; } void display(int matrix[100][100], int v, int q) { int i,j;   for( i=0; i<v; i++)   {     for( j=0; j<q; j++)       printf(“%d\t”,matrix[i][j]);       printf(“\n”);   } } int main() {   int r, c, d[100][100], a[100][100], b[100][100], e[100][100], i, j, z, choice;   printf(“Enter the number of rows (between 1 and 100): “);   scanf(“%d”, &r);   printf(“Enter the number of columns (between 1 and 100): “);   scanf(“%d”, &c);     printf(“\nEnter elements of 1st matrix:\n”);   for (i = 0; i < r; ++i)   {     for (j = 0; j < c; ++j)  {       printf(“Enter element a%d%d: “, i + 1, j + 1);       scanf(“%d”, &a[i][j]);     }   }     printf(“Enter elements of 2nd matrix:\n”);   for (i = 0; i < r; ++i)   {     for (j = 0; j < c; ++j)  {       printf(“Enter element b%d%d: “, i + 1, j + 1);       scanf(“%d”, &b[i][j]);     }   }     printf(“\nChoose the matrix operation,\n”);     printf(“—————————-\n”);     printf(“1. Addition\n”);     printf(“2. Subtraction\n”);     printf(“3. Multiplication\n”);     printf(“—————————-\n”);     printf(“Enter your choice: “);     scanf(“%d”, &choice);       switch (choice) {       case 1:         sum(a, b, d, r, c);         printf(“Sum of matrix: \n”);         display(d, r, c);         break;       case 2:         sub(a, b, d, r, c);         printf(“Subtraction of matrix: \n”);         display(d, r, c);         break;       case 3:         mul(a, b, d, r, c);         printf(“Multiplication of matrix: \n”);         display(d, r, c);         break;       default:         printf(“Invalid input.\n”);         printf(“Please enter the correct input.\n”);    } } Output :

C Program to Implements Matrix Calculation Read More »

C Program to Count Each Elements In Array

Below is a simple C program that counts the occurrences of each element in an array. This program takes an array as input from the user, counts the occurrences of each element, and then prints the count for each unique element in the array. It uses a nested loop to iterate through the array and count occurrences. Program : #include <stdio.h>int main(){int arr[100], freq[100];int size, i, j, count;printf(“Enter size of array: “);scanf(“%d”, &size);printf(“Enter elements in array: “);for(i=0; i<size; i++){scanf(“%d”, &arr[i]);freq[i] = -1;}for(i=0; i<size; i++){count = 1;for(j=i+1; j<size; j++){if(arr[i]==arr[j]){count++;freq[j] = 0;}}if(freq[i] != 0){freq[i] = count;}}printf(“\nFrequency of all elements of array : \n”);for(i=0; i<size; i++){if(freq[i] != 0){printf(“%d occurs %d times\n”, arr[i], freq[i]);}}return 0;} Output :

C Program to Count Each Elements In Array Read More »

Shopping Basket
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare
Verified by MonsterInsights