Share scripts, the same problem, PHP and Shell notation

Source: Internet
Author: User

About writing scripts, 1 2 3 5 8 13 ...... Write it out with a script, what's the 100th number?

Shell

######### #下面是脚本内容 ##########

#!/bin/bash
For ((i=1;i<=100;i++))
Do
If [$i-eq 1];then
Let S[1]=1
elif [$i-eq 2];then
Let s[2]=2
Else
Let s[$i]=s[i-1]+s[i-2]
Fi
Done
echo "$ ((s[100]))"

######### #shell脚本到此为止 # # # #

It is worth noting that let do mathematical operations without using $, the final output of the 100th number, to add (()), otherwise only output S[100]

Php

Here is the script content/////////////////

<?php
for ($i =1; $i <=100; $i + +)
{
if ($i ==1)
{
$s [1]=1;
}
ElseIf ($i ==2)
{
$s [2]=2;
}
Else
{
$s [$i]= $s [$i -1]+ $s [$i-2];
}
}
echo "$s [100]";
?>

The script ends here///////////////////

It is worth noting that if the judgment is = = or = = =, it is best to add the contents of each if statement {}.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.