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 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

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

Simple Program to remove Duplicate Element in an Array

Simple Program to remove Duplicate Element in an Array

Simple Program to remove Duplicate Element in an Array   #include<stdio.h> #include<conio.h> void main() { int a[20], i, j, k, n; clrscr(); printf(“\nEnter array size: “); scanf(“%d”, &n); printf(“\nEnter %d array element: “, n); for(i = 0; i < n; i++) { scanf(“%d”, &a[i]); } printf(“\nOriginal array is: “); for(i = 0; i < n; … Read more

C Program to find the Sum of First n Natural numbers using for loop

C Program to find the Sum of First n Natural numbers

C Program to find the Sum of First n Natural numbers using for loop   #include <stdio.h> int main() { int n, count, sum = 0; printf(“Enter the value of n(positive integer): “); scanf(“%d”,&n); for(count=1; count <= n; count++) { sum = sum + count; } printf(“Sum of first %d natural numbers is: %d”,n, sum); … Read more

C Program to print the Multiplication Table of any Number

multiplication table program in c

C Program to print the Multiplication Table of any Number #include<stdio.h> int main() { printf(“\n\n\t\tEduguru – C Program Example\n\n\n”); int n,i; printf(“Enter an integer you need to print the table of: “); scanf(“%d”, &n); printf(“\n\n\n”); for(i = 1; i <= 10; i++) { printf(“\n\t\t\t%d * %d = %d \n”, n, i, n*i); } printf(“\n\n\n\n\t\t\tAll Done … Read more

Program to check if input Number is int or float

pointer program example in c

Program to check if input Number is int or float #include<stdio.h> #include<conio.h> #include<string.h> int main() { printf(“\n\n\t\tEduguru – C Program example\n\n\n”); char number[10]; int flag = 0; int length, i = 0; printf(“\n\nEnter a number: “); scanf(“%s”, number); length = strlen(number); // till string does not end while(number[i++] != ‘\0’) // same as while(length–>0) { … Read more

Program to find Palindrome using Recursion

palindrome program in c

Program to find Palindrome using Recursion A Palindrome is a sequence that if reversed looks identical to the original sequence Eg : abba, level, 999 etc. #include<stdio.h> // declaring the recursive function int isPal(int ); /* global declaration to use the same value in both the functions */ int n; int main() { printf(“\n\n\t\tStudytonight – … Read more

Program to print Fibonacci Series using Recursion

fibonacci-sequence

Program to print Fibonacci Series using Recursion A Fibonacci series is defined as a series in which each number is the sum of the previous two numbers with 1, 1 being the first two elements of the series. #include<stdio.h> // declaring the function void printFibo(int ); int main() { printf(“\n\n\t\tEduguru – Recursion program in c\n\n\n”); … Read more

Program to find Factorial of a Number using Recursion

Program to find Factorial of a Number using Recursion

Program to find Factorial of a Number using Recursion #include<stdio.h> // declaring the function int fact(int); int main() { printf(“\n\n\t\tEduguru – Recursion Program Example\n\n\n”); int num, f; printf(“\n\nEnter a number: “); scanf(“%d”, &num); f= fact(num); printf(“\n\nFactorial of %d is %d\n\n”, num, f); printf(“\n\n\t\t\tCoding is Fun here !\n\n\n”); return 0; } int fact(int aj) { if(aj==1 … Read more