Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,945 questions

51,887 answers

573 users

How to use simple struct to store and display information in C

3 Answers

0 votes
#include <stdio.h> 
 
struct worker
{
    char name[30];
    int age;
    float salary;
} w;

int main(void)
{
    printf("Enter worker name: ");
    scanf("%s", w.name);

    printf("Enter worker age: ");
    scanf("%d", &w.age);

    printf("Enter worker salary: ");
    scanf("%f", &w.salary);

    printf("\nWorker name: %s\n", w.name);
    printf("Worker age: %d\n", w.age);
    printf("Worker salary: %.2f\n", w.salary);
       
    return 0;
}
   
           
/*
run:
        
Enter worker name: dan
Enter worker age: 45
Enter worker salary: 13900

Worker name: dan
Worker age: 45
Worker salary: 13900.00
  
*/

 



answered May 25, 2017 by avibootz
0 votes
#include <stdio.h> 
#include <string.h> 
 
struct worker
{
    char name[30];
    int age;
    float salary;
} w;

int main(void)
{
    strcpy(w.name, "dan");
    w.age = 45;
    w.salary = 13900;

    printf("Worker name: %s\n", w.name);
    printf("Worker age: %d\n", w.age);
    printf("Worker salary: %.2f\n", w.salary);
       
    return 0;
}
   
           
/*
run:
        
Worker name: dan
Worker age: 45
Worker salary: 13900.00

*/

 



answered May 25, 2017 by avibootz
0 votes
#include <stdio.h> 
#include <string.h> 
 
struct worker
{
    char name[30];
    int age;
    float salary;
};

int main(void)
{
    struct worker w;
    
    strcpy(w.name, "dan");
    w.age = 45;
    w.salary = 13900;

    printf("Worker name: %s\n", w.name);
    printf("Worker age: %d\n", w.age);
    printf("Worker salary: %.2f\n", w.salary);
       
    return 0;
}
   
           
/*
run:
        
Worker name: dan
Worker age: 45
Worker salary: 13900.00

*/

 



answered May 25, 2017 by avibootz

Related questions

1 answer 168 views
168 views asked Oct 7, 2014 by avibootz
2 answers 234 views
1 answer 99 views
1 answer 117 views
117 views asked Apr 27, 2017 by avibootz
1 answer 190 views
...