C Programming

C Program to Execute a Pointer Program.

In C programming, a pointer is a variable that stores the memory address of another variable. Pointers are powerful and flexible features in C, allowing direct manipulation of memory and providing a way to implement dynamic memory allocation. Here are some key concepts related to pointers: Pointers require careful use to avoid common pitfalls like segmentation faults and undefined behavior. Memory management and pointer arithmetic should be done with caution to ensure the stability and correctness of your programs. Program : #include<stdio.h>#include<conio.h>main(){int a;int *pointer=&a;printf(“Enter the value of a : “);scanf(“%d”,&a);printf(“\nThe value of a is : %d”,a);printf(“\nThe address of a is : %x”,&a);printf(“\nThe value of pointer is : %x”,pointer);printf(“\nThe address of pointer is : %x”,&pointer);getch();} Output :

C Program to Execute a Pointer Program. Read More »

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 »

C Program to Find the Duplicate Elements in an Array

To find duplicate elements in an array using a C program,you can use nested loops or hash sets. I’ll provide you with a simple example using nested loops. Here’s a sample program. Program : #include<stdio.h>#include<conio.h> void main(){int i,arr[20],j,no; printf(“Enter size of array: “);scanf(“%d”,&no);printf(“Enter any %d elements in array: “,no);for(i=0;i<no;i++){scanf(“%d”,&arr[i]);}printf(“Duplicate elements are: “);for(i=0; i<no; i++){for(j=i+1;j<no;j++){if(arr[i]==arr[j]){printf(“%d\n”,arr[i]);}}}getch();} Output :

C Program to Find the Duplicate Elements in an Array Read More »

C Program to Reverse an Array Elements

Reversing an array in C involves swapping the elements of the array in a way that the first element becomes the last, the second becomes the second-to-last, and so on. Here’s a simple C program that reverses an array Program : #include<stdio.h>void main(){int i,length;printf(“Enter the Length of array : “);scanf(“%d”,&length);int arr[length];printf(“Enter elements into the array:”);for(i=0;i<length;i++){printf(“arr[%d] :”,i);scanf(“%d”,&arr[i]);}printf(“\nOriginal array: \n”); for ( i = 0; i < length; i++) { printf(“%d “, arr[i]); } printf(“\nArray in reverse order: \n”); for ( i = length-1; i >= 0; i–) { printf(“%d “, arr[i]); } return 0; } Output :

C Program to Reverse an Array Elements 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