Saturday, 31 October 2015

Write A C Program To Reverse Very Large Or Big Numbers Without Using Library Function / Pointer Problem Solution.


Solution:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int my_str_len(char str[]){

    int i = 0,cnt = 0;
    while(str[i++] != '\0')cnt++;
    return cnt;
}
int main(){

    char num[1000],rem,rev[1000];

    int i,j = 0,len;
    printf("Enter any positive integer: ");
    scanf("%s",num);

    len  = my_str_len(num);
    for(i = len-1; i>= 0; i--,j++){
        if(!(num[i] >= 48 && num[i] < 58)){
            printf("Invilied Number.");
            return 0;
        }
        else{
            rev[i] = num[j];
        }
    }
    printf("\nReversed of number: %s",rev);
    return 0;
}

Write A C Program To Reverse Very Large Or Big Numbers Using Pointer Problem Solution.

/*
Definition: 
    opposite or contrary in position, direction, order, or character:
an impression reverse to what was intended; in reverse sequence.
*/

Solution:

#include <stdlib.h>
#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *

*/
int main(){

    char *num,rem,*rev;

    int i,j = 0,len;
    num = (char *) malloc(10000);
    rev = (char *) malloc(10000);

    printf("Enter any positive integer: ");
    scanf("%s",num);

    len  = strlen(num);
    for(i = len-1; i>= 0; i--,j++){
        if(!(*(num+i) >= 48 && *(num+i) < 58)){
            printf("\nInvalid Number.");
            return 0;
        }
        else{
            *(rev+i) = *(num+j);
        }
    }
    printf("\nReversed of number: %s",rev);
    return 0;
}

Write A C Program To Reverse A Given Number Using For Loop Problem Solution.

/*
Definition: 
    opposite or contrary in position, direction, order, or character:
an impression reverse to what was intended; in reverse sequence.
*/


Solution:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){
    long long num,rem,rev=0;

    printf("Enter any number: ");
    scanf("%lld",&num);

    for(;num > 0;num/=10){
         rem=num%10;
         rev=rev*10+rem;
    }
    printf("\nReversed of number: %lld",rev);
    return 0;
}

Write A C Program To Reverse A Given Number Problem Solution.

/*
Definition: 
    opposite or contrary in position, direction, order, or character:
an impression reverse to what was intended; in reverse sequence.
*/



Solution:


#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){
    long long num,rem,rev=0;

    printf("Enter any number: ");
    scanf("%lld",&num);

    while(num){
         rem=num%10;
         rev=rev*10+rem;
         num/=10;
    }
    printf("\nReversed of number: %lld",rev);
    return 0;
}

Write A C Program To Find Factorial Value In A Given Range Problem Solution.

/*
Definition Of Factorial Number:
The Result of multiplying a sequence of descending natural numbers (such as 4 * 3 * 2* 1).

Example: 4! = 4*3*2*1 = 24
7! = 7*6*5*4*3*2*1 = 5040
*/

Solution:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

  long long fac = 1;
  int i,num,min,max;

  printf("Enter The Minimum Range: ");
  scanf("%d",&min);

  printf("Enter The Maximum Range: ");
  scanf("%d",&max);

  printf("Factorial Series In Given Range: ");
  for(num = min; num <= max; num++){
    fac = 1;
    for(i=1;i<=num;i++)
      fac *= i;

    printf("%lld ",fac);
  }
  return 0;
}

Write A Program To Find Factorial Value In C Using Recursion Function Problem Solution.

/*
Definition Of Factorial Number:
The Result of multiplying a sequence of descending natural numbers (such as 4 * 3 * 2* 1).

Example: 4! = 4*3*2*1 = 24
7! = 7*6*5*4*3*2*1 = 5040
*/

Solution:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int fac_cal(int n){

    if(n== 0)return 1;
    return n*fac_cal(n-1);
}
int main(){

    long long fac=1,num;

    printf("Enter a number: ");
    scanf("%lld",&num);
    fac = fac_cal(num);

    printf("\nFactorial of %lld is: %lld",num,fac);
    return 0;
}

C Program To Find The Factorial Of A Given Number Problem Solution.

/*
Definition Of Factorial Number:
The Result of multiplying a sequence of descending natural numbers (such as 4 * 3 * 2* 1).

Example: 4! = 4*3*2*1 = 24
7! = 7*6*5*4*3*2*1 = 5040
*/


Solution:


#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    long long fac=1,num,tmp;

    printf("Enter a number: ");
    scanf("%lld",&num);
    tmp = num;
    while(tmp){
        fac*=tmp;
        tmp--;
    }
    printf("\nFactorial of %lld is: %lld",num,fac);
    return 0;
}

Write a program to find Sum of Fibonacci series In C Problem Solution.

/*
Definition of Fibonacci numbers:



We assume first two Fibonacci are 0 and 1

A series of numbers in which each sequence number is sum of its two previous numbers is known as Fibonacci series and each numbers are called Fibonacci numbers. So Fibonacci numbers is : 0 , 1 ,1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55  etc.

*/


Solution:


#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *

*/
int main(){

    int k,range;
    long long i = 0ll,j = 1ll,fib = 0,sum = 0;

    printf("Enter the number range:");
    scanf("%d",&range);

    for(k=1;k<=range;k++){

        sum+=fib;
        i=j;
        j=fib;
        fib=i+j;
    }
    printf("\nSum of Fibonacci series is: %lld ",sum);
    return 0;
}

Write A Program To Generate The Fibonacci Series In C Problem Solution.

/*
Definition of Fibonacci numbers:



We assume first two Fibonacci are 0 and 1

A series of numbers in which each sequence number is sum of its two previous numbers is known as Fibonacci series and each numbers are called Fibonacci numbers. So Fibonacci numbers is : 0 , 1 ,1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55  etc.
*/


