Thursday 6 December 2018

Programming for Problem Solving (3110003) - Program no 1 to 5

1. Write a program that perfomrs as calculator. (Addition, Subtraction, Division, Multiplication, Modulus)

#include<stdio.h>
#include<conio.h>

void main()
{
    int a,b,ans;
    clrscr();
    printf("Enter the value of a");
    scanf("%d",&a);
    printf("Enter the value of b");
    scanf("%d",&b);
   
    ans = a+b;
    printf("\n Addition :%d ",ans);
   
    ans=a-b;
    printf("\n Subtraction :%d ",ans);
   
    ans=a*b;
    printf("\n Multiplication :%d ",ans);
   
    ans=a/b;
    printf("\n Division :%d ",ans);
   
    ans=a%b;
    printf("\n Modulus :%d ",ans);
    getch();       
}



2. Write a program to find area of triangle(a=h*b*.5)

#include<stdio.h>
#include<conio.h>

int main()
{
    float a,h,b;
    printf("Enter the value of height");
    scanf("%f",&h);
   
    printf("Enter the value of base");
    scanf("%f",&b);
   
    a = h*b*0.5;
    printf("\nArea of Triangle: %f",a);
          
}


 3. Write a program to calculate simple interest (i = (p*r*n)/100 )

#include<stdio.h>
#include<conio.h>

int main()
{
    long int p,r,n,i;
   
    printf("Enter principal amount");
    scanf("%ld",&p);
   
    printf("Enter rate of interest");
    scanf("%ld",&r);
   
    prin

tf("Enter number of years");
    scanf("%ld",&n);
   
    i=(p*r*n)/100;
   
    printf("\nSimple interest: %ld",i);
          
}


4. Write a C program to interchange two numbers. 

#include<stdio.h>
#include<conio.h>

int main()
{
    int a,b,temp;
    printf("Enter value of a");
    scanf("%d",&a);
   
    printf("Enter value of b");
    scanf("%d",&b);
   
    printf("Value before interchange");
    printf("\n Value of a: %d",a);
    printf("\n Value of b: %d",b);
   
    temp=a;
    a=b;
    b=temp;
   
    printf("\nValue after interchange");
    printf("\n Value of a: %d",a);
    printf("\n Value of b: %d",b);
              
}


5. Write a C program to enter a distance in to kilometre and convert it in to meter, feet, inches and centimetre 

#include<stdio.h>
#include<conio.h>
int main()
{
    float km, m, cm, feet, inch;
    printf("Enter the distance in kilometers: ");
    scanf("%f", &km);
    m=km*1000;
    cm=m*100;
    feet=km*3280.8;
    inch=feet*12;
    printf("The distance in meters is %f\n", m);
    printf("The distance in centimeters is %f\n", cm);
    printf("The distance in feet is %f\n", feet);
    printf("The distance in inches is %f\n", inch);
   
}
 

 

No comments:

Post a Comment