Results 1 to 16 of 16

Thread: C!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Nov:2008
    Location: Sofia
    Posts: 15

    C!

    , . . ( ), :
    25, 17, 20, 18
    ( ):
    - ;
    - ;
    - ;
    - .
    25
    17
    20
    18
    ____________________
    20.0

    :

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #define MAX 30
    struct people
    {
    char name[50];
    int year;
    };
    void menu()
    {
    printf("\n1.Add people and their years \n");
    printf("2.List of all people \n");
    printf("3.Middle-aged people \n");
    printf("4.Table with information for people \n");
    printf("5.Exit \n");
    }
    float sredna_vyzrast(struct people group[], int current_num_people)
    {
    int i;
    int sum=0;
    float sr_sum;
    for(i=0;i<current_num_people;i++)sum=sum +group[i].year;



    sr_sum=(sum/current_num_people);
    return sr_sum;
    }
    void print_person(struct people group)
    {
    printf("%s",group.name);
    }
    void print_years(struct people group)
    {
    printf("%d",group.year);

    }




    int main(void)
    {
    int num_people,current_num_people=0;
    struct people group[MAX],temp[MAX];
    int i,j,choice;
    int sum=0;
    float sr_sum;
    char search;
    do
    {
    printf("count people: ");
    scanf("%d",&num_people);
    }
    while (num_people>MAX);
    printf("\n\n");
    do
    {
    menu();
    scanf("%d",&choice);
    switch(choice)
    {
    case 1:
    for(i=0;i<num_people;i++)
    {
    printf("Person: ");
    printf("\nName: ");
    scanf("%s",&group[i].name);
    printf("Year: ");
    scanf("%d",&group[i].year);
    printf("\n");
    current_num_people++;
    }
    break;
    case 2:
    printf("People: \n");
    for(i=0;i<current_num_people;i++)
    {
    if(i!=0)
    printf(",");
    printf("%s\t",group[i].name);
    printf("%d",group[i].year);


    }
    break;
    case 3:
    printf("srednata vyzrast e: %.1f",sredna_vyzrast(group,current_num_p eople));
    printf("\n");
    break;
    case 4:
    for(i=0;i<current_num_people;i++)
    {
    printf("\n");
    print_person(group[i]);
    printf("\t\t");
    print_years(group[i]);
    }
    {
    printf("\n");
    printf("___________________");
    printf("\n");
    printf("Sr.vyzrast \t");
    printf("%.1f",sredna_vyzrast(group,curre nt_num_people));

    }
    break;
    case 5:
    exit(0);
    break;
    }
    }
    while(1);
    return 0;
    }

    , ..

  2. #2
    Registered User
    Join Date: Oct:2006
    Location: Plovdiv
    Posts: 305
    prepBut nI vrbLike adjHungarian! qWhat's artThe adjBig nProblem?

  3. #3
    Registered User
    Join Date: Nov:2008
    Location: Sofia
    Posts: 15
    ..

  4. #4
    Registered User
    Join Date: Dec:2007
    Location: Sofia
    Posts: 366
    , / .
    , FILE* . fopen(). fclose(). / fprintf()/fscanf(), printf()/scanf(), , , - .

  5. #5
    Registered User
    Join Date: Nov:2008
    Location: Sofia
    Posts: 15
    Quote Originally Posted by Pheoman View Post
    , / .
    , FILE* . fopen(). fclose(). / fprintf()/fscanf(), printf()/scanf(), , , - .
    , ...

  6. #6
    Registered User Mechkov's Avatar
    Join Date: Jan:2009
    Location: internet
    Posts: 531
    FILE*. , fopen(). :
    Code:
    FILE *in,*out;
    in=fopen("in.txt","r");
    out=fopen("out.txt","w");
    in in.txt , out out.txt . / fprintf() fscanf() printf() scanf() , , /. :
    Code:
    fscanf(in,"%s",string);
    fscanf(in,"%d",integer);
    fprintf(out,"Hello, World!\n");
    <stdio.h>
    Quote Originally Posted by Pheoman View Post
    @Mechkov, ,
    , , 1 ( ) .
    fclose() .
    . , , - 5 . USACO /, , . 1000 ( 5 ).
    Last edited by Mechkov; 28th April 2009 at 08:14.

  7. #7
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    ++, , , ?!

    , , / .

    ( '', ), . , , , , .

  8. #8
    Registered User
    Join Date: Nov:2008
    Location: Sofia
    Posts: 15
    Quote Originally Posted by tedych View Post
    ++, , , ?!

    , , / .

    ( '', ), . , , , , .
    , ...

    ---------- 14:09 ---------- 14:01 ----------

    , .....

    ---------- 14:17 ---------- 14:09 ----------

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <conio.h>
    #define MAX 30
    int size;
    struct people
    {
           
           char name[50];
           int year;
           
           
           };
           void menu()
           {
                printf("\n1.Write \n");
                printf("2.Read \n");
                printf("3.Add people and their years \n");
                printf("4.List of all people \n");
                printf("5.Middle-aged people \n");
                printf("6.Table with information for people \n");
                printf("7.Exit \n");
                }
    
                float sredna_vyzrast(struct people group[], int current_num_people)
                {
                     int i;
                      int sum=0;
                      float sr_sum;
                      for(i=0;i<current_num_people;i++)sum=sum+group[i].year;
                      
                                                       
                                                       
                                                       sr_sum=(sum/current_num_people);
                                                       return sr_sum;
                                                       }
                                                       void print_person(struct people group)
                                                       {
                                                            printf("%s",group.name);
                                                            }
                                                            void print_years(struct people group)
                                                            {
                                                            printf("%d",group.year);
                                                            
                                                            }
                                                            
                                                            
                                                            
                                                                 int num_people,current_num_people=0;
                                                                struct people group[MAX],temp[MAX];
                                                                int i,j;
                                                                int sum=0;
                                                                float sr_sum;
                                                                char search;
                                                            void add()
                                                            {
                                                                
                                                                
                                                                do
                                                                {
                                                                
                                                                     printf("count people: ");
                                                                     scanf("%d",&num_people);
                                                                     }
                                                                     while (num_people>MAX);
                                                                     printf("\n\n");
                                                                     
                                                                
                                                                          
                                                                                        
                                                                                             for(i=0;i<num_people;i++)
                                                                                             {
                                                                                                                      printf("Person: ");
                                                                                                                      printf("\nName: ");
                                                                                                                      scanf("%s",&group[i].name);
                                                                                                                      printf("Year: ");
                                                                                                                      scanf("%d",&group[i].year);
                                                                                                                      printf("\n");
                                                                                                                      current_num_people++;
                                                                                                                      }
                                                                                                                      }
                                                                                                                      
                                                                                                                      
                                                                                                                      void print(){
                                                                                                                           printf("People: \n");
                                                                                                                           for(i=0;i<current_num_people;i++)
                                                                                                                           {
                                                                                                                                                           if(i!=0)
                                                                                                                                                           printf(",");
                                                                                                                                                            printf("%s\t",group[i].name);
                                                                                                                                                            printf("%d",group[i].year);
                                                                                                                                                            
                                                                                                                                                            
                                                                                                                                                            }
                                                                                                                                                            }
                                                                                                                                                            void load(){
    	int i;
    	char namez[ 100 ];
    	FILE *in;
    
    	size = 0;
    
    	printf("File name: ");
    	scanf("%s", namez);
    
    	in = fopen(namez, "rt");
    	fscanf(in, "%d", &size);
    	for(i=0; i<size; i++){
    		fscanf(in, "%s %d \n", &group[i].name, &group[i].year);
    	}
    	fclose( in );
    }
    
     void save(){
    	int i;
    	char namez[ 100 ];
    	FILE *out;
    
    	printf("File name: ");
    	scanf("%s", namez);
    
    	out = fopen(namez, "wt");
    	fprintf(out, "%d\n", size);
    	for(i=0; i<size; i++){
    		fprintf(out, "%s %d \n", group[i].name,group[i].year);
    	}
    	fclose( out );
    }
                                                                                                                                                            void vyzrast(){
                                                                                                                                                                 printf("srednata vyzrast e: %.1f",sredna_vyzrast(group,current_num_people));
                                                                                                                                                                 printf("\n");
                                                                                                                                                                 }
                                                                                                                                                                 void tablica(){
                                                                                                                                                                      for(i=0;i<current_num_people;i++)
                                                                                                                                                                      {
                                                                                                                                                                      printf("\n");
                                                                                                                                                                      print_person(group[i]);
                                                                                                                                                                      printf("\t\t");
                                                                                                                                                                      print_years(group[i]);
                                                                                                                                                                      }
                                                                                                                                                                      {
                                                                                                                                                                                            printf("\n");
                                                                                                                                                                                            printf("___________________");
                                                                                                                                                                                            printf("\n");
                                                                                                                                                                      printf("Sr.vyzrast \t");
                                                                                                                                                                      printf("%.1f",sredna_vyzrast(group,current_num_people));
                                                                                                                                                                      
                                                                                                                                                                      }
                                                                                                                                                                      }  
                                                                                                                                                                 void exitt(){
                                                                                                                                                                      exit(0);
                                                                                                                                                                      
                                                                                                                                                                      
                                                                                                                                                                      
                                                                                                                                                                      }
                                                                                                                                                                      int main(void)
                                                                                                                                                                      {
                                                                                                                                                                      int choice = 0;
                                                                                                                                                                      
                                                                                                                                                                 
                                                                                                                                                                      while(1)
                                                                                                                                                                      
                                                                                                                                                                      {
                                                                                                                                                                      
                                                                                                                                                                             menu();
                                                                                                                                                                             scanf("%d",&choice);
                                                                                                                                                                              switch(choice)
                                                                                                                                                                              {
                                                                                                                                                                                              case 1:save();
                                                                                                                                                                                              break;
                                                                                                                                                                                              case 2:load();
                                                                                                                                                                                              break;
                                                                                                                                                                                              case 3:add();
                                                                                                                                                                                              break;
                                                                                                                                                                                              case 4:print();
                                                                                                                                                                                              break;
                                                                                                                                                                                              case 5:vyzrast();
                                                                                                                                                                                              break;
                                                                                                                                                                                              case 6:tablica();
                                                                                                                                                                                              break;
                                                                                                                                                                                              case 7:exitt();
                                                                                                                                                                                              break;
                                                                                                                                                                                              }
                                                                                                                                                                                              }
                                                                                                                                                                                              return 0;
                                                                                                                                                                                              }
    .. 0 :S

  9. #9
    Registered User
    Join Date: Dec:2007
    Location: Sofia
    Posts: 366
    0, size 0. 0, , , .

  10. #10
    Registered User
    Join Date: Oct:2006
    Location: Plovdiv
    Posts: 305
    Quote Originally Posted by CuST0M1z3 View Post
    [/COLOR] , .....[COLOR="Silver"]
    - .

    :

    1. 2 ( )
    2. size? current_num_people?
    3. num_people current_num_people num_people e 1 ?

    4. () size ?

    5. - ...

    ( - )

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <conio.h>
    
    
    #define MAX 30
    
    struct people
    {
        char name[50];
        int year;
    };
    
    
    
    struct people group[MAX],temp[MAX];
    int current_num_people=0;
    
    
    
    
    
    
    
    
    void menu()
    {
        printf("\n1.Write \n");
        printf("2.Read \n");
        printf("3.Add people and their years \n");
        printf("4.List of all people \n");
        printf("5.Middle-aged people \n");
        printf("6.Table with information for people \n");
        printf("7.Exit \n");
    }
    
    float sredna_vyzrast(struct people group[], int current_num_people)
    {
        int i;
        float sum=0;
        float sr_sum;
        for(i=0;i<current_num_people;i++)sum += group[i].year;
    
        sr_sum=(sum/current_num_people);
        return sr_sum;
    }
    
    
    void print_person(struct people group)
    {
        printf("%s",group.name);
    }
    
    
    
    void print_years(struct people group)
    {
        printf("%d",group.year);
    
    }
    
    
    
    void add()
    {
        int num_people;
        do
        {
    
            printf("count people: ");
            scanf("%d",&num_people);
        }
        while (num_people>MAX);
        printf("\n\n");
    
    
    
        for(int i=0;i<num_people;i++)
        {
            printf("Person #%d",i);
            printf("\nName: ");
            scanf("%s",&group[i].name);
            printf("Year: ");
            scanf("%d",&group[i].year);
            printf("\n");
            current_num_people++;
        }
    }
    
    
    void print(){
        printf("People: \n");
        for(int i=0;i<current_num_people;i++)
        {
            if(i!=0)
                printf(",");
            printf("%s\t",group[i].name);
            printf("%d",group[i].year);
    
    
        }
    }
    
    
    void load(){
        int i;
        char namez[ 100 ];
        FILE *in;
    
        printf("File name: ");
        scanf("%s", namez);
    
        in = fopen(namez, "rt");
        fscanf(in, "%d", &current_num_people);
        for(i=0; i<current_num_people; i++){
            fscanf(in, "%s %d \n", &group[i].name, &group[i].year);
        }
        fclose( in );
    }
    
    
    
    void save(){
        int i;
        char namez[ 100 ];
        FILE *out;
    
        printf("File name: ");
        scanf("%s", namez);
    
        out = fopen(namez, "wt");
        fprintf(out, "%d\n", current_num_people);
        for(i=0; i<current_num_people; i++){
            fprintf(out, "%s %d \n", group[i].name,group[i].year);
        }
        fclose( out );
    }
    
    
    
    void vyzrast(){
        printf("srednata vyzrast e: %.1f",sredna_vyzrast(group,current_num_people));
        printf("\n");
    }
    
    
    void tablica(){
        for(int i=0;i<current_num_people;i++)
        {
            printf("\n");
            print_person(group[i]);
            printf("\t\t");
            print_years(group[i]);
        }
        {
            printf("\n");
            printf("___________________");
            printf("\n");
            printf("Sr.vyzrast \t");
            printf("%.1f",sredna_vyzrast(group,current_num_people));
    
        }
    }  
    
    
    
    
    void exitt(){
        exit(0);
    }
    
    
    
    
    int main(void)
    {
        int choice = 0;
    
    
        while(1)
        {
    
            menu();
            scanf("%d",&choice);
            switch(choice)
            {
            case 1:save();
                break;
            case 2:load();
                break;
            case 3:add();
                break;
            case 4:print();
                break;
            case 5:vyzrast();
                break;
            case 6:tablica();
                break;
            case 7:exitt();
                break;
            }
        }
        return 0;
    }



    Quote Originally Posted by CuST0M1z3 View Post
    20 30 .. ..
    ... Dimple
    prepBut nI vrbLike adjHungarian! qWhat's artThe adjBig nProblem?

  11. #11
    Registered User
    Join Date: Nov:2008
    Location: Sofia
    Posts: 15
    ... C * , ... (bow)

  12. #12
    Registered User
    Join Date: Oct:2006
    Location: Plovdiv
    Posts: 305
    , .

    , pascal java

    :

    Code:
    void load(){
        int i;
        char namez[ 100 ];
        FILE *in;
    
        printf("File name: ");
        scanf("%s", namez);
    
        in = fopen(namez, "rt");
        fscanf(in, "%d", &current_num_people);
        for(i=0; i<current_num_people; i++){
            fscanf(in, "%s %d \n", &group[i].name, &group[i].year);
        }
        fclose( in );
    }
    ( ) ()

    Code:
    procedure load();
    var f: textfile; namez: string; i: integer;
    begin
        Write('File name: ');
        ReadLn(namez);
    
        AssignFile(f, namez);
        Reset(f);
        ReadLn(f, current_num_people);
        for i:= 0 to current_num_people-1 do
        begin
            ReadLn(f, group[i].name, group[i].year);
        end;
        CloseFile(f);
    end;
    prepBut nI vrbLike adjHungarian! qWhat's artThe adjBig nProblem?

  13. #13
    Registered User
    Join Date: Nov:2008
    Location: Sofia
    Posts: 15
    (bow) 6 ,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |