C Program to find nth term of the series using recursion

C Program to find nth term of the series using recursion

#include
int get_term(int x);

int main()
{
    int n,p;
    printf("Enter which term do you want?\n");
    scanf("%d",&n);
    p=get_term(n);
    printf("T(%d) = %d\n",n,p);
    return 0;
}

int get_term(int x)
{
    int term;
    if(x==1)
      term=2;
    else
      term= get_term(x-1) + 1;
    return term;
}

Related Links :

C Program to create Diamond of Asterisk (*)

C Program to create Diamond of Asterisk (*)


Diamond Shape in C Language | C Program to create Diamond of Dollar or Asterisk| Using for loop create Asterisk Diamond Shape 

#include
main()
{
    int j,i,k,l;
    char c;
    do
    {
        printf("Enter the number of stars in the base..\n");
        scanf("%d",&k);
        for (i=1;i<=k;i++)
        {
            for(l=0;l<(k-i);l++)
                printf(" ");
            for (j=0;j<i;j++)
                printf ("$ ");
            printf("\n");
        }
        for (i=1;i<=k;i++)
        {
            for(l=0;l<i;l++)
                printf(" ");
            for (j=1;j<=k-i;j++)
                printf ("$ ");
            printf("\n");
        }
        printf("\n Enter y to try more...press any other key exit program...\t");
        c=getchar();
        c=getchar();
    }
    while(c=='y');
} 


Related Links :

C Program to create ABCD triangle

C Program to create ABCD triangle 


Triangle of ABCD in C Language using Loop Control | Triangle of Alphabets in C language |
#include
main()
{
    char z;
    int j,i,k;
    printf("Enter the number of rows..(Between 1 to 26)\n");
    scanf("%d",&k);
    if(k<1||k>26)
    {
        printf("\n The number entered was not in range of 1 to 26\n"); //For Validation
        printf("exiting...\n");
        exit(0);
    }
    //If Proper Input given by user...
    printf("\n\n");
    for (i=1;i<=k;i++)
    {
        z = 'A';
        for (j=0;j<i;j++)
        {    
            printf ("%c  ",z);
            z++;
        }
    printf("\n\n");
    }
}

Related Links :

C++ program to Insert and Delete element of an array

Write a program to Insert and Delete element of an array