Solution:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *

*/
int main(){

    int k,range;
    long long i = 0ll,j = 1ll,fib = 0;

    printf("Enter the number range:");
    scanf("%d",&range);

    printf("FIBONACCI SERIES: ");

    for(k=1;k<=range;k++){

        printf("%lld ",fib);
        i=j;
        j=fib;
        fib=i+j;
    }
    return 0;
}

Write A C Program To Check Given String Is Palindrome String Or Not Without Using Library Function Problem Solution.

/*
Definition of Palindrome string:

A string is called palindrome if it symmetric. In other word a string is called palindrome if string remains same if its characters are reversed. For example: asdsa
If we will reverse it will remain same i.e. asdsa

Example of string palindrome:  a,b, aa,aba,qwertrewq,madam etc.
*/

Solution:

#include<string.h>
#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){
  char str[100],rev[100];
  int i,j = 0,len;
  printf("\nEnter a string:");
  scanf("%s",str);
  len = strlen(str);

  for(i = len-1;i>=0;i--,j++)rev[j]=str[i];
  rev[j]='\0';
  int OK = 1;
  for(i = 0; i < len; i++){
      if(str[i] != rev[i]){
          OK = 0;
          break;
      }
  }
  if(OK) printf("\nThe String Is A Palindrome");
  else printf("\nThe String Is Not A Palindrome");
  return 0;
}

Write A C Program To Check Given String Is Palindrome String Or Not Problem Solution

/*
Definition of Palindrome string:

A string is called palindrome if it symmetric. In other word a string is called palindrome if string remains same if its characters are reversed. For example: asdsa
If we will reverse it will remain same i.e. asdsa

Example of string palindrome:  a,b, aa,aba,qwertrewq,madam etc.
*/

Solution:

#include<string.h>
#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

  char str[100],rev[100];
  int i,j = 0,len;
  printf("\nEnter a string:");
  scanf("%s",str);
  len = strlen(str);

  for(i = len-1;i>=0;i--,j++)rev[j]=str[i];
  rev[j]='\0';

  if(strcmp(rev,str) == 0) printf("\nThe String Is A Palindrome");
  else printf("\nThe String Is Not A Palindrome");
  return 0;
}

Write A C Program To Find Palindrome Numbers In Given Range Problem Solution.


/*
Definition:
                     A number is called palindrome number if it is remain same when its digits are reversed. For example 121 is palindrome number. When we will reverse its digit it will remain same number i.e. 121
*/

Solution:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int num,revNum = 0,tmp,mod,min,max;
    printf("Enter Minimum Range: ");
    scanf("%d",&min);

    printf("Enter Maximum Range: ");
    scanf("%d",&max);

    printf("\Between %d To %d Palindrome Numbers Are: ",min,max);
    for(num = min; num <= max; num++){

        tmp = num;
        revNum = 0;
        while(tmp!=0){
            mod = tmp%10;
            revNum=revNum*10+mod;
            tmp/=10;
        }
        if(num == revNum)printf("%d ",num);
    }
    return 0;
}

Write A C Program To Find Whether A Number Is Palindrome Or Not Problem Solution.

/*
Definition of Palindrome number:

                                                     A number is called palindrome number if it is remain same when its digits are reversed. For example 121 is palindrome number. When we will reverse its digit it will remain same number i.e. 121
*/

Solution:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int num,revNum = 0,tmp,mod;
    printf("Enter A Number: ");
    scanf("%d",&num);

    tmp = num;
    while(num!=0){
        mod = num%10;
        revNum=revNum*10+mod;
        num/=10;
    }
    if(tmp == revNum)printf("\n%d Is A Palindrome Number.",tmp);
    else printf("\n%d Is Not A Palindrome Number.",tmp);
    return 0;
}

Write A C Program To Find Sum of odd and even numbers In Given Range Problem Solution.


Solution:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int min,max,i,sum = 0;

    printf("Enter Minimum Range: ");
    scanf("%d",&min);

    printf("Enter Maximum Range: ");
    scanf("%d",&max);
    printf("\nSum Of Even numbers in given range is: ");
    for(i = min; i <= max; i++){
        if(!(i%2))sum+=i;
    }
    printf("%d ",sum);
    sum = 0;
    printf("\nSum Of Odd numbers in given range are: ");
    for(i = min; i <= max; i++){
        if((i%2))sum+=i;
    }
    printf("%d ",sum);
    return 0;
}

Write A C Program To Find Sum of Even Numbers In Given Range Problem Solution.


Solution:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int min,max,i,sum = 0;

    printf("Enter Minimum Range: ");
    scanf("%d",&min);

    printf("Enter Maximum Range: ");
    scanf("%d",&max);
    printf("\nSum Of Even numbers in given range is: ");
    for(i = min; i <= max; i++){
        if(!(i%2))sum+=i;
    }
    printf("%d ",sum);

    return 0;
}

C Program To Find Even And Odd In Given Range Problem Solution.

/*
Number is called even number if it is divisible by two otherwise odd.  

Example of even numbers: 0,2,4,8,9,10,12,14 etc.
Example of odd numbers: 1, 3,5,7,9,11,13 etc.
*/


Solution:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int min,max,i;

    printf("Enter Minimum Range: ");
    scanf("%d",&min);

    printf("Enter Maximum Range: ");
    scanf("%d",&max);
    printf("\nEven numbers in given range are: ");
    for(i = min; i <= max; i++){
        if(!(i%2))printf("%d ",i);
    }
    printf("\nOdd numbers in given range are: ");
    for(i = min; i <= max; i++){
        if((i%2))printf("%d ",i);
    }
    return 0;
}