0% found this document useful (0 votes)
173 views3 pages

C Programs Code

The document contains several C programs demonstrating different algorithms, including string reversal, perfect numbers, Armstrong numbers, sum of digits, Fibonacci series using recursion, factorial using recursion, and bubble sorting. Each program includes code snippets and comments explaining the functionality. The document serves as a collection of examples for basic programming concepts in C.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
173 views3 pages

C Programs Code

The document contains several C programs demonstrating different algorithms, including string reversal, perfect numbers, Armstrong numbers, sum of digits, Fibonacci series using recursion, factorial using recursion, and bubble sorting. Each program includes code snippets and comments explaining the functionality. The document serves as a collection of examples for basic programming concepts in C.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

C Program For String Reverse.

  #include<conio.h>
void main()
#include<stdio.h> {
#include<conio.h> int a[20],i,n;
void main() clrscr();
{ printf("Enter the n value");
char n[50],j,i=0; scanf("%d",&n);
clrscr(); for(i=1;i<=n;i++)
printf("OUTPUT\n"); {
printf("------"); printf("enter the a[%d]=",i);
printf("Enter String:\n"); scanf("%d",&a[i]);
printf("The Reverse Of The Given String }
is\n"); for(i=n;i>0;i--)
printf("**********************************"); {
while((n[i]=getchar())!='\n')i++; printf("%d\n",a[i]);
for(j=i-1;j>=0;j--) }
{ getch();
printf("%c",n[j]); }
}
getch(); C Program For PERFECT NUMBER.
}
#include<stdio.h>
C Program For ARMSTRONG NUMBER.  #include<conio.h>
void main()
#include<stdio.h> {
#include<conio.h> int c=0,n,i;
void main() clrscr();<br>
{ printf("Enter n value:");
int n,t,s=0,k; scanf("%d",&n);
clrscr(); for(i=1;i<n;i++)
printf("Enter the n value:"); {
scanf("%d",&k); if(n%i==0)
n=k; {
while(n>0) c=c+i;
{ }
t=n%10; }
s=s+t*t*t; if(n==c)
n=n/10; {
} printf("given number %d is perfect
if(k==s) number",c);
{ }
printf("given %d is armstrong else
number",k); {
} printf("not perfect number");
else }
{ getch();
printf("not armstrong number"); }
}
getch(); C Program For SUM OF DIGITS.
}
#include<stdio.h>
#include<conio.h>
C Program For ARRAY REVERSE.  void main()
{
#include<stdio.h> int n,t,s=0;
clrscr(); i=j;
printf("Enter the digit"); j=k;
scanf("%d",&n); printf("%d ",k);
while(n>0) }
{ getch();
t=n%10; }
s=s+t;
n=n/10; C Program For FIBANACCI SERIES USING
} RECURSION.
printf("sum =%d",s);
getch(); #include<stdio.h>
} #include<conio.h>
void main()
{
C Program For PRIME SERIES. int i,n;
clrscr();
#include<stdio.h> printf("Enter the n value:");
#include<conio.h> scanf("%d",&n);
void main() printf("the fibinacci series is\n");
{ for(i=0;i<n;i++)
int r,a,b,c=0; {
clrscr(); printf("%d\n",fib(i));
printf("Enter the n value:"); }
scanf("%d",&r); getch();
a=1; }
while(a<=r)//for(i=1;i<=n;i++) int fib(int n)
{ {
b=1;c=0; if(n==0)
while(b<=a) {
{ return(0);
if(a%b==0) }
c=c+1; if(n==1)
b++; {
}//end of while return(1);
if(c==2) }
printf("%d",a); else
a++; {
} return(fib(n-1)+fib(n-2));
getch(); }
} }

This program prints the Fibonacci series C Program For FACTORIAL USING
RECURSION.
#include<stdio.h>
#include<conio.h> #include<stdio.h>
void main(void) #include<conio.h>
{ void main()
int i,j,k,n; {
clrscr(); int n,f;
i=0; clrscr();
j=1; printf("Enter the n value:");
printf("%d %d ",i,j); scanf("%d",&n);
for(n=0;n<=5;n++) f=fact(n);
{ printf("factorial value is=%d",f);
k=i+j; getch();
}
int fact(int a) clrscr();
{ printf("Enter the n value:");
int c=1; scanf("%d",&n);
if(a==1) for(i=1;i<=n;i++)
{ {
return(1); printf("Enter the number in ascending order
} a[%d]=",i);
else scanf("%d",&a[i]);
{ }
a=a*fact(a-1); printf("Enter the search element:");
//printf("%d\n",c); scanf("%d",&search);
return (a); low=1;
} high=n;
} while(low<=high)
{
C Program For BUBBLE SORTING. mid=(low+high)/2;
if(search<a[mid])
#include<stdio.h> {
#include<conio.h> high=mid-1;
void main() }
{ else if(search>a[mid])
int n,i,j,t,a[20]; {
clrscr(); low=mid+1;
printf("Enter the n value:"); }
scanf("%d",&n); else
for(i=1;i<=n;i++) {
{ f=1;
printf("a[%d]=",i); printf("obtainedin the position %d:",mid);
scanf("%d",&a[i]); getch();
} exit();
for(i=1;i<=n;i++) }
{ }
for(j=i+1;j<=n;j++) if(f==0)
{ {
if(a[i]>=a[j]) printf("not present");
{ }
t=a[i]; getch();
a[i]=a[j]; }
a[j]=t;
}
}
}
for(i=1;i<=n;i++)
{
printf("%d\n",a[i]);
}
getch();
}

Program For BINARY SEARCH.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,search,f=0,low,high,mid,a[20];

You might also like