DO NOT MISS

Ads

Friday 16 December 2016

C-Programs Using Structures(Static Time & Dynamic Time)


Example 1:- (Variable Assignment)

#include<stdio.h>
#include<conio.h>

struct sample
  {
       int a;
       float b;
       char c;
  }s;

void main()
  {
       struct sample s;
       clrscr();
 
       s.a=10;
       s.b=12.75;
       s.c='P';


       printf("a value is:%d\n",s.a);
       printf("b value is:%f\n",s.b);
       printf("c value is:%c\n",s.c);

   getch();

}

Output:-


Example 2:-(Variable Initialization)

#include<stdio.h>
#include<conio.h>

struct sample
   {
       int a;
       float b;
       char c;
   }s;


void main()
   {
       struct sample s={10,15.75,'K'};
       clrscr();

       printf("a value is:%d\n",s.a);
       printf("b value is:%f\n",s.b);
       printf("c value is:%c\n",s.c);

   getch();

}

Output:-


* To Print the Student Details

#include<stdio.h>
#include<conio.h>

struct student
  {
      int sno,age;
      char sname[20];
  }s;

void main()
  {
      struct student s;
      clrscr();

      printf("Enter a student no,name,age: ");
      scanf("%d%s%d",&s.sno,&s.sname,&s.age);

      printf("Student no :%d\n",s.sno);
      printf("Student name :%s\n",s.sname);
      printf("Student age :%d\n",s.age);

    getch();

  }
Output:-


* To Print the Employee Details


#include<stdio.h>
#include<conio.h> 

struct emp 
   { 
       int eno; 
       float esal; 
       char ename[20]; 
   }e; 

void main() 
  { 
      struct emp e; 
      clrscr(); 

      printf("Enter a Employee no,name,salary: "); 
      scanf("%d%s%f",&e.eno,&e.ename,&e.esal); 

      printf("Employe no :%d\n",e.eno); 
      printf("Employe name :%s\n",e.ename); 
      printf("Employe salary :%.2f\n",e.esal); 

    getch(); 

  }

Output:-


---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------


Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims