GCD (Greatest Common Divisor) of 2 numbers using Recursion C program

This program displays the GCD ( Greatest Common Divisor) of 2 numbers using Recursion. This is a part of Mumbai University MCA Colleges C Program MCA





#include<stdio.h>
#include<conio.h>

void main()
{
           int gcd(int num1,int num2,int n);
           int num2,num1,n,ans;
           clrscr();

           printf("\n Enter two numbers");
           scanf("%d %d",&num1,&num2);

           if(num1> num2)                         /* select the limit for the divisor */
                    n=num1/2;
           else
                    n=num2/2;

           ans=gcd(num1,num2,n);
           printf("GCD of %d and %d is %d",num1,num2,ans);
           getch();
}

int gcd(int num1,int num2,int n)
{
     if(n==1)                      /*if divisor is 1 */
           return(1);
    else
    {                                   /* find if n divides both the numbers */
         if(num1%n==0 && num2%n==0)
                return(n);
        else                            /*check the numbers with next values */
                 gcd(num1,num2,(n-1));
  }
}



OUTPUT:

Enter two numbers           36         45

GCD of 36 and 45 is 9




Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

C Program Decimal to Binary Fraction Conversion

This programs calculates the Decimal fraction equivalent of a Decimal number using Array. This is a part of Mumbai University MCA Colleges C Programs MCA Sem 1


