Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- #define ll long long int
- ll fact(ll n)
- {
- ll i,s=1;
- for(i=2; i<=n; i++)
- s*=i;
- return s;
- }
- ll prime(ll n)
- {
- ll i,j;
- if(n==1)
- return 0;
- else if(n%2==0 && n!=2)
- return 0;
- else
- {
- for(i=3; i*i<=n; i+=2)
- {
- if(n%i==0 && n!=i)
- return 0;
- }
- }
- return 1;
- }
- ll gcd(ll a,ll b)
- {
- while(a!=b)
- {
- if(a>b)
- a-=b;
- else
- b-=a;
- }
- return a;
- }
- int main()
- {
- ll m,n,q;
- char t;
- printf("============================================================================\n================================ | WELCOME | ===============================\n============================================================================\n");
- printf("1 | Type 'F/f' and press enter for Calculating factorial\n2 | Type 'P/p' and press enter to check if the number is prime\n3 | Type 'G/g' and press enter for Calculating GCD of 2 numbers\n");
- printf("5 | Type anything and press enter to exit\n============================================================================\n");
- while(1)
- {
- scanf("%c",&t);
- if(t=='F' || t=='f')
- {
- printf("Give a input for Calculating Factorial\n");
- scanf("%lld",&n);
- printf("Factorial Of %lld is : %lld\n",n,fact(n));
- }
- else if(t=='P' || t=='p')
- {
- printf("Give a input for checking If it is prime\n");
- scanf("%lld",&n);
- if(prime(n))
- printf("%lld Is a Prime Number\n",n);
- else
- printf("%lld is not a Prime number\n",n);
- }
- else if(t=='G' || t=='g')
- {
- printf("Give 2 inputs for both numbers\n");
- scanf("%lld %lld",&n,&m);
- printf("GCD of %lld %lld is : %lld\n",n,m,gcd(n,m));
- }
- else
- {
- printf("HAPPY CODING :)\n");
- break;
- }
- getchar();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment