Skip to content

Commit 24edbe6

Browse files
committed
new file: r/CMakeLists.txt
new file: r/main.c new file: r/resistor/CMakeLists.txt new file: r/resistor/build.sh new file: r/resistor/resistorcal.c new file: r/resistor/resistorcal.h modified: resistor/src/main.c new file: ../go/helloworld/main.go
1 parent 0e45a5a commit 24edbe6

File tree

8 files changed

+56
-2
lines changed

8 files changed

+56
-2
lines changed

c/r/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.9)
2+
PROJECT(RESISTOR)
3+
ADD_SUBDIRECTORY(resistor)
4+
AUX_SOURCE_DIRECTORY(. DIR_SRC)
5+
ADD_EXECUTABLE(bin ${DIR_SRC})
6+
TARGET_LINK_LIBRARIES(bin RESISTOR)

c/r/main.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <stdio.h>
2+
#include "resistor/resistorcal.h"
3+
int main(){
4+
printf("Welcome to Mayuri's Resistor Calculator(Only for separate routes and 2 resistor in it)\n");
5+
printf("Make your choice\n> 1.Your have the two resistors of separate routes\n> 2. Your have one of the resistors in the separate routes and the total resistor\nAny other choice is to exit\n");
6+
char choice;
7+
scanf("%c",&choice);
8+
switch (choice){
9+
case '1' : printf("Please input your args as [R1 R2]:\n");break;
10+
case '2' : printf("Please input your args as [R1 R]:\n");break;
11+
default : printf("exiting\n");return 0;break;
12+
}
13+
double r1 = -1 ,r2 = -1;
14+
scanf("%lf %lf",&r1,&r2);
15+
while ((r1<0)||(r2<0)) {
16+
printf("args don't meet the requirement(R>0)\n");
17+
printf("please input them again:\n");
18+
scanf("%lf %lf",&r1,&r2);
19+
20+
}
21+
switch (choice){
22+
case '1' : printf("R=%lf\n",resistorcal(r1,r2,choice));break;
23+
case '2' : printf("R2=%lf\n",resistorcal(r1,r2,choice));break;
24+
}
25+
}

c/r/resistor/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
AUX_SOURCE_DIRECTORY(. DIR_LIB_SRCS)
2+
ADD_LIBRARY(RESISTOR ${DIR_LIB_SRCS})

c/r/resistor/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rm -rf build && mkdir -p build &&cd build && cmake ..&& make

c/r/resistor/resistorcal.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdio.h>
2+
#include "resistorcal.h"
3+
double resistorcal(double R1,double R2,char type){
4+
switch (type){
5+
case '1' : return (R1*R2)/(R1+R2); break;
6+
case '2' : return (R1*R2)/(R1-R2); break;
7+
}
8+
return (double)0;
9+
}

c/r/resistor/resistorcal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef _RESISTOR_H
2+
#define _RESISTOR_H
3+
double resistorcal(double R1,double R2,char type);
4+
#endif

c/resistor/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int main(){
1919

2020
}
2121
switch (choice){
22-
case '1' : printf("R=%lf",resistorcal(r1,r2,choice));break;
23-
case '2' : printf("R2=%lf",resistorcal(r1,r2,choice));break;
22+
case '1' : printf("R=%lf\n",resistorcal(r1,r2,choice));break;
23+
case '2' : printf("R2=%lf\n",resistorcal(r1,r2,choice));break;
2424
}
2525
}

go/helloworld/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
fmt.Println("helloworld")
7+
}

0 commit comments

Comments
 (0)