C++ program to Insert and Delete element of an array | Add Elements in Given Array | Run time Array Size Input 



    #include
    #include
    void main()
    {
    clrscr();
    int a[100],i,pos,num,item,size;
    cout<<"How many element: ";
    cin>>size;
    cout<<"Enter the elements of array: "<>a[i];
    cout<>num;
    cout<<"Enter position number: ";
    cin>>pos;
    cout<=pos;i--)
    a[i+1]=a[i];
    a[pos]=num;
    size++;
    cout<<"New Array: "<>pos;
    --pos;
    item=a[pos];
    for(i=pos;i


Related Links :

C program to find area of a circle

C++ program to find area of a circle 


Area of Circle in C++ | C Assignment to Find area of Circle | Calculate area of Circle when radius is given as input in C++ language



    #include 
    #include 
    void main()
    {
    clrscr();
    float r,a;
    cout<<"enter radius ";
    cin>>r;
    a=3.14*r*r;
    cout<<"The area is "<

Related Links :

Digital clock in VHDL

Digital clock in VHDL  | VHDL Digital Clock Program 


Program to create digital clock in VHDL, Source Code to create digital clock in VHDL



library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity digi_clk is
port (clk1 : in std_logic;
      seconds : out std_logic_vector(5 downto 0);
      minutes : out std_logic_vector(5 downto 0);
      hours : out std_logic_vector(4 downto 0)
     );
end digi_clk;

architecture Behavioral of digi_clk is
signal sec,min,hour : integer range 0 to 60 :=0;
signal count : integer :=1;
signal clk : std_logic :='0';
begin
seconds <= conv_std_logic_vector(sec,6);
minutes <= conv_std_logic_vector(min,6);
hours <= conv_std_logic_vector(hour,5);

 --clk generation.For 100 MHz clock this generates 1 Hz clock.
process(clk1)
begin
if(clk1'event and clk1='1') then
count <=count+1;
if(count = 50000000) then
clk <= not clk;
count <=1;
end if;
end if;
end process;

process(clk)   --period of clk is 1 second.
begin

if(clk'event and clk='1') then
sec <= sec+ 1;
if(sec = 59) then
sec<=0;
min <= min + 1;
if(min = 59) then
hour <= hour + 1;
min <= 0;
if(hour = 23) then
hour <= 0;
end if;
end if;
end if;
end if;

end process;

end Behavioral;

Related Links :

C program of Newton Raphson Method

C program of Newton Raphson Method



#include
#include
#include
#include

int bigval,i=0,cnt=0,flag=0;
int coef[10]={0};
float x1=0,x2=0,t=0;
float fx1=0,fdx1=0;

int main()
{

   
    printf("\n\n\t C PROGRAM FOR THE NEWTON RAPHSON METHOD");
    printf("\n\n\n\t PLEASE ENTER THE MAXIMUM POWER OF X = ");
    scanf("%d",&bigval);

    for(i=0;i<=bigval;i++)
    {
        printf("\n\t x^%d = ",i);
        scanf("%d",&coef[i]);
    }

    printf("\n");

    printf("\n\t So, THE POLYNOMIAL IS "= ");
    for(i=bigval;i>=0;i--)/*printing coefficients*/
    {
        printf(" %dx^%d",coef[i],i);
    }

    printf("\n\n\tFirst approximation x1 ----> ");
    scanf("%f",&x1);

 
     printf("\n ITERATION \t x1 \t F(x1) \t \tF'(x1)  ");


    do
    {
            cnt++;
            fx1=fdx1=0;
            for(i=bigval;i>=1;i--)
            {
                fx1+=coef[i] * (pow(x1,i)) ;
            }
            fx1+=coef[0];
            for(i=bigval;i>=0;i--)
            {
                fdx1+=coef[i]* (i*pow(x1,(i-1)));
            }
            t=x2;
            x2=(x1-(fx1/fdx1));

            x1=x2;

            printf("\n\t %d \t%.3f \t %.3f\t\t%.3f ",cnt,x2,fx1,fdx1);

    }
 while((fabs(t - x1))>=0.0001);
    printf("\n\n\n\t AND.... THE ROOT OF EQUATION IS = %f",x2);
    getch();
}



Related Links :

String concatenation in c without using strcat Function

String concatenation in c without using strcat Function 



void stringConcat(char[],char[]); 
int main()
{
char strl[100],str2[100]; 
int compare;
printf("\nEnter first string: \n"); 
scanf("%s",strl);
printf("\nEnter second string: "); 
scanf("%s",str2);

stringConcat(strl,str2);
printf("\nString after concatenation: %s",strl);
return 0; 
}


void  stringConcat(char   strl[],char   str2[])
{ 
int   i=0,j=0;
while(strl[i]!='\0')
{
i++; 
}
while(str2[j] ! = '\0') 
{
strl[i] = str2[j] ;
i++;
j++;
}

strl[i] = ' \0';
}

Related Links :

C Program to convert string into ASCII values

C Program to convert string into ASCII values

 

#include
int main()
{
char str[100]; 
int i=0;
printf("Enter any string: \n"); 
scanf("%s",str);
printf("\nASCII values of each characters of given string: "); 
while(str[i])
printf("%d ",str[i++]);
return 0; 
}

Related Links :

C Program to Calculating Area of Circle using Pointer

C Program to Calculating Area of Circle using Pointer



#include

void areaperi ( int r, float *a, float *p )
{
*a = 3.14 * r * r ;
*p = 2 * 3.14 * r ;
}

void main( )
{
int radius ;
float area, perimeter ;

printf ( "\n Enter radius of a circle " ) ;
scanf ( "%d", &radius ) ;

areaperi ( radius, &area, &perimeter ) ;

printf ( "The Area is = %f", area ) ;
printf ( "\n The Perimeter = %f", perimeter ) ;
}

Related Links :

C Program to Calculate Area of Equilateral Triangle

C Program to Calculate Area of Equilateral Triangle

  • Equilateral triangle is a triangle in which all three sides are equal .
     
  • All angles are of measure 60 degree
     
  • A three-sided regular polygon
#include
#include
#include
void main()
{
int side;
float area,r_4;      // r_4 = root 3 / 4
clrscr();  // Clear Screen

r_4 = sqrt(3) / 4 ;

printf("\n Please Enter the Length of Side : "); 
scanf("%d",&side); 

area = r_4 * side * side ;

printf("\n The Area of Equilateral Triangle : %f",area);
getch();
}

Related Links :

C Program To find equivalent capacitance of series combination of capacitive circuit

C Program To find equivalent capacitance of series combination of capacitive circuit


#include
#include

void main()
{
float c[10],num,Cs=0;
int i;
clrscr();

printf("Enter the number of Capacitors : ");
scanf("%f",&num);

printf("\nEnter Value of Each Capacitor : \n");
for(i=0;i<num;i++)
   {
   printf("\nC%d : ",i+1);
   scanf("%f",&c[i]);
   }

for(i=0;i<num;i++)
   {
   Cs = Cs + (1.0/c[i]);
   }
   Cs = 1.0 / Cs;

printf("\nEquivalent Series Capacitance : %f mFarad",Cs);

getch();
}



Related Links :

C Program to Calculate Area of Rectangle

C Program to Calculate Area of Rectangle


#include
#include

void main()
{
int length,breadth,side;
clrscr();  // Clear Screen

printf("\n Enter the Length of Rectangle : "); 
scanf("%d",&length); 

printf("\n Enter the Breadth of Rectangle : "); 
scanf("%d",&breadth); 

area = length * breadth;

printf("\n Area of Rectangle : %d",area);
getch();
}


Related Links :

C program to find Hexadecimal equivalent using pointer

C program to find Hexadecimal equivalent using pointer



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

void main()
{
 int num,rem[20],*ptr;
 clrscr();
 printf("\nEnter number:");
 scanf("%d",&num);
 ptr=rem;
 while(num!=0)
 {
  *ptr=num%16;
  num=num/16;
  ptr++;
 }
 ptr--;
 while(ptr>=rem)
 {
  if(*ptr < 10)
   printf("%d",*ptr);
  else
   printf("%c",*ptr+55);
   ptr--;
 }
}


Related Links :

C Program to Check whether given string is palindrome or not

C Program to Check whether given string is palindrome or not


If we reverse of any string is equivalent to the original string then it is called palindrome String. 

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

int palin(char str[],int i,int j);
void main()
{
 char str[100];
 int i,j,reply; 
 clrscr();
 printf("\n Enter a string \n");
 gets(str);
 j = 0;
 while ( str[j] != '\0')
 {
  j++;
 } // while
 j--;
 i=0;
 reply = palin(str,i,j);
 if( reply == 0 )
  printf("\n %s is not palindrome",str);
 else
  printf("\n %s is palindrome",str);
}

int palin(char str[],int i,int j)
{
 if (i < j )
 {
  if ( str[i] != str[j])
   return(0);
  else
   return(palin(str,i+1,j-1));
 }
 else
  return(1);
} 


Related Links :

C Program to Convert binary number to decimal

C Program to Convert binary number to decimal 


binary number to decimal number conversion in C, C assignment to convert Binary to Decimal, Number convention in C language.


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

void main()
{
 long n,dec,mult,r,base; 
 clrscr();
 printf("\n Enter a base : ");
 scanf("%ld",&base);
 printf("\n Enter a number :");
 scanf("%ld",&n); 
 dec = 0;
 mult=1;
 printf("\n Decimal equivalent of base %ld number %ld is ",base,n);
 while ( n != 0 )
 {
  r = n % 10;
  n /= 10;
  r = r * mult;
  dec = dec + r;
  mult *= base;
 } // while
 printf("%ld",dec);
}
 

Related Links :

C Program to Reverse number using pointer initialization

C Program to Reverse number using pointer initialization



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

void main()
{
    long *np,*revp,n,rev,*np1,n1;
    clrscr();
    np=&n;
    revp=&rev;
    np1=&n1;
    printf("\nEnter value for n:");
    scanf("%ld",np);
    *revp=0;
    *np1=*np;
    while(*np!=0)
    {
        *revp=*revp*10+(*np%10);
        *np=*np/10;
    }
    printf("\n Reverse of %ld is %ld",*np1,*revp);
}

Related Links :

C program to Find the GCD (Greatest Common Divisor) of two numbers

C program to Find the GCD (Greatest Common Divisor) of two numbers

GCD of Numbers in C, C Assignment to find GCD in C, C Language program to find GCD




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

void main()
{
int x,y;
clrscr();
printf("\nEnter two numbers :");
scanf("%d %d",&x,&y);
if(x==0 && y==0)
printf("\n No GCD");
else
if(x==0 && y!=0)
printf("GCD is %d",y);
else
if(x!=0 && y==0)
printf("GCD is %d",x);
else
{
while(x!=y)
{
if(x>y)
x=x-y;
else
if(x < y)
y=y-x;
}
printf("\n GCD is %d",x);
}
}

Related Links :

C Program to Find the maximum element of array

C Program to Find the maximum element of array | C Program to find largest element from array | Program to Find highest value from given array in C language




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

void main()
{
int a[100],max,i,n;
clrscr();
printf("Enter the size of an array\n");
scanf("%d",&n);
printf("Enter the elements %d for array\n", n);
for(i=0;i < n;i++)
{
scanf("%d",&a[i]);
}
max=a[0];
for(i=0;i < n;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
printf("The max of the given array is %d",max);
getch();
}



Related Links :

C Program to calculate sum of diagonal elements of a matrix

C Program to calculate sum of diagonal elements of a matrix | C Program to add Numbers diagonally | Diagonally add Elements of array in C





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

void main()
{
int a[10][10],i,j,sum=0,r,c;
clrscr();
printf("\n Enter the number of rows and column ");
scanf("%d%d",&r,&c);
printf("\nEnter the %dX%d matrix",r,c);
for(i=0;i < r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}//for
}//for
for(i=0;i <r;i++)
{
for(j=0;j < c;j++)
{
if(i==j)
{
sum+=a[i][j];
}
}//for
}//for
printf("\nThe sum of diagonal elements is %d",sum);
}

Related Links :

C program to add value in Spiral matrix Format

C program to add value in Spiral matrix Format



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

void main()
{
int m[20][20],i,j;
int p,q,r,hr,r,c,cnt;
clrscr();
printf("\nEnter r & c :");
scanf("%d %d",&r,&c);
cnt = 1;
r = 0; p = 0;
hr = r - 1;
q = c - 1;
while ( r <=hr && p <= q )
{
i = r;
for(j=p;j <= q;j++)
{
m[i][j] = cnt++;
j = q;
for(i=r+1;i<=hr;i++)
{
m[i][j] = cnt++;
if( r != hr )
{
i = hr;
for(j=q-1;j>=p;j--)
m[i][j] = cnt++;
}
if ( p != q )
{
j = p;
for(i=hr-1;i>r;i--)
m[i][j] = cnt++;
}
}
}
r++;p++;
hr--;q--;
}
printf("\nSpirally filled matrix is\n");
for(i=0;i < r;i++)
{
for(j=0;j<c;j++)
{
printf("%4d",m[i][j]);
printf("\n");
}
}

Related Links :

C Program to Check perfect number

C Program to Check perfect number





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

void main()
{
int n,d,tot;

clrscr();
printf("\n Enter value for n : ");
scanf("%d",&n);
tot = 0;

d = 1;
while ( d<= n/2)
{
if ( n % d == 0 )
{
tot = tot + d;
}
d++;
} // while
if ( tot == n )
{
printf("\n Yes... %d is perfect",n);
}
else
{
printf("\n Ohhhh... %d is not perfect",n);
}
}

Related Links :

C program for multiplication of two mXn matrix

C program for multiplication of two mXn matrix

multiplication of Matrix in C, C assignment to multiplication of matix M x N in C, C assignment to solve multiplication of matrix.



#include
#include
#define ROW 20
#define COL 20
void main()
{
int a[ROW][COL],b[ROW][COL],c[ROW][COL];
int i=0,j=0,k,sum=0,m,n;
clrscr();
printf("\n enter the value for m\n");
scanf("%d",&m);
printf("\n enter the value for n\n");
scanf("%d",&n);
printf("\n enter the matrix A elements ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n the matrix A elements ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
printf("\n enter the matrix B elements ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n the matrix B elements ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d",b[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
sum=0;
for(k=0;k<n;k++)
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
}
}
printf("\n the product of matrices is as follows \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\t%d",c[i][j]);
}
printf("\n");
}
getch();
}




Related Links :

C Program to Calculate the volume and area of cube

C Program to Calculate the volume and area of cube


#include
main()
{
float side,surfacearea,volume;
clrscr();
printf("\n Please enter the side of cube...\n ");
scanf("%f",&side);
surfacearea=6*side*side;
volume=side*side*side;
printf("\n The surface area of cube=%f",surfacearea);
printf("\n The volume of cube=%f",volume);
getch();
}




Related Links :

c program to calculate the length of the string without using library function

c program to calculate the length of the string without using library function




#include
#include
void main()
{
int i=0,cnt=0;
char str[50];
clrscr();
printf("\n Enter Any string=");
gets(str);
while(str[i]!=NULL)
{
i++;
}
printf("\n length of string is =%d",i);
getch();
}

Related Links :

write a C program to display Fibonacci series upto n terms

write a C program to display Fibonacci series upto n terms

Fibonacci series in C++ language | C++ Program to print Fibonacci series | Fibonacci series upto n numbers, Fibonacci series upto given number in C++





#include
#include
void main()
{
clrscr();
int a=0,b=1,c=0,n;
cout<<"Enter the number of terms you wanna see: ";
cin>>n;
cout<<a<<" "<<b<<" ";
for(int i=1;i<=n-2;i++)
{
c=a+b;
a=b;
b=c;
cout<<c<<" ";
}
getch();
}




Related Links :


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!