#include<stdio.h>
#include<conio.h>
void main()
{
double z,doub,r,n,count=0,i=0,frac;
int num,p,ar[100];
clrscr();
printf("Enter the number to convert");
scanf("%lf",&doub);
num=doub;
frac=doub-num;
while(num!=0)
{
ar[i]=num%2;
num=num/2;
i++;
count++;
}

printf("The Binary form of this number is ");
for(i=(count-1);i>=0;i--)
{
printf("%d",ar[i]);
}
printf(".");
while(frac!=0)
{
z=frac*2;
p=z;
frac=z-p;
printf("%d",p);
}
getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

C program calculate seconds from days

This program calculates the number of days in a given date. This is a part of Mumbai University MCA Colleges C programs MCA Sem 1


#include<stdio.h>
#include<conio.h>
void main()
{
int y,m,d;
long float sec,total;
clrscr();
printf("Enter the year");
scanf("%d",&y);
printf("Enter the month");
scanf("%d",&m);
printf("Enter the days");
scanf("%d",&d);
total=(365*y)+(30*m)+d;
sec=total*24*60*60;

printf("The number of seconds is %lf",sec);
getch();
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

C program Compound interest using simple interest

This program calculates the  Compound interest using simple interest function. This is a part of Mumbai University MCA Colleges C Program MCA Sem 1


#include<stdio.h>
#include<conio.h>
double simpint(double,double);
void main()
{
double p,amt,r,n;
int i;
clrscr();
printf("Enter the principle amount\n");
scanf("%lf",&p);
printf("Enter the rate of interesnt\n");
scanf("%lf",&r);
printf("Enter the years\n");
scanf("%lf",&n);

for(i=1;i<=n;i++)
{
amt=simpint(p,r);
p=p+amt;
}
printf("The compund interest after %lf years is %lf",n,p);
getch();
}
double simpint(double p,double r)
{
return((p*r)/100);
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

C program percent-grade of students.

This C program finds the percentage of students marks and classifies them according to percentage. This is a part of Mumbai University MCA Colleges C programs MCA Sem 1


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float m1,m2,m3;
float per;
printf("Enter the marks of three subjects out of 100");
scanf("\n %f %f %f",&m1,&m2,&m3);
if(m1<0 || m2<0 || m3<0)
{
printf("Marks cant be negetive");
}
else
{
if(m1<35 || m2<35 || m3<35)
{
printf("You have failed");
}
else
{
per=(m1+m2+m3)/3;
if(per>=75)
{
printf("You got distinction with %f percentage",per);
}
else if (per>=60)
{
printf("You got a 1st class with %f percentage",per);
}
else if(per>=45)
{
printf("You got 2nd class with %f percentage",per);
}
else
{
printf("You got pass class with %f percentage",per);
}
}
}
getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

C program binary fraction to decimal conversion

This program converts a Binary Fraction to a Decimal Fraction. This is a part of Mumbai University MCA Colleges C Programs MCA Sem 1


#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
clrscr();
double ans,bin,frac,fun=0.0,a;
int sum=0,dec,i=0,rem,b,j=1;
printf("\nEnter the Binary number");
scanf("%lf",&bin);
dec=bin;
frac=bin-dec;
while(dec!=0)
{
rem=dec%10;
dec=dec/10;
sum=sum+(rem*pow(2,(i++)));
}
while(frac!=0.000)
{
a=10*frac;
b=a;
fun=fun+(b*(1/pow(2,(j++))));
frac=a-b;
}
ans=sum+fun;
printf("\nThe decimal equivalent is %lf",ans);
getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

C program Binary to Decimal conversion

This Program converts a Binary number to a decimal number. This is a part of Mumbai University MCA Colleges C program MCA Sem 1


#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
clrscr();
int sum=0,bin,i=0,rem;
printf("\n Enter binary number:");
scanf("%d",&bin);
while(bin!=0)
{
rem=bin%10;
bin=bin/10;
sum=sum+(rem*pow(2,(i++)));
}
printf("\nThe decimal equivalent is %d",sum);
getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

C program replace vowel in string


This C program accepts a string of min 15 characters. Replace all the vowels in the string with the character ‘*’. Do not use any standard library function. This is a part of Mumbai University MCA Colleges C Program MCA Sem 1


#include<stdio.h>
#include<conio.h>
void main()
{
char st1[50];
int i;
clrscr();
printf("Enter any string");
scanf("%s",st1);
while(s1[i]!=’\0’)
{
len++l
i++;
}
if(len<=15)
printf(“Plz, Enter more than 15 characters”);
else
{
for(i=0;i<15;i++)
{
if(st1[i]=='a' || st1[i]=='e' || st1[i]=='i' || st1[i]=='o' || st1[i]=='u' || st1[i]==’A’ || st1[i]==’E’ || st1[i]==’I’ || st1[i]==’O’ || st1[i]==’U’)
{
st1[i]='*';
}
}
}
printf("\n After replacing vowels by * string will be %s",st1);
getch();

}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Decimal to Binary Conversion using Recursion

This program converts the Decimal number to Binary Using Recursion. This is a part of Mumbai University MCA Colleges C Program MCA





#include<stdio.h>
#include<conio.h>
void main()
{
int n;
void convert(int num);
clrscr();

printf("Enter the decimal integer : ");
scanf("%d",&n);

printf("Binary equivalent is : ");
convert(n);
getch();
}


void bin_convert(int num)
{
int r;
if(num>0)
{
r=num%2;
num=num/2;
convert(num);
printf("%d",r);
}
}





OUTPUT:

Enter the decimal integer:       9

Binary equivalent is:    1001


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

String Reverse using Recursion C Program


This program is for Reversing a String Using Recursion. This is a part of Mumbai University MCA Colleges C Program and Data Structure MCA





#include<stdio.h>
#include<conio.h>
void revstring(char[],int);

void main()
{
          char str[20];
          clrscr();
         
          /* accept a string from the user */
          printf("\n Enter the string\n");
          fflush(stdin);
          gets(str);
 
          /*print the original string */
          printf("\n original string: %s\n",str);

          printf("\n Reversed string: ");
          revstring(str,0);
          getch();
 }

void revstring(char str[],int n)
{
          /* check for null string */
          if(str[n]=='\0')
                   return;

          revstring(str,n+1);
          printf("%c",str[n]);
}






OUTPUT:

Enter the string:       Data Structures

Original String:         Data Structures

Reversed String:       serutcurtS ataD



Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.