C program to make Area calculator

 In this post ,I will let you know how to make  Area calculator. So, without any further delay let's get started .

Code:

#include <stdio.h>
int main()
{
    char Shape;
    float radius, side, length, breadth, base, height;
    float areaC, areaS, areaR, areaT;
    printf("Enter shape symbol for which you want Area(Circle=C,Square=S,Rectangle=R,Triangle=T)\n");
    scanf("%c", &Shape);
    if (Shape == 'c' || Shape == 'C')
    {printf("Enter radius of circle\n");
        scanf("%f", &radius);
        areaC = 3.14 * radius * radius;
        printf("Area of circle=%f\n", areaC);
    }
    else if (Shape == 'S' || Shape == 's')
    {printf("Enter side of Square\n");
        scanf("%f", &side);
        areaS = side * side;
        printf("Area of square=%f\n", areaS);
    }
    else if (Shape == 'R' || Shape == 'r')
    {printf("Enter Length and Breadth of Rectangle \n");
        scanf("%f %f", &length, &breadth);
        areaR = length * breadth;
        printf("Area of Rectangle=%f\n", areaR);
    }
    else if (Shape == 'T' || Shape == 't')
    {printf("Enter Base and Height of Triangle\n");
    scanf("%f %f", &base, &height);
        areaT = 0.5 * base * height;
        printf("Area of Triangle=%f\n", areaT);
    }
    return 0;

Logic:

Now let us first understand how algorithm for this .Here we make calculator only for four Shapes  i.e. Circle ,Square ,Rectangle and Triangle .

For that we must know formula of all these .Below are formula for these:

    Circle:  Area=pi*radius*radius  ,pi=3.14

     Square: Area=Side*Side 

      Rectangle: Area=Length*Breadth

      Triangle : Area=1/2*Base *Height

Know more about if-else.  After this its time to understand each and everything about this program ,so that you don't left any doubt after reading this .First we declare variable Shape of type character  and some float variables radius for circle ,side for square ,length and breadth for Rectangle and for Triangle base and height. And other variables areaC for Circle ,areaS for square ,areaR for rectangle and areaT for triangle of type float . Now we ask user to enter just symbol of shape C for Circle and R for rectangle , S for Square  and T for Triangle . And then we use if (Shape =='C' || Shape =='c') ,that means we check  if it is equal to C (capital letter ) or in c(small letter) then execute it for Circle .Here || is OR operator  means if any of them is true then execute code .Now continue it printf() inside if gets executed and ask for Radius from user .Then he enters radius and program work and print area of Circle. And this work for all Square , Rectangle and Triangle. 
Output:                                                                                                                                                                                                                   


Here you can see output ,it works as  we think .It take symbol of Shape and then ask for Requirements to calculate its area. And give us correct output . 

                            I hope you might  find this helpful  in your work.

                                                         Thanks for reading 

C program to make Calculator

In this I will tell you how to make a simple calculator just by using if-else in c language .First I tell you about if-else condition .You can easily understand it let us consider an example if(age>18) Then you can ride bike . This condition you have to meet in order to ride bike similarly in programming .If condition is  true then you should do this other wise check for next condition .Using this we can also design calculator 

Code:

#include <stdio.h>

int main()
{
    float number1, number2;
    char sign;
    printf("Enter number1\n");
    scanf("%f", &number1);
    printf("Enter number second\n");
    scanf("%f", &number2);
     printf("Enter operator(*,-,+,/)\n");
    scanf(" %c", &sign);

    if (sign == '+')
    {
        printf("\nSum : %.2f", number1 + number2);
    }
    else if (sign == '-')
    {
        printf("\nDifferece: %.2f", number1 - number2);
    }
    else if (sign == '*')
    {
        printf("\nMultiply: %.2f", number1 * number2);
    }
    else if (sign == '/')
    {
        printf("\nDivision : %.2f", number1 / number2);
    }
    return 0;
}

Logic:

Now I will tell you what I do here .First I define three variables number1,number2 of type float and sign is of type character .If you does not know what variable is you can check my previous post where I do brief coverage of this topic .You can check here some brief Idea .Now back to this then I take value 

of sign variable which can be(*,+,-,/) these are basic operator in c language. Then I ask user to enter number1 and number2.Then using if condition I check for every operator user can enter. Then If match is found then perform that operation .And in each match condition I give a print statement to output to user .

Output:

Here I show you output how it give us result . Make this program on your pc and run it .


I hope you might find this helpful . 
Thanks for reading  
 

C program to Calculate Simple Interest

 In this post I will tell you how to write  C program to calculate Simple Interest .  So, without any further delay let's get started.

Code:

#include<stdio.h>

int main(){
  int principal;
  float rate,time,simpleInterest;
  printf("Enter principal amount \n");
  scanf("%d",&principal);
  printf("Enter rate of interest\n");
  scanf("%f",&rate);
  printf("Enter time(means year)\n");
  scanf("%f",&time);
  simpleInterest=(principal*rate*time)/100;
  printf("Simple Interset=%f\n",simpleInterest);



    return  0;
}

Logic:                                                                                                  We know that in S.I.=P*R*T/100 .Here P means principal amount ,R means rate at which it is increasing. And last T is time for which money is given .And multiplication of P*R*T divides by 100 . Gives us Simple Interest .Now I show you code  screen shot for your  comfort . I paste screen shot Here int principal; is called variable declaration in c language and here int is datatype means simply we said to compiler that you take value in principal in form of integer numbers .Float is also datatype and I will discuss this particular topic in detail in another post. And scanf here take value in variables using format specifier like %d for int ,%f  for float etc. And you will eager to see output of this program.

Output:

And I hope you will try by yourself on your pc and also try for other numbers . And last most important tip for you guys that always &(means at this address ) while taking input through user.

I hope this might helpful to you.

Thanks for reading 

Simple C program

 In this program I will tell you how to write a simple  C program . For your comfort I also put down image of code and output .

Here I am using vs code which I very good IDE if you are beginner .

Code:

#include<stdio.h>
// sample C program 
int main(){

printf("I am reader\n");

    return 0;
}


Logic:

Here we write #include<stdio.h> because it is standard file for input and output .

And main is function which returns value in integers that why at the end of it we use return zero.

Third we use printf() because it is a function which is used to print any statement in c language as its name suggest .

Last \n is used to give line break or we can say after printing move control to next line .

Now you must think what is the output of this 

Output:


And this is the output and last one most important tip for you always end statement by ; otherwise compiler through us error .

I hope that you might find it helpful 

Thanks for reading .