Monday, 8 December 2014

C Program to evaluate an expression

Program to evaluate an expression
#include<stdio.h>
#include<stdlib.h>
operations()
{
int a;
printf("Program for various operations\n");
printf("enter ur choice 1:tabs\n 2:manipulate\n 3:forloop\n");
scanf("%d",&a);
if(a==1)
{
printf("performing tabs operation\n");
tabs();
}
else if(a==2)
{
printf("performing manipulations..\n");
manipulate();
}
else if(a==3)
{
printf("performing forloop operation...\n");
forloop();
}
}
tabs()
{
printf("for back Space\b");
printf("for tab space\t");
printf("for coming to next line\n");
}
manipulate()
{
int a,b,result,n;
printf("read the values for a and b\n");
scanf("%d%d",&a,&b);
printf("enter ur choice N\n");
scanf("%d",&n);

switch(n)
{
case 1:
printf("addition operation\n");
result=a+b;
break;

case 2:
printf("substraction operation\n");
if(a>=b)
result=a-b;
else
result=b-a;
break;

case 3:
printf("multiplication operation\n");
result=a*b;
break;

case 4:
printf("division operation\n");
result=(a/b);
break;

default:printf("enter correct choice\n");
}
printf("result is %d\n",result);
}
forloop()
{
 int i,j,n;
char ch='a';
 printf("enter value for N\n");
   scanf("%d",&n);
  for(i=0;i<n;i++)
  {
   for(j=0;j<=i;j++)
   printf("%c ",ch++);
   printf("\n");
  }
}

main()
{
int choice;
operations();
}
OutPut:
Program for various operations
enter ur choice 1:tabs
 2:manipulate
 3:forloop
3
performing forloop operation...
enter value for N
3
a 
b c 
d e f 
madan@madan-Lenovo-G570:~/madan$ ./a.out
Program for various operations
enter ur choice 1:tabs
 2:manipulate
 3:forloop
2
performing manipulations..
read the values for a and b
12
35
enter ur choice N
4
division operation
result is 0