-->

Facebook

Jasper Roberts - Blog
Showing posts with label c programs. Show all posts
Showing posts with label c programs. Show all posts

Wednesday, December 21, 2016

Write a C Program to find Gratest of 3 numbers to print the given no in ascending order.

void main()
{
     int a,b,c;
     clrscr();
     printf("enter the values of a,b and c");
    scanf("%d%d%d",&a,&b,&c);

   if(a<b && a<c)
  {
       if(b<c)
  {
       printf(" %d%d%d", a,b,c);
  }
 else if(b>c){
        printf(" %d%d%d",a,c,b);
  }
else if(b<c && b<a)
{
if(c<a)
       printf(" %d%d%d",b,c,a);
else
printf("%d%d%d",b,a,c);
}
else if(b<a)
         printf("%d%d%d",c,b,a);
else
         printf(%d%d%d",c,a,b);
}
}

OUTPUT:
Enter the values of a,b and c
6
4
5
4 5 6

Monday, December 19, 2016

Write a C Program to Find power of a number using recursion.

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

  3. int main() {
  4. int pow,no;
  5. long int res;
  6. long int power(int,int);
  7. printf("Enter a number: ");
  8. scanf("%d",&no);
  9. printf("\n Enter power: ");
  10. scanf("%d",&pow);
  11. res=power(no,pow);
  12. printf("\n%d to the power %d is: %ld",no,pow,res);
  13. return 0;
  14. }
  15. int i=1;
  16. long int sum=1;
  17. long int power(int num,int pow) {
  18. if(i<=pow) {
  19. sum=sum*no;
  20. power(no,pow-1);
  21. } else
  22. return sum;
  23. }
OUTPUT:
Enter a number: 5
Enter power: 2
5 to the power 2 is: 25

Tuesday, April 14, 2015

A C Program to find out factorial of a given number using recursion.

#include<conio.h>
#include<stdio.h>
int fact(int p);

void main()
{
            int n, ans;
            clrscr();

            printf(“Enter the number:”);
            scanf(“%d”,&n);

            ans = fact(n);

            printf(“Factorial of  a given number %d is %d”,n,ans);
            getch();
}
int fact(int p)
{
            if(p==1)
            {
            return 1;
            }
            else
            {
            return p*fact(p-1);
            }
}

OUTPUT:
Enter the number: 3
Factorial of  a given number 3 is 6