Powered By Blogger

Thursday, March 8, 2012

Program : 1


Prg: 1 Let a and b are two integer variables
   Write a   program to evaluate the following arithmetic expressions.
     i) a + b       ii) a – b     iii) a * b     iv) a / b     v) a % b
#include<stdio.h>
#include<conio.h>
void main()
{
                int a,b,sum,difference,product,quotient,remainder;
                clrscr();
                printf("enter the values of a,b : ");
                scanf("%d %d",&a,&b);// Reading the values of a and b
                sum=a+b; // adding a and b and storing in sum variable
                difference=a-b;
                product=a*b;
                quotient=a/b;
                remainder=a%b;
                printf("\n sum=%d",sum);// printing the answer
                printf("\n  difference=%d",difference);
                printf("\n product=%d",product);
                printf("\n quotient=%d",quotient);
                printf("\n remaimder=%d",remainder);
                getch();
}


Program 2:

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
    int a,b,x,y,k,t,r1,r2,r3,r4,r_r1,r_r2;
    clrscr();
    printf("Enter the values of a,b,x,y,k,t : ");

//reading the values of a,b,x,y,k,t

    scanf("%d %d %d %d %d %d",&a,&b,&x,&y,&k,&t);

//the datatype float inside the brackets before the operation has already
 //seen in typecasting,means taking input of diff type and performing
//logic with the same data type and producing result in required data type(float)

    r1=(float) (a*x+b)/(a*x-b);
    r_r1=(float) 2.5*log(x)+cos(32*((22.0/7)/180));
    r_r2=abs(x*x+y*y)+sqrt(2*x*y);     
    r2=r_r1+r_r2;
    r3=(float)pow(x,5)+10*pow(x,4)+8*pow(x,3)+4*x+2;                                          
    r4=(float) a*exp(k*t);

//printing the results r1,r2,r3,r4

    printf("\n r1= %d",r1);
    printf("\n r2= %d",r2);
    printf("\n r3= %d",r3);
    printf("\n r4= %d",r4);

  getch();
}

2 comments: