-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from Ayushparikh-code/Print-names-of-all-File
C Program to Print names of all Files present in a Directory
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <stdio.h> | ||
|
||
void main() | ||
{ | ||
int n, r, npr_var; | ||
|
||
printf("Enter the value of n:"); | ||
scanf("%d", &n); | ||
printf("\nEnter the value of r:"); | ||
scanf("%d", &r); | ||
|
||
/* nPr is also known as P(n,r), the formula is: | ||
* P(n,r) = n! / (n - r)! For 0 <= r <= n. | ||
*/ | ||
npr_var = fact(n) / fact(n - r); | ||
printf("\nThe value of P(%d,%d) is: %d",n,r,npr_var); | ||
} | ||
// Function for calculating factorial | ||
int fact(int num) | ||
{ | ||
int k = 1, i; | ||
// factorial of 0 is 1 | ||
if (num == 0) | ||
{ | ||
return(k); | ||
} | ||
else | ||
{ | ||
for (i = 1; i <= num; i++) | ||
{ | ||
k = k * i; | ||
} | ||
} | ||
return(k); | ||
} | ||
Output: | ||
|
||
Enter the value of n: | ||
5 | ||
Enter the value of r: | ||
2 | ||
The value of P(6,2) is: 30 |