Skip to content

Commit

Permalink
Merge pull request #67 from RealCifer/RealCifer-4
Browse files Browse the repository at this point in the history
Added solution for issue #48 that is question 6
  • Loading branch information
krishnapatidar458 authored Oct 3, 2023
2 parents c3c7f8e + b8056c2 commit fd691fc
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 44 deletions.
27 changes: 0 additions & 27 deletions solutions/#4.c

This file was deleted.

17 changes: 0 additions & 17 deletions solutions/#4i.c

This file was deleted.

Empty file added solutions/sol0.c
Empty file.
17 changes: 17 additions & 0 deletions solutions/sol004.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>

int main ()
{
// Defining function
int n;
printf("Enter an integer n of your choice:");
scanf("%d", &n);

// Writing formula to calculate the sum of first n natural number
int sum = ( n * ( n + 1)) / 2;

//Printing result
printf("Sum of the first %d natural numbers is %d\n", n, sum);

return 0;
}
52 changes: 52 additions & 0 deletions solutions/sol006.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <stdio.h>

#define PI 3.141

int main() {
int choice;

printf("Choose the desired shape :\n");
printf("1. Triangle\n");
printf("2. Rectangle\n");
printf("3. Circle\n");

printf("Enter your choice\n");
scanf("%d", &choice);

switch (choice) {
case 1: {
double base, height, area;
printf("Enter the base of triangle: ");
scanf("%lf", &base);
printf("Enter the height of triangle: ");
scanf("%lf", &height);
area = 0.5 * base*height;
printf("Area of the triangle is: %.2lf\n", area);
break;
}

case 2: {
double length, width, area;
printf("Enter the length of rectangle: ");
scanf("%lf", &length);
printf("Enter the width of rectangle: ");
scanf("%lf", &width);
area = length*width;
printf("Area of rectangle is: %.2lf\n", area);
break;
}

case 3: {
double radius, area;
printf("Enter the radius of circle: ");
scanf("%lf", &radius);
area = PI * radius*radius;
printf("Area of circle is: %.2lf\n", area);
break;
}
default:
printf("You entered wrong choice.\n");
}
return 0;
}

0 comments on commit fd691fc

Please sign in to comment.