Day 1 of Programming in C

Write a program to add, subtract, multiply and divide 3 numbers

        
#include <stdio.h>
void main(){
    float a,b,c;
    scanf("%f%f%f",&a,&b,&c);
    printf("%f\n",(a+b)+c);
    printf("%f\n",(a-b)-c);
    printf("%f\n",(a*b)*c);
    printf("%f\n",(a/b)/c);
}
        
        
    
Step 1: Declare three floating-point variables `a, b, c`.
Step 2: Take user input using `scanf("%f%f%f", &a, &b, &c);`.
Step 3: Perform addition, subtraction, multiplication, and division.
Step 4: Print the results using `printf`.

Write a program to find the perimeter and area of a square

        
#include <stdio.h>
void main(){
    float a;
    printf("Enter the length of side of square : ");
    scanf("%f",&a);
    printf("Perimeter of the square = %f\nArea of the square = %f",4*a,a*a);
}   
        
        
    
Step 1: Declare a float variable `a`.
Step 2: Take user input for side length.
Step 3: Calculate `Perimeter = 4 * a` and `Area = a * a`.
Step 4: Print results.

Write a program to find the perimeter and area of a rectangle

        
#include <stdio.h>
void main(){
    float a,b;
    printf("Enter the length of rectangle: ");
    scanf("%f",&a);
    printf("Enter the breadth of rectangle: ");
    scanf("%f",&b);
    printf("Perimeter of the rectangle = %f\nArea of the rectangle = %f",2*(a+b),a*b);
}   
        
        
    
Step 1: Declare float variables `a, b`.
Step 2: Take user input for length and breadth.
Step 3: Compute `Perimeter = 2 * (a + b)`, `Area = a * b`.
Step 4: Print results.

Write a program to find the circumference and area of a circle

        
#include <stdio.h>
void main(){
    float r;
    printf("Enter the radius of circle : ");
    scanf("%f",&r);
    printf("Circumference of the circle = %f\nArea of the circle = %f",2*3.14*r,3.14*r*r);
}   
        
        
    
Step 1: Declare float variable `r`.
Step 2: Take user input for radius.
Step 3: Compute `Circumference = 2 * 3.14 * r`, `Area = 3.14 * r * r`.
Step 4: Print results.

Comments

Popular Posts