Thursday 1 February 2018

Examples Function in C Language

1.

#include<stdio.h>
int main()
{
    int power(int,int);
    int p,a,b;
    printf("Enter the no. ");
    scanf("%d",&a);
    printf("Enter The Power ");
    scanf("%d",&b);
    p=power(a,b);
    printf("p=%d",p);
}
power(int x,int y)
{
    int i,a=1;   
    for(i=1;i<=y;i++)
    {
        a=a*x;
    }
    return(a);
}


2.

#include<stdio.h>
int main()
{
    float area (float);
    float aoc,r;
    printf("Enter the circle of radius .");
    scanf("%f",&r);
    aoc=area(r);
    printf("aoc=%f",aoc);
}
area(float rad)
{
    float a,pi=3.14;
    a=pi*rad*rad;
    return(a);
}


3.

#include<stdio.h>
int main()
{
    void avg(int,int);
    int a,b;
    printf("Enter the number");
    scanf("%d%d",&a,&b);
    avg(a,b);   
}
sum(int x,int y)
{
    int z;
    z=x+y;
    return(z);
}
avg(int p,int q)
{
    float r,av;
    r=sum(p,q);
    av=r/2;
    printf("\nSum=%f",r);
    printf("\nAvg=%f",av);
}


4.

#include<stdio.h>
int main()
{
    int prime(int);
    int a;
    printf("Enter the no = ");
    scanf("%d",&a);
    prime(a);
}
prime(int a)
{
    int i,y,x=0;
    if((a==1)||(a==2))
    {
        printf("prime no");
    }
    else
    {
        for(i=2;i<a;i++)
        {
            if((a%i)==0)
            {   
                x=1;
                y=i;
                printf("\n no is divid by %d",y);
            }
        }
        if(x==1)
        {
            printf("\nThen no is not prime");
        }
        else
        {
            printf("prime no");   
        }
    }
}


5.

#include<stdio.h>
float c;
sum(float a,float b)
{
    c=a+b;
    return(c);
}
diff(float a,float b)
{
    c=a-b;
    return(c);
}
mul(float a,float b)
{
    c=a*b;
    return(c);
}
div(float a,float b)
{
    c=a/b;
    return(c);
}
mod(int a,int b)
{
    int d;
    d=a%b;
    return(d);
}
int main()
{
    int ch,d,x,y;
    float a,b;
    printf("for sum prace 1,for deffrence prace 2,for mul prace 3,for division prace 4,for modlus prace 5");
    printf("\nEnter the ch=");
    scanf("%d",&ch);
    switch(ch)
    {
    case 1:
        printf("Enter the no=");
        scanf("%f%f",&a,&b);
        c=sum(a,b);
        printf("Sum=%f",c);
        break;
    case 2:
        printf("Enter the no=");
        scanf("%f%f",&a,&b);
        c=diff(a,b);
        printf("Diff=%f",c);
        break;
    case 3:
        printf("Enter the no=");
        scanf("%f%f",&a,&b);
        c=mul(a,b);
        printf("Mul=%f",c);
        break;
    case 4:
        printf("Enter the no=");
        scanf("%f%f",&a,&b);
        c=div(a,b);
        printf("Div=%f",c);
        break;
    case 5:
        printf("Enter the no=");
        scanf("%d%d",&x,&y);
        d=mod(x,y);
        printf("Mod=%d",d);
        break;
    default:
        printf("Wrong Choice");
       
    }
}


Share this

0 Comment to "Examples Function in C Language"

Post a Comment