Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions calc_nPr.c
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
29 changes: 29 additions & 0 deletions vowel&const.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
int main()
{
char str[100];
char *p;
int vCount=0,cCount=0;

printf("Enter any string: ");
fgets(str, 100, stdin);

//assign base address of char array to pointer
p=str;

//'\0' signifies end of the string
while(*p!='\0')
{
if(*p=='A' ||*p=='E' ||*p=='I' ||*p=='O' ||*p=='U'
||*p=='a' ||*p=='e' ||*p=='i' ||*p=='o' ||*p=='u')
vCount++;
else
cCount++;
//increase the pointer, to point next character
p++;
}

printf("Number of Vowels in String: %d\n",vCount);
printf("Number of Consonants in String: %d",cCount);
return 0;
}