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

Monday, October 20, 2014

PGDCA SAMPLE PAPER SET PROG. IN C LANG.



Sub Prog. in C                                                                                  
Total : 100 Marks                                                                              Time : 3 Hours
Que-1 Attempt Following Questions (Any Four):                                           [20]
1.     Explain data types available in C language.
2.     Explain structure of C program.
3.     Explain use of break, continue and goto statements.
4.     What is user define function? Explain types of UDF.
5.     List operators available in C. Explain any two.
Que-2 Attempt Following Questions (Any Four):                                           [20]
1.     What is an array? Explain two dimensional array’s memory management.
2.     Explain entry controlled loops with an example.
3.     What is recursion? Explain with suitable example.
4.     Explain Switch…case with example.
5.     Explain conditional statement with example.
Que-3 Attempt Following Questions (Any Four):                                           [20]
1.     Differences call by value v/s call by reference
2.     What is String? Explain any three string related functions.
3.     What is Pointer? Explain pointer of pointer with example.
4.     Explain any three file handling functions.
5.  Explain command line arguments with example.
Que-4 Attempt Following Questions (Any Four):                                           [20]
1. Explain storage classes in detail.
2. Explain  C Preprocessor.
3. What is structure? Explain array within structure with example.
4. What do you mean by variable, Explain naming rules of it.
5.  Explain back slash codes with example.
Que-5 Write Following Programs (Any Two).                                                  [20]
1.     Write a program to get a string from the user and counts lowercase letter, uppercase latter, space, symbols and digit print all of them.
2.     Write a program to generate following output for N  lines.
                                                          1
                                                       1 0 1
                                                    1 0 1 0 1
                                                           .
                                                           .
                                                      N lines  
3.  Write a program to open a file and print and store all contexts in another file.

Thursday, October 16, 2014

NOTEPAD IN C LANGUAGE


 ALGORITHM:


1.Display options new, open and exit and get choice.
2.If choice is 1 , call Create() function.
3.If choice is 2, call Display() function.
4.If choice is 3, call Append() function.
5.If choice is 4, call Delete() function.
6.If choice is 5, call Display() function.
7.Create()

7.1 Get the file name and open it in write mode.

    7.2 Get the text from the user to write it.
8.Display()
    8.1 Get the file name from user.
    8.2 Check whether the file is present or not.
    8.2 If present then display the of the file.
9.Append()
    9.1 Get the file name from user.
    9.2 Check whether the file is present or not.
    9.3 If present then append the file by getting the text to add with the existing file.
10. Delete()
    10.1 Get the file name from user.
    10.2 Check whether the file is present or not.
    10.3 If present then delete the existing file.

SOURCE CODE:

#include<stdio .h>
#include<conio .h>
#include<process .h>
int i,j,ec,fg,ec2;
char fn[20],e,c;
FILE *fp1,*fp2,*fp;
void Create();
void Append();
void Delete();
void Display();
void main()
{
 do {
  clrscr();
  printf("\n\t\t***** TEXT EDITOR *****");
  printf("\n\n\tMENU:\n\t-----\n ");
  printf("\n\t1.CREATE\n\t2.DISPLAY\n\t3.APPEND\n\t4.DELETE\n\t5.EXIT\n");
  printf("\n\tEnter your choice: ");
  scanf("%d",&ec);
  switch(ec)
  {
   case 1:
     Create();
     break;
   case 2:
     Display();
     break;
   case 3:
     Append();
     break;
   case 4:
     Delete();
     break;
   case 5:
     exit(0);
  }
 }while(1);
}
void Create()
{
 fp1=fopen("temp.txt","w");
 printf("\n\tEnter the text and press '.' to save\n\n\t");
 while(1)
 {
  c=getchar();
  fputc(c,fp1);
  if(c == '.')
  {
   fclose(fp1);
   printf("\n\tEnter then new filename: ");
   scanf("%s",fn);
   fp1=fopen("temp.txt","r");
   fp2=fopen(fn,"w");
   while(!feof(fp1))
   {
    c=getc(fp1);
    putc(c,fp2);
   }
   fclose(fp2);
   break;
  }}
}
void Display()
{
  printf("\n\tEnter the file name: ");
  scanf("%s",fn);
  fp1=fopen(fn,"r");
  if(fp1==NULL)
  {
   printf("\n\tFile not found!");
   goto end1;
  }
  while(!feof(fp1))
  {
   c=getc(fp1);
   printf("%c",c);
  }
end1:
  fclose(fp1);
  printf("\n\n\tPress any key to continue...");
  getch();
}
void Delete()
{
  printf("\n\tEnter the file name: ");
  scanf("%s",fn);
  fp1=fopen(fn,"r");
  if(fp1==NULL)
  {
   printf("\n\tFile not found!");
   goto end2;
  }
  fclose(fp1);
  if(remove(fn)==0)
  {
   printf("\n\n\tFile has been deleted successfully!");
   goto end2;
  }
  else
   printf("\n\tError!\n");
end2: printf("\n\n\tPress any key to continue...");
  getch();
}
void Append()
{
  printf("\n\tEnter the file name: ");
  scanf("%s",fn);
  fp1=fopen(fn,"r");
  if(fp1==NULL)
  {
   printf("\n\tFile not found!");
   goto end3;
  }
  while(!feof(fp1))
  {
   c=getc(fp1);
   printf("%c",c);
  }
  fclose(fp1);
  printf("\n\tType the text and press 'Ctrl+S' to append.\n");
  fp1=fopen(fn,"a");
  while(1)
  {
   c=getch();
   if(c==19)
    goto end3;
   if(c==13)
   {
    c='\n';
    printf("\n\t");
    fputc(c,fp1);
   }
   else
   {
    printf("%c",c);
    fputc(c,fp1);
   }
  }
end3: fclose(fp1);
  getch();
}

Saturday, August 2, 2014

swaping programme

#include 
 
int main()
{
   int x, y, temp;
 
   printf("Enter the value of x and y\n");
   scanf("%d%d", &x, &y);
 
   printf("Before Swapping\nx = %d\ny = %d\n",x,y);
 
   temp = x;
   x    = y;
   y    = temp;
 
   printf("After Swapping\nx = %d\ny = %d\n",x,y);
 
   return 0;
}

 
#include 
 
int main()
{
   int a, b;
 
   printf("Enter two integers to swap\n");
   scanf("%d%d", &a, &b);
 
   a = a + b;
   b = a - b;
   a = a - b;
 
   printf("a = %d\nb = %d\n",a,b);
   return 0;
}

Tuesday, October 4, 2011

marksheet using array

#include<stdio.h>

#include<conio.h>

void main()

{

int marks[4],tot=0,per,i;

clrscr();

for(i=0;i<4;i++)

{

printf("\nEnter Marks[%d subject]:",i+1);

scanf("%d",&marks[i]);

tot=tot+marks[i];

}

per=tot/4;

if(marks[0]>=40 && marks[1]>=40 && marks[2]>=40 && marks[3] >=40)

{

if(per >= 70)

{

printf("\nDistinction");

}

else if(per >= 60)

{

printf("\nFirst Class");

}

else if(per >= 50)

{

printf("\nSecond Class");

}

else

{

printf("\nPass");

}

printf("\n-------------------\n");

for(i=0;i<4;i++)

{

printf("\n subject %d : %d",i+1,marks[i]);

}

printf("\n-------------------\n");

printf("\n total : %d",tot);

printf("\n percentage : %.2f",(float)per);

printf("\n-------------------\n");


}

else

{

gotoxy(35,12);

textcolor(RED+BLINK);

cprintf("Fail");

}

getch();


}