Pages

Showing posts with label C Language program. Show all posts
Showing posts with label C Language program. Show all posts

Monday, 21 May 2012

a program to print the use of pointer in structure



123./*Write a program to print the use of pointer in structure*/

#include<stdio.h>
#include<conio.h>
struct student
{
 int rollno;
 char name[20];
 };
 void main()
 {
 struct student s1={123,"mahesh"};
 struct student *sptr;
 clrscr();

 sptr=&s1;
 printf("\nThe details with the help of structure variable.....\n\n");
 printf("The roll number of the student is%d\n\n",s1.rollno);
 printf("The name of the student is%s\n\n",s1.name);
 printf("\nNow the details with the help of pointer.....\n\n");
 printf("\nThe roll number of the student is%d\n\n",sptr->rollno);
 printf("The name of the student is %s\n\n",sptr->name);
 getch();
 }


OUTPUT
                  The details with the help of structure variable....

   

     The roll number of the student is123


                 The name of the student is mahesh

                 Now the details with the help of pointer.....

                 The roll number of the student is123

                 The name of the student is mahesh

a program to print the structure variable pass in function


122./*Write a program to print the structure variable pass in function*/

#include<stdio.h>
#include<conio.h>
struct student
{
            int rollno;
            char name[40];
            };
            void main()
            {
            struct student s1;
            clrscr();

            printf("Enter roll number and name of the student:\n");
            scanf("%d%s",&s1.rollno,s1.name);
            display(s1);
            getch();
            }
            display(struct student s)
            {
             printf("\nThe roll number of the student is:%d\n",s.rollno);
             printf("\nThe name of the student is:%s",s.name);
}

OUTPUT

            Enter roll number and name of the student:
            23 RAM KUMAR
           
            The roll number of the student is: 23
           
The name of the student is: RAM KUMAR

a program to print the name, roll no, and date of brith


121./*Write a program to print the name, roll no, and date of brith*/

#include<stdio.h>
#include<conio.h>
struct date
{
            int dd,mm,yy;
            clrscr();
            };
            struct student
            {
            int roll;
            char name[20];
            struct date dob;
            };
            void main()
            {
             struct student p;
             clrscr();
             printf("Enter name");
             gets(p.name);
             printf("Enter roll no.");
             scanf("%d",&p.roll);
             printf("Enter dd/mm/yy");
             scanf("%d%d%d",&p.dob.dd,&p.dob.mm,&p.dob.yy);
             printf("\nName is %s",p.name);
             printf("\nRoll No. is%d",p.roll);
             printf("\nDOB is %d/%d/%d",p.dob.dd,p.dob.mm,p.dob.yy);
             getch();
}

OUTPUT
            Enter name :mahesh
            Enter roll no. 23

            Enter dd/mm/yy. 02/21/87

            Name is mahesh
            Roll No. is 23

            DOB 02/21/87

program to print the item,qty,price and multiplication of qty & price and find out his total value


120./*Write a program to print the item,qty,price and multiplication of qty & price and find out his total value*/                  

#include<stdio.h>
#include<conio.h>
struct inv
{
            int item;
            int qty;
            int price;
};
void main()
{
int i,count;
struct inv item[10];
clrscr();
printf("\nEnter Number of Itema:");
scanf("%d",&count);
printf("\n");
for(i=0;i<count;i++)
{
printf("ITEM:QTY:PRICE:");
scanf("%d%d%d",&item[i].item,&item[i].qty,&item[i].price);
}
value(item,count);
getch();
}
value(cal,num)
struct inv cal[10];
int num;
{
int i;
int value;
printf("\n\n********S T O C K V A L U E**********\n");
printf("\nITEM\tQTY\tPRICE\t\tQTY *PRICE");
for(i=0;i<num;i++)
{
value=cal[i].qty*cal[i].price;
printf("\n%d\t%d\t%d\t\t%d",cal[i].item,cal[i].qty,cal[i].price,value);
}
return(0);
}

OUTPUT
            Enter Number of Item : 1
            ITEM:QTY:PRICE:1 2 10
            ITEM:QTY:PRICE:
           
            **************S T O C K V A L U E******************
            ITEM              QTY                PRICE            QTY*PRICE
            1                      2                      10                    20

program to print the details of a student


119./*Write a program to print the details of a student*/

#include<stdio.h>
#include<conio.h>
struct student
{
int rollno;
char name[20];
};
struct personal
{
int age;
char phone[10];
struct student s1;
};
void main()
{
struct personal p1;
clrscr();
printf("Enter roll number and name of the student:\n");
scanf("%d%s",&p1.s1.rollno,p1.s1.name);
printf("\nEnter age and phone number of the student :\n");
scanf("%d%s",&p1.age,p1.phone);
printf("\nThe roll number of the student is:%d",p1.s1.rollno);
printf("\nThe name of the student is:%s",p1.s1.name);
printf("\nThe age of the student is: %d",p1.age);
printf("\nThe phone number of the student is:%s\n",p1.phone);
getch();
}


OUTPUT
            Enter roll number and name of the student:
23                RAM KUMAR VARMA

Enter age and phone number of the student:
20                277458

The roll number of the student is: 23

The name of the student is: mahesh

The age of the student is: 20

The phone number of the student is: 277458