-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path'
79 lines (66 loc) · 1.56 KB
/
'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
int assingmentTwo(){
int len;
int hei;
printf("What is the length: ");
scanf("%d", &len);
printf("What is the Height: ");
scanf("%d", &hei);
int area = len * hei;
printf("The area of the rectangle is: %d", area);
}
int exerciseThree(){
int input;
scanf("%d", &input);
for(int b = 1; b <= input; ++b){
for(int j = 1; j <= b; ++j){
printf("*");
}
printf("\n");
}
for(int a = input; a >= 0; --a){
for(int l = a; l >= 0; --l){
printf("*");
}
printf("\n");
}
}
int exerciseTwo(){
/* Write a program to read 10 numbers from the keyboard and find their sum and average.*/
int sum = 0;
for(int i = 0; i <= 10; i++){
int n;
scanf("Number: %d", &n);
sum += n;
}
float avg = sum / 10;
printf("The sum of 10 no. is: %d\nThe Average is: %fl", sum, avg);
}
int exerciseOne() {
/*Write a program to display n terms of natural numbers and their sum*/
int n;
printf("What is n? ");
scanf("%d", &n);
int sum = 0;
for(int i = 0; i <= n; i++){
printf("%d ", i);
sum += i;
}
printf("\n");
printf("The Sum of Natural Numbers up to 7 terms: %d \n", sum);
}
int main(){
int Userinput;
printf("Your choice: ");
scanf("%d", &Userinput);
if(Userinput == 1){
exerciseOne();
}
else if(Userinput == 2){
exerciseTwo();
}else if(Userinput == 3){
exerciseThree();
}else if(Userinput == 4){
assingmentTwo();
}
}