AbdullahZaidPPS / TwoProgramsaday_assignment

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TwoProgramsaday_assignment


1. Write a program to find the area of a triangle using following function signatures.
void input(float *base, float *height);
void find_area(float base , float height, float *area);
void output(float base, float height, float area);
input:
1
2
output:
the area of the traingle with base 1.000000 and height 2.000000 is 1.000000


2. Write a program to find if a triangle is scalene. A triangle is a scalene traingle if all the three sides of the triangle are not equal to each other.

<br> int input_side()
<br> int check_scalene(int a, int b, int c)
<br> void output(int a, int b, int c, int isscalene)


3. Write a program find whether a number is a composite number. A Composite number has a factor other than 1 and itself
int input_number();
int is_composite(int n);
void output(int n, int composite);
input:
8
output:
8 is a composite number.


4. Write a program to find Sum of composite number in an array of numbers different containing numbers entered by the user.
int input_array_size();
void input_array(int n, int a[n]);
int sum_composite_numbers(int n, int a[n]);
void out_put(int sum);
input:
1 2 7 8 12
output:
20
5. Write a program to find gcd (hcf) of two numbers.
int input();
int gcd(int a, int b);
void output(int a, int b, int gcd); input: 12 16 output 4


6. Write a program to reverse a string.
void input_string(char *a);
char *str_reverse(char *a);
void output(char *a,char *reversea);
input:
hello
output:
olleh


7. Write a program to find the area of a triangle
struct _triangle
{
float base,altitude,area;
}; <brtypedef _triangle Triangle
Triangle input_triangle();
void find_area(Traingle *t);
void output(Triangle t);
input:
2 3
output:
The area of triangle wwith base = 2.000000 and altitude = 3.000000 is 3.000000


8. Write a program to find the triangle with smallest area in n given triangles.
struct _triangle
{
float base,altitude,area;
};
typedef _triangle Triangle
int input_n();
Triangle input_triangle();
void input_n_triangles(int n, triangle t[n]);
void find_area(Triangle *t);
void find_areas_n(int n, Triangle t[n]);
Triangle find_smallest_triangle(int n, Triangle t[n]);

void output(int n, Triangle t[n], Triangle smallest);
void
input:
2 3
4 6
the smallest of triangles with base and height
2,3 and
4,6
is
triangle with base 2.000000, 3.000000 is 3.000000
The area of triangle wwith base = 2.000000 and altitude = 3.000000 is 3.000000


9. Write a program to find the distance between two points
void input(float *x1, float *y1, float *x2, float *y2);
void find_distance(float x1, float y1, float x2, float y2, float *area);
void output(float x1, float y1,float x2, float y2, float area);
input:
1 1 2 2
output:
the distance between point (1.000000,1.000000) and (2.000000,2.000000) is with 1.4142


10. Write a program to find whether the three points form a triangle.
void input_triangle(float *x1, float *y1, float *x2, float *y2, float *x3, float *y3);
int is_triangle(float x1, float y1, float x2, float y2,float x3, float y3)
void output(float x1, float y1, float x2, float y2,float x3, float y3, int istriangle)


11. Write a program find whether a given number is a prime number.
int input_number();
int is_prime(int n);
void output(int n, int is_prime);
input:
3
output:
3 is a prime number.


12. Write a program to find nth number in fibonacci sequence.
Fibonacci sequence consists of 0,1,1,2,3,5,8,13,21........
int input();
int find_fibo(int n);
void output(int n, int fibo);


13. Write a program to find all the prime numbers between erotosthenes sieve method.
int input_array_size();
void init_array(int n, int a[n];
void erotosthenes_sieve(int n, int a[n]);
void out_put(int n, int a[n]);
input:
100
output:
2,3,7,11,13,19,23,29,31,...


14. Write a program to find the index of a substring of a string.
void input_string(char *a);
int str_reverse(char *string, char *substring);
void output(char *string, char *substring, int index);
input:
helloworldhello
world
output:
The index of world in helloworldhello is 5


15. Write a program to find the length of a line.
struct _point {
float x,y;
};
typedef struct _point Point;
struct _line
{
Point p1,p2;
float distance;
};
typedef struct _line Line
Point input_point();
Line input_line();
void find_length(Line *l);
void output(Line l);


16. Write a program to find the permeter of a polygon
struct _point {
float x,y;
};
typedef struct _point Point;
struct _line
{
Point p1,p2;
float distance;
};
struct _line Line;
struct _polygon {
int n;
Line l[100];
float perimenter;
}
int input_n();
int input_polygon( int n, Polygon *p);
Line input_line();
void input_n_lines(int n, Line l[n]);
void find_perimeter(Polygon *p);
void output(Polygon p);
17. Write a program to Compare two strings
void input_two_string(char *a, char *b);
int strcmp(char *a, char *b);
void output(char *a, char *b, int result);
input:
hello
world
output:
world is greater than hello
18. Write a program to find Sum of n complex numb
ers
struct _co
mplex
{
float real,imaginary;
};
typedef _complex Complex;
int get_n();
Complex input_complex();
void input_n_complex(int n, Complex c[n]);
Complex add(Complex a, Complex b);
Complex add_n_complex(int n, Complex c[n]);
void output(int n, Complex c[n], Complex result);
input: 2
2 + 3i
4 + 5i
2 + 3i
+ 4 + 5i is
6 + 8i

<br> 19. Write program to add n fractions
<br> struct _fraction 
<br> {
<br>    int num,den;
<br> };
<br> typedef _fraction Fraction;
<br> int find_gcd(int a, int b);
<br> Fraction input_fraction();
<br> void input_in_fractions(int n, Fraction f[n]);
<br> Fraction add_fractions(Fraction f1, Fraction f2);
<br> Fraction add_n_fractions(int n,Fraction f[n]);
<br> void output(int n, Fraction f[n], Fraction sum);


20. Write a program to evaluate a polynomial at a given point using horners method.
int input_degree();
float input_x();
void input_coefficients(int n, float a[n]);
float evaluate_polynomial(int n, float a[n], float x);
void out_put(int n, float a[n], float x, float result);
input:
1 1 1
output:
1+1*x + 1*x^2 at 1.000000 is 1.000000

About


Languages

Language:C 100.0%