pages

Monday, 14 June 2021

c-program to add two number by using pointer | call by reference | c-programming

program to add two number by pointer in c language

In this program we will now takes two number and add them by using call by reference (pointer)
 Call by Reference :- when address are passed to the called function.


#include<stdio.h>
#include<conio.h>
int add(int *,int *);
void main()
{
         int a,b,sum=0;
         printf("enter the number:-");
         scanf("%d %d",&a,&b);
         sum=add(&a,&b);
         printf("\n the sum of the two number is %d",sum);
         getch();
}
int add(int *x,int *y)
{
         int s;
         s=*x+*y;
         return(s);
}

output :- 


















Wednesday, 9 June 2021

c-program to find the reverse of the number by using function | c-programming

Program to find the reverse of the number 

In this program we will now  find the  reverser of the number by using function by taking the values from the user in c-programming.

#include<stdio.h>
#include<stdio.h>
int reverse(int);
void main()
{
         int a,num;
         printf("enter the number:-");
         scanf("%d",&a);
         num=reverse(a);
         printf("\n the reverse of the number is %d",num);
         getch();
}
int reverse(int n)
{
         int rev=0,i,x;
         while(n!=0){
                  x=n%10;
                  rev=rev*10+x;
                  n=n/10;
         }
         return(rev);
}

Output:-



For more c-programming















c-program to find the factorial of the number using function | c-programming languages

Program to find the factorial of the number

In this program we will now find the factorial of the number by taking input form the number using function in c-programming.
 factorial of 5 is = 1*2*3*4*5= 120






#include<stdio.h>
#include<conio.h>
int factorial(int);
void main()
{
         int x,fact;
         printf("enter the number:-");
         scanf("%d",&x);
         fact=factorial(x);
         printf("\n the factorial of the number is %d",fact);
         getch();
}
int factorial(int a)
{
         int f=1,i;
         for(i=1;i<=a;i++){
                  f=f*i;
         }
         return(f);
}

output:-










c-program to find the power of the number by using function | c-programming

 program to find the power of the number 

In this program we will now input the base and power of the number  form the user and calculate the power of the number by using function  in c-programming.





#include<stdio.h>
#include<conio.h>
int power(int ,int);
void main()
{
         int p,b,a;
         printf("enter the base:-");
         scanf("%d",&b);
         printf("\nenter the power:-");
         scanf("%d",&p);
         a=power(b,p);
         printf("\n the power of the number is %d",a);
         getch();
}
int power(int x,int y)
{
         int i,f=1;
         for(i=0;i<y;i++){
                  f=f*x;
         }
         return(f);
}

output:-





For more c-programming:-






Wednesday, 2 June 2021

c-program to calculate the sum of the digits of the number | c-programming

 Program to calculate the sum of the digits of the number in c-programming.

In this program we will now takes input form the user and calculate the sum of the digits of the number in c-programming languages.

#include<Stdio.h>
int sum(int n);
main()
{
    int x,s;
    printf("enter the number");
    scanf("%d",&x);
    s=sum(x);
    printf("the sum of the number is %d",s);
    getch();
}
int sum(int n)
{
    int result;
    if(n==0)
        return(0);
    result=n%10+sum(n/10);
    return(result);
    getch();
}

output:-


                                  


For more c-programming:-




c-program to find all prime number by using function | c-programming

Program to find the prime number in c-langauge

In this program we will now find all the n prime number where value n is entered by the user by using function in c-programming.

#include<stdio.h>
#include<conio.h>
void prime(int );
void main()
{
         int n;
         printf("enter the number:-");
         scanf("%d",&n);
         prime(n);
         getch();
}

void prime(int x)
{
         int i,j,count=0;
         for(i=1;i<x;i++){
                  for(j=2;j<i;j++){
                           if(i%j==0)
                                    break;
                  }
                  if(i==j)
                           printf("%d ",i);
         }
}


output:-