Skip to content

Commit 0886704

Browse files
authored
cwh
1 parent 50958e0 commit 0886704

File tree

7 files changed

+114
-0
lines changed

7 files changed

+114
-0
lines changed

05_06_area_square.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include<stdio.h>
2+
#include<math.h>
3+
4+
int main(){
5+
int side;
6+
printf("Enter the value of side\n");
7+
scanf("%d", &side);
8+
printf("The value of area is %f", pow(side,2));
9+
10+
return 0;
11+
}

05_07_recursion.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include<stdio.h>
2+
int factorial(int x);
3+
4+
int main(){
5+
int a = 5;
6+
printf("The value of factorial %d is %d", a, factorial(a));
7+
return 0;
8+
}
9+
10+
int factorial(int x){
11+
printf("Calling factorial(%d)\n", x);
12+
if (x==1 || x==0){
13+
return 1;
14+
}
15+
else{
16+
return x * factorial(x-1);
17+
}
18+
}

05_08_pr01.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<stdio.h>
2+
float average(int a, int b, int c);
3+
4+
int main(){
5+
int a, b, c;
6+
printf("Enter the value of a\n");
7+
scanf("%d", &a);
8+
printf("Enter the value of b\n");
9+
scanf("%d", &b);
10+
printf("Enter the value of c\n");
11+
scanf("%d", &c);
12+
printf("The value of average is %f", average(a, b, c));
13+
return 0;
14+
}
15+
16+
float average(int a, int b, int c){
17+
float result;
18+
result = (float)(a + b + c)/3;
19+
return result;
20+
}

05_08_pr02.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// avg of 3 nos using func hardcoded inputs
2+
3+
#include<stdio.h>
4+
5+
int avg(int a , int b, int c)
6+
{
7+
int d;
8+
d= (a+b+c)/3;
9+
printf("The average of 3 numbers is: %d\n ", d);
10+
return d;
11+
}
12+
13+
int main()
14+
{
15+
int d;
16+
d=avg(2,3,2);
17+
return 0;
18+
}

05_09_pr03.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include<stdio.h>
2+
float force(float mass);
3+
int main(){
4+
float m;
5+
printf("Enter the value of mass in kgs\n");
6+
scanf("%f", &m);
7+
printf("The value of force in Newton is %.2f\n", force(m));
8+
return 0;
9+
}
10+
11+
float force(float mass){
12+
float result = mass * 9.8;
13+
return result;
14+
}

05_11_pr05.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include<stdio.h>
2+
3+
int main(){
4+
int a =3;
5+
printf("%d %d %d", a, ++a, a++);
6+
return 0;
7+
}

05_12_pr07.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include<stdio.h>
2+
void printPattern(int n);
3+
int main(){
4+
int n =4;
5+
printPattern(n);
6+
return 0;
7+
}
8+
// for n = 3
9+
// *
10+
// ***
11+
// *****
12+
// 1 - 1
13+
// 2 - 3
14+
// 3 - 5
15+
// (2n-1)
16+
void printPattern(int n){
17+
if (n==1){
18+
printf("*\n");
19+
return;
20+
}
21+
printPattern(n-1);
22+
for(int i=0;i<(2*n-1);i++){
23+
printf("*");
24+
}
25+
printf("\n");
26+
}

0 commit comments

Comments
 (0)