Hirdetés

Új hozzászólás Aktív témák

  • cellpeti

    veterán

    válasz Karma #1333 üzenetére

    igen!

    Így néz ki a progi:

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


    int getline(char s[],int lim){
    int i,c;
    for (i=0;i<lim && (c=getchar())!=EOF && c!='\n';++i)
    s[i]=c;
    s[i]='\0';
    while (c!=EOF && c!='\n')
    c=getchar();
    return (i);
    }

    int lebege(char s[]){
    int i=0, kezd;
    while(isspace(s[i])) ++i;
    if(s[i]=='+'||s[i]=='-') ++i;
    kezd=i;
    while(isdigit(s[i])) ++i;
    if(s[i]=='.') ++i;
    while(isdigit(s[i])) ++i;
    if(i==kezd||kezd+1==i&&s[kezd]=='.') return 0;
    if(toupper(s[i])=='E'){
    ++i;
    if(s[i]=='+'||s[i]=='-')++i;
    if(!isdigit(s[i])) return 0;
    while(isdigit(s[i])) ++i;}
    if(isspace(s[i])||!s[i]) return 1;
    else return 0;
    }


    void main (void)
    {
    float r,T,K;
    float pi=3.14;
    char s[24];
    int ok=1;
    do
    {
    ok=1;
    printf("Adja meg a kor sugarat!\n\n");
    if(!getline (s,25))
    {
    printf("Üres sort adtal meg!\n\n");
    ok=0;
    }
    else
    {
    if(!lebege(s))
    {
    printf("Nem lebegopontos a megadott szam!\n");
    ok=0;
    }
    else
    r=atof(s);
    }
    }while(ok==0);

    K=2*r*pi;
    T=r*r*pi;
    printf("\nA kor kerulete: %.2f\n\nA kor terulete: %.2f\n\n",K,T);
    getch();
    }

    [ Szerkesztve ]

    Tigris, tigris, csóvafény...

Új hozzászólás Aktív témák