Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

create new vector which uses range typed from keybord and steps by 0.25

I have to create a code to create new vector which is created of range typed by user. For ex: we start with 3 and end with 9. So i need crate vector forom 3 to 9 stepped by 0.25

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    float starts=0;
    float ends=0;
    float stepo = 0.25;
    float tab[]={};
    int startInt = 0;
    int endInt = 0;
    int counter = 0;
    printf("Podaj poczatek:
");// "Type starting int"
    scanf("%d", &endInt);
    printf("Podaj koniec:
"); // "Type ending int"
    scanf("%d", &startInt); 
    int diff = startInt - endInt;
    printf("%d
", diff);
    starts= startInt;
    ends= endInt;
    for (int i = 0; i< (diff)*4; i++) {
        tab[i]= ends;
        printf("%f
", tab[i]);**strong text**
        ends = ends + stepo;
    }
    return 0;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I solved it by my own ;-) "float tab[]={};" it was a problem.

 #include <stdio.h>
  #include <stdlib.h>
  #include <math.h>

    int main()
           {
    float starts=0;
    float ends=0;
    float stepo = 0.25;

    printf("Podaj poczatek:
");
    scanf("%f", &ends);
    printf("Podaj koniec:
");
    scanf("%f", &starts);
    float diff = starts - ends;
    printf("%f
", diff);
    int tabSize = diff *4;
    float tab[tabSize];

    for (int i = 0; i<=diff*4; i++){
        tab[i]= ends;
        printf("%8.2f
", tab[i]);
        ends = ends + stepo;

    }

    return 0;
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...