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
68 changes: 68 additions & 0 deletions programs/C/factorial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include<stdio.h>
int main()
{
int choose = 0, n, i;
unsigned long long factorial = 1;

while (choose !=3){
factorial = 1;

printf("Type number to choose \n 1. factorial \n 2. double factorial \n 3.Exit\n Choice: ");
scanf("%d", &choose);

switch(choose){

case(1):
printf("Enter an integer: ");
scanf("%d",&n);

if (n > 0){
for(i=1; i<=n; ++i)
{
factorial *= i; //n! = n*(n-1)...
}
}
else if( n = 0){
factorial = 1; //0!=1;
}
else // show error if the user enters a negative integer
{
printf("Error! Factorial of a negative number doesn't exist.");
}
printf(" %d!= %llu\n", n, factorial);

break;

case(2):
printf("Enter an integer: ");
scanf("%d",&n);

if (n > 0){
for(i=n; i>=1; i-=2)
{
factorial *= i; //n! = n*(n-1)...
}
}
else if( n = 0){
factorial = 1; //0!=1;
}
else // show error if the user enters a negative integer
{
printf("Error! Double Factorial of a negative number doesn't exist.");
}
printf(" %d!!= %llu\n", n, factorial);

break;

case(3):
printf("Good bye!\n");

break;

default:
printf("Invalid number, please choose again.");
}

}
return 0;
}
27 changes: 27 additions & 0 deletions programs/Java/substring_string.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package substring;

import java.util.Scanner;

public class substring_string {
public static void main(String[] args) {

String stringis, substringis;
char option;
Scanner input = new Scanner(System.in);

System.out.print("Please intput a string: ");
stringis = input.nextLine();

System.out.print("Please intput a substring: ");
substringis = input.nextLine();

if (stringis.contains(substringis)) {
System.out.println(stringis + " contains " + substringis);
}
else {
System.out.println("Result no found!");
}

System.out.println("Good bye!");
}
}