Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Thursday, February 17, 2011

C22 : Declare a memory variable and print its address

Back to Home   &  C


//Declare a memory variable and print its address  by using a pointer variable.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,*p;
clrscr();
p=&n;
printf("Address of variable n=%u",p);
getch();
}
---------------------------------------------------
Output
Address of variable n = 65524
========================================================
Back to Home   &  C

C21 : Enter details using Structures

Back to Home   &  C


A ))) //Program to enter student details by using a structure called stud

#include<stdio.h>
#include<conio.h>
struct stud
{
int rno;
char name[20];
char branch[20];
};
void main()
    {
    clrscr();
    struct stud s;
    printf("Enter roll no\n");
    scanf("%d",&s.rno);
    printf("Enter name\n");
    scanf("%s",s.name);
    printf("Enter branch\n");
    scanf("%s",&s.branch);
       clrscr();
       printf("Details of the student is..\n");
       printf("Roll number-%d\nName-%s\nBranch-%s\n",s.rno,s.name,s.branch);
getch();
}
----------------------------------------------------------------------------
Output :
Enter roll no
1
Enter name
aaa
Enter branch
Computer Science
Details of the student is..
Roll No-1
Name-aaa
Branch-Computer Science
===============================================
//you can write the above printf statement as :
printf("Roll number=%d\n",s.rno);
printf("Name=%s\n",s.name);
printf("Branch=%s\n",s.branch);
=========================================================================

B ))) //Program to enter n number of employee details by using a structure called emp


#include<stdio.h>
#include<conio.h>
struct emp
{
char name[20];
char dept[20];
int code;
};
void main()
{
struct emp e[20];
int i,n;
clrscr();
printf("Enter number of employee\n");
scanf("%d\n",&n);
for(i=0;i<=n;i++)
printf("Enter employee name\n");
scanf("%s",e[i].name);
printf("Enter department\n");
scanf("%s",e[i].dept);
printf("Enter employee code\n");
scanf("%d",&e[i].code);
clrscr();
printf("Name\tDepartment\tcode\n");
for(i=0;i<=n;i++)
{
printf("%s\t%s\t%d\n",e[i].name,e[i].dept,e[i].code);
}
getch();
}
-------------------------------------------------------------------------------
Output
Enter number of employee
2
Enter employee name
aaa
Enter department
Computer Science
Enter employee code
11

Enter employee name
bbb
Enter department
Maths
Enter employee code
22
This will print as :
Name    Dept            code
aaa         cs                11
bbb        maths           22
===============================================

C ))) //Program to enter n number of student details,
enter 3 subject mark, and find total marks (by using a structure called student)


#include<stdio.h>
#include<conio.h>
struct student
{
int rno;
char name[20];
int m1,m2,m3,t;
};
void main()
    {
    clrscr();
    struct student s[20];
    int i,n;
    printf("Enter number of students\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    printf("Enter roll no\n");
    scanf("%d",&s[i].rno);
    printf("Enter name\n");
    scanf("%s",s[i].name);
    printf("Enter 3 subject marks\n");
    scanf("%d%d%d",&s[i].m1,&s[i].m2,&s[i].m3);
    s[i].t=s[i].m1+s[i].m2+s[i].m3;
    }
     clrscr();
     printf("Details of the student is..\n");
     printf("Name\tRno\tMark1\tMark2\tMark3\tTotal\n");
     for(i=0;i<n;i++)
{
printf("%s\t%d\t%d\t%d\t%d\t%d\n",s[i].name,s[i].rno,s[i].m1,s[i].m2,s[i].m3,s[i].t);
getch();
     }
     }
-------------------------------------------------------------
Output
Enter number of students
2
Enter roll no
1
Enter name
aa
Enter 3 subject marks
21
34
56

Enter roll no
2
Enter name
bb
Enter 3 subject marks
65
65
89
This will print as :
Roll no    name          mark1     mark2    mark3    total
1              aa                  21             34          56        111
2              bb                 65            65           89         219
===============================================
Back to Home   &  C