Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k 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 Reply

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;
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...