Thursday 13 October 2011

A PROGRAM TO ENTER STUDENTE DETAILS AND DISPLAY IT IN PROPER FORMAT

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
 struct student
 {
  int rollno;
  char name[30];
  int marks;
 }stud[3];
 int i;
 clrscr();
 for(i=0;i<3;i++)
 {
  printf("Enter Roll no : ");
  scanf("%d",&stud[i].rollno);
  printf("Enter Name of student : ");
  scanf("%s",&stud[i].name);
  printf("Enter Marks : " );
  scanf("%d",&stud[i].marks);
 }
printf("\n                              STUDENT DETAILS");
printf("\n------------------------------------------------------------------------------");
printf("\n    ROLL NO       NAME                    MARKS");
printf("\n------------------------------------------------------------------------------\n");
 for(i=0;i<3;i++)
 {
  printf("\t%7d",stud[i].rollno);
  printf("\t\t   %s",stud[i].name);
  printf("\t\t\t%3d\n",stud[i].marks);
 }
printf("\n------------------------------------------------------------------------------");
 getch();
}
/*
OUTPUT:
Enter Roll no : 01
Enter Name of student : PAYAL
Enter Marks : 70
Enter Roll no : 02
Enter Name of student : URMILA
Enter Marks : 75
Enter Roll no : 03
Enter Name of student : KAJAL
Enter Marks : 65
         STUDENT DETAILS
------------------------------------------------------------------------------
    ROLL NO       NAME                    MARKS
------------------------------------------------------------------------------
    1     PAYAL    70
    2     URMILA    75
    3     KAJAL    65
------------------------------------------------------------------------------
*/

Sunday 9 October 2011

Difference between malloc() and calloc()

malloc() is used for allocating single block of memory while calloc() is used for allocating multiple blocks of memory.

The default value of mallo() is garbage value while in calloc it is zero.

malloc() takes one argument while calloc() takes two arguments.

Saturday 8 October 2011

gotoxy function in C

gotoxy function places cursor at a desired location on screen i.e. we can change cursor position using gotoxy function.
GotoXY is a function or procedure that positions the cursor at (X,Y), X in horizontal, Y in vertical direction relative to the origin of the current window. The origin is located at (1,1), the upper-left corner of the window.

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
printf("This is the first line.\n");
gotoxy(10,4);
printf("This is the second line.\n");
gotoxy(20,8);
printf("And this is line 3.\n");
getch();
}

C Language BCA-1 Chapter 2 questions

Discuss about conditional control structure?
What is loop? Discuss various looping structure in detail.
Describe continue and break statement.
Write detail about switch case.