C program to display the odd digits present in integer

C program to display the odd digits present in integer

C program to display the odd digits present in integer Odd number can not be divided by 2. The remainder after dividing an Odd number by 2 is one. For example . . . Odd digits of number 6547 are 5 and 7. #include<stdio.h> int main(){ int num,rem,odd=0,digit; printf(”  Enter an integer number: “); scanf(“%d”,&num); … Read more

C program to print diamond pattern

C Programming Tutorial

C program to print diamond pattern #include <stdio.h> int main() { int i, j, rows, space = 1; printf(“Please enter number of rows you want to see in half Diamond\n”); scanf(“%d”, &rows); printf(“Diamond pattern:\n”); space = rows – 1; for (j = 1; j <= rows; j++) { for (i = 1; i <= space; … Read more

C Program to convert uppercase string to lowercase string

C Program to convert uppercase string to lowercase string

C Program to convert uppercase string to lowercase string Program Logic: The logic we have used in the program is: All the upper case characters (A-Z) have ASCII value ranging from 65 to 90 and their corresponding lower case characters (a-z) have ASCII value 32 greater than them. For example ‘A‘ has a ASCII value … Read more

C Program to Print names of all Files present in a Directory

C Program to Print names of all Files present in a Directory

C Program to Print names of all Files present in a Directory dirent.h header file contains variables and functions related to directory streams. #include<stdio.h> #include<dirent.h> int main(void) { DIR *d; struct dirent *dir; d = opendir(“.”); if (d) { while ((dir = readdir(d)) != NULL) { printf(“%s\n”, dir->d_name); } closedir(d); } return(0); } Output: testFile1.txt testFile2.txt … Read more

C Program to Swap Two Numbers using Pointers

Selection-sort-swapping

C Program to Swap Two Numbers using Pointers #include<stdio.h> int main() { printf(“\n\n\t\tEduguru – C Program Example\n\n\n”); int a, b; int *ptra, *ptrb; int temp; printf(“Enter value for a: “); scanf(“%d”, &a); printf(“\n\nEnter value for b: “); scanf(“%d”, &b); printf(“\n\nThe values before swapping are: a = %d b = %d”, a, b); ptra = &a; … Read more

C Program for Dynamic Memory Allocation using malloc()

C Program for Dynamic Memory Allocation

C Program for Dynamic Memory Allocation using malloc() Below is a program on dynamic memory allocation using malloc() and clearing out memory space using free(). sizeof() returns the number of bytes occupied by any datatype, in this case by an integer. #include <stdio.h> int main() { printf(“\n\n\t\tEduguru – C Program Example\n\n\n”); int n, i, *ptr, sum = 0; printf(“\n\nEnter … Read more

Basic C Program for Pointers

basic program of pointer

Basic C Program for Pointers #include <stdio.h> int main() { printf(“\n\n\t\tEduguru – C program example\n\n\n”); int var = 24; // actual variable declaration int *p; p = &var; // storing address of int variable var in pointer p printf(“\n\nAddress of var variable is: %x \n\n”, &var); // address stored in pointer variable printf(“\n\nAddress stored in … Read more

C Program to find Deteminant of 2×2 Matrix

matrix program in c

C Program to find Deteminant of 2×2 Matrix #include<stdio.h> int main() { printf(“\n\n\t\tEduguru – C Program example\n\n\n”); int a[2][2], i, j; long determinant; printf(“\n\nEnter the 4 elements of the array\n”); for(i = 0; i < 2; i++) for(j = 0; j < 2; j++) scanf(“%d”, &a[i][j]); printf(“\n\nThe entered matrix is: \n\n”); for(i = 0; i … Read more

C Program to perform addition and subtraction of Matrices

C Program to perform addition and subtraction of Matrices

C Program to perform addition and subtraction of Matrices #include<stdio.h> int main() { printf(“\n\n\t\Eduguru- C Program example\n\n\n”); int n, m, c, d, first[10][10], second[10][10], sum[10][10], diff[10][10]; printf(“\nEnter the number of rows and columns of the first matrix \n\n”); scanf(“%d%d”, &m, &n); printf(“\nEnter the %d elements of the first matrix \n\n”, m*n); for(c = 0; c … Read more