Skip to main content

Simple Programs to Begin With

1) area of the circle given the diameter.
2)area of the circle given the circumference.
3)area of the circle given center point (x1,y1) and one point on the perimeter (x2,y2).
(Hint: input the two points and compute the distance between them as radius)
4)area of a triangle given three sides a,b,c.( assume they form a triangle)
5)area and perimeter of a right angled triangle given width(w) and height(h).
6)volume and surface area of a sphere given the radius.
7)area of an equilateral triangle given one side (s).
8) volume and surface area of the cylinder given radius(r) and height(h).
9) volume and surface area of a cube given one side ( s).
10)hypotenuse of a right-angled triangle, given the length of the other two sides.
Note: assume uniform input values( eg: cm)
11) Find A, the Final Investment Value, using the simple interest formula: 
A = P(1 + rt) where P is the Principal amount of money to be invested at an Interest Rate R% per period for t Number of Time Periods. Where r is in decimal form; r=R/100;
12)Compute the compound interest(CI)
CI=A-P
Where, A = future amount
A=P(1+r/n)^(nt)
P = principal
r = rate of interest
n = number of times interest is compounded per year
t = time (in years)



Example- You can run this program using gcc in ubuntu
Area of the circle given the diameter

#include <stdio.h>
#include <math.h>
int main()
{
float d,r,area;
system("clear");
printf("Enter the diameter\n");
scanf("%f",&d);
r=d/2;
area=M_PI*r*r;
printf("area of circle=%f\n",area);
}
area of the circle given center point (x1,y1) and one point on the perimeter (x2,y2).
#include <stdio.h>
#include <math.h>
int main()
{
float x1,y1,x2,y2;
float r,a;
system("clear");
printf("Enter the center point (x1,y1)\n");
scanf("%f%f",&x1,&y1);
printf("Enter the point on the circle (x2,y2)\n");
scanf("%f%f",&x2,&y2);
r=sqrt(pow(x2-x1,2)+pow(y2-y1,2)); // finding radius
a=M_PI*r*r; //computing area
printf("area of circle=%.4f\n",a);
}

Note: use -lm option with gcc to link the math module while compiling your program.

Comments

Popular posts from this blog

KTU Mandatory C programs for Laboratory and Solutions

LIST OF LAB EXPERIMENTS 1. Familiarization of Hardware Components of a Computer 2. Familiarization of Linux environment – Programming in C with Linux 3. Familiarization of console I/O and operators in C     i) Display “Hello World”     ii) Read two numbers, add them and display their sum     iii) Read the radius of a circle, calculate its area and display it 4. Evaluate the arithmetic expression ((a -b / c * d + e) * (f +g))   and display its solution. Read the values of the variables from the user through console 5. Read 3 integer values, find the largest among them. 6. Read a Natural Number and check whether the number is prime or not 7. Read a Natural Number and check whether the number is Armstrong or not 8. Read n integers, store them in an array and find their sum and average 9. Read n integers, store them in an array and search for an element in the    array using an algorithm for Linear Search 10.Read n integers, store them in an array and sort the elements in t

PROGRAMMING IN C KTU EST 102 THEORY AND LAB NOTES

PROGRAMMING IN C  KTU  EST 102  THEORY AND LAB   COMMON FOR ALL BRANCHES About Me Syllabus Theory Syllabus Lab Model Question Paper EST 102 Programmin in C University Question Papers  and evaluation scheme   EST 102 Programming in C  Introduction( Lab) Introduction to C programming Linux History and GNU How to create a bootable ubuntu USB stick Installing  Linux Install Linux within  Windows Virtual Box and WSL Linux Basic Features and Architecture Basic Linux Commands Beginning C Programming Compiling C programs using gcc in Linux Debugging C program using gdb Module 1: Basics of computer hardware and software          Module-1 Reading Material Basics of Computer Architecture Hardware and Software System Software and Application Software  Programming Languages ( High level, Low level and Machine Language) and Translators ( Compiler, Interpreter, Assembler) Algorithm, Flowcharts and Pseudo code Program Development Structured Programming Basics of hardware ( video) Know about Motherboar