使用函数查找三个值中的最小值

时间:2018-08-13 11:41:37

标签: c

width

代码的逻辑应该放在第一个函数的注释中。然后,函数应产生minVal并在控制台上打印

3 个答案:

答案 0 :(得分:3)

import React, { Component } from 'react';
import { View, AsyncStorage } from 'react-native';
import { Form, Item, Input, Label, Button, Text } from 'native-base';
import axios from 'axios';
import { JWT } from 'App';

class RegistrationForm extends Component {
	constructor(props) {
		super(props);
		this.state = {
			name: '',
			email: '',
			emailValidate: '',
			pin: '',
			pinValidate: '',
			role: 'Consumer',
			pin_confirmation: ''
		};
	}

	onSubmit = () => {
		const { name, email, pin, role, pin_confirmation } = this.state;
		axios
			.post('http://0.0.0.0:4000/api/v1/sign_up', {
				user: {
					name,
					email,
					pin,
					role,
					pin_confirmation
				}
			})
			.then(response => {
				AsyncStorage.setItem('JWT', response.data.jwt);
				console.log(response.data.jwt);
				this.props.navigation.navigate('Profile');
			})
			.catch(error => {
				console.log(error);
			});
	};

	validate(text, type) {
		alph = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/g;
		if (type == 'email') {
			if (alph.test(text)) {
				this.setState((emailValidate = true));
			} else {
				this.setState((emailValidate = false));
			}
		}
		return type;
	}

	acceptTextInput = () => {
		if (emailValidate == true) {
			this.setState({ email: type });
		}
	};

	// this.setState({someField:someValue})

	render() {
		return (
			<View>
				<Form>
					<Item floatingLabel>
						<Label>Name</Label>
						<Input
							value={this.state.name}
							onChangeText={name => {
								this.setState({ name });
							}}
						/>
					</Item>
					<Item floatingLabel last>
						<Label>Email</Label>
						<Input
							autoCapitalize="none"
							value={this.acceptTextInput}
							onChangeText={text => this.validate(text, 'email')}
						/>
					</Item>
					<Item floatingLabel last>
						<Label>Pin</Label>
						<Input
							keyboardType={'number-pad'}
							secureTextEntry
							value={this.state.pin}
							onChangeText={pin => {
								this.setState({ pin });
							}}
						/>
					</Item>
					<Item floatingLabel last>
						<Label>Pin Confirmation</Label>
						<Input
							keyboardType={'number-pad'}
							secureTextEntry
							value={this.state.pin_confirmation}
							onChangeText={pin_confirmation => {
								this.setState({ pin_confirmation });
							}}
						/>
					</Item>
				</Form>
				<Button onPress={this.onSubmit}>
					<Text> Submit</Text>
				</Button>
			</View>
		);
	}
}

export default RegistrationForm;

答案 1 :(得分:1)

双重方法

int main(void)
{
     double a, b, c, temp, min;

     printf ("Enter three nos. separated by spaces: ");
     scanf ("%lf%lf%lf", &a, &b, &c);

     temp = (a < b)    ? a : b;
     min =  (c < temp) ? c : temp;

     printf ("The Minimum of the three is: %lf", min);

     /* indicate success */
     return 0;
 }

int方法

int main(void)
{
    int a, b, c, temp, min;

    printf ("Enter three nos. separated by spaces: ");
    scanf ("%d%d%d", &a, &b, &c);

    temp = (a < b)    ? a : b;
    min =  (c < temp) ? c : temp;

    printf ("The Minimum of the three is: %d", min);

    /* indicate success */
    return 0;
}

答案 2 :(得分:0)

首先,您应该为minValue函数返回类型为double的

那么你的逻辑应该是 考虑3个数字abc和另一个double temp 然后...

If (a < b)

Temp = a

Else

Temp = b

If(temp < c)

Return temp

Else 

Return c