forked from muruga21/C-problems-Hacktoberfest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from RealCifer/RealCifer-4
Added solution for issue #48 that is question 6
- Loading branch information
Showing
5 changed files
with
69 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|