Sunday, August 10, 2014

Multi Function In C Programming Language

#include<stdio.h>
add()
{
    int x=10,y=12,res;
    printf("enter the value of x\n");
    scanf("%d",&x);
    printf("enter the value of y\n");
    scanf("%d",&y);
    res=x+y;
    printf("the result is %d",res);
}
substract()
{
    int num1,num2,result;
    printf("enter the value of num1\n");
    scanf("%d",&num1);
    printf("enter the value of num2\n");
    scanf("%d",&num2);
    result=num1-num2;
    printf("the result is %d",result);
}
run_it()
{
    add();
}
main()
{
    char answer[20];
    printf("what do you want to do?? (type add or substract)");
    scanf("%s",&answer);
    if(strcmp(answer, "add")==0)
    {
        run_it();
    }
    else if(strcmp(answer, "substract")==0)
    {
        substract();
    }
    else
    {
        printf("i can not work\n");
    }
    fflush(stdin);
    getchar();
}

No comments: