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

Monday, November 15, 2010

Write a program to read an alphanumeric from user and check whether entered alphanumeric is (1) Capital Alphabet (2) Small Alphabet (3) Number

/* Write a program to read an alphanumeric from user and check whether entered alphanumeric is (1) Capital Alphabet (2) Small Alphabet (3) Number
   Developed by : Malhar Vora
   Developed on : 15-11-2010
   Development Status : Completed and tested
   Email : vbmade2000@gmail.com
   WebSite : www.malhar2010.blogspot.com
**************************************************************************/
void main()
{

 char c;
 printf("Enter any alphanumeric character :");
 scanf("%c",&c);

 if(c>=48 && c<=57)
 {
        printf("Number");
        return;
 }
 else if(c>=65 && c<=91)
 {
        printf("Capital alphabet");
        return;
 }
 else if(c>=97 && c<=123)
 {
        printf("Small Alphabet");
        return;
 }
 else
 {
        printf("Unknown symbol");
        return;
 }

}

A program to read an integer no recursively until the user enters negative numbers

/* Write a program to read an integer no recursively until the user enters negative numbers
   and find the sum of nos entered by the user
   Developed by : Malhar Vora
   Developed on : 15-11-2010
   Development Status : Completed and tested
   Email : vbmade2000@gmail.com
   WebSite : www.malhar2010.blogspot.com
********************************************************************************************/
int a=0,sum=0;

void main()
{
   printf("Enter no :");
   scanf("%d",&a);

   if(a<0)
   {
 printf("Sum is : %d",sum);
 return;
   }
   else
   {
 sum = sum + a;
   }
   main();

}

A program to accept nos from user till their sum exceeds 50


/* Write a program to accept nos from user till their sum exceeds 50
   Developed by : Malhar Vora
   Developed on : 15-11-2010
   Development Status : Completed and tested
   Email : vbmade2000@gmail.com
   WebSite : www.malhar2010.blogspot.com
********************************************************************************************/

void main()
{

    int a=0,sum=0;

    test:
   if(sum>=50)
   {
  printf("Sum exceeds 50");
  return;
   }
   printf("Enter no:");
   scanf("%d",&a);

   sum=sum + a;
   goto test;

}

A program to get a no from user and find the sum of its odd digits

/* Write a program to get a no from user  and find the sum of its odd digits
   Developed by : Malhar Vora
   Developed on : 15-11-2010
   Development Status : Completed and tested
   Email : vbmade2000@gmail.com
   WebSite : www.malhar2010.blogspot.com
**********************************************************************************/   
void main()
{

 int a=0,temp=0,sum=0;
 printf("Enter no :");
 scanf("%d",&a);
 if(a==0)
 {
     printf("No can't be 0");
     return;
 }

 //Label test
 test:
  if(a==0)
  {
       printf("Sum is :%d",sum);
       return;
  }

  temp=a%10;
  if(temp%2!=0)
  {
       sum=sum+temp;
  }
  a=a/10;
  goto test;

}

Sunday, November 14, 2010

A Program to enter a 4 digit integer from user and display it in characters without using loop and functions ( e.g 1654 = One Six Five Four )

/*Program to get 4 digit integer rom user and display each digit in character ( e.g 1545 should be displayed as One Five Four Five )
  Developed by : Malhar Vora
  Development Status : Completed and Tested
  Developed on : 14/11/2010
  Email : vbmade2000@gmail.com
  Web Site : www.malhar2010.blogspot.com
***********************************************************************************/  
void main()
{

 int a=0,temp=0,divisor=1000,temp1=0;

 printf("Enter no:");
 scanf("%d",&a);

 test:
  if(divisor==0)
  {
      return;
  }

  temp=a/divisor;
  divisor=divisor/10;
  temp1=temp%10;

  switch(temp1)
  {
   case 1:
    printf("One");
    break;
   case 2:
    printf("Two");
    break;
   case 3:
    printf("Three");
    break;
   case 4:
    printf("Four");
    break;
   case 5:
    printf("Five");
    break;
   case 6:
    printf("Six");
    break;
   case 7:
    printf("Seven");
    break;
   case 8:
    printf("Eight");
    break;
   case 9:
    printf("Nine");
   case 0:
    printf("Zero");
    break;
  }
  goto test;

}

Saturday, August 21, 2010

Program to print 1 to 10 using while loop ( GTU Sem I Program No : 8)

/*Program to print 1 to 10 using while loop 
  Program No         :- 8 of GTU Practice Programs SEM I 
  Developed by       :- Malhar Vora 
  Developed on       :- 21/07/2010 
  Email              :- vbmade2000@gmail.com 
  Web Site           :- http://malhar2010.blogspot.com 
  Development Status :- Completed
**************************************************/  
void main()
{
     int n=1;

     while(n<=10){
 printf("%d\n",n);//Prints n
 n++; //Incrementing n
     }
}

Execute function after completion of main() function in C using #pragma directive

/*This Program demonstrates the use of #pragma directive.#pragma exit can be used to call a function after main.The function must not returning anything other than void and must not contain any arguments.
  Syntax : #pragma exit function-name [priority]
  Here function-name is the name of a function and priority is optional.
  priority can be from 64 to 255.Do not use priority from 0 to 63 because they are used by C libraries.
  100 is a Default priority
  255 is a lowest priority
  Developed on       :- 28/03/2009
  Developed by       :- Malhar Vora
  Email              :- vbmade2000@gmail.com         
  WebSite            :- http://malhar2010.blogspot.com
  Development Status :- Completed
  
*************************************************************/


 #include 

void PrintChar1()
{
   printf("Hello after main1\n");
   getch();
}



#pragma exit PrintChar1


void main()
{

   printf("Hello from Main");

}

Execute function before execution of main() function in C using #pragma directive

/*This Program demonstrates the use of #pragma directive.
  #pragma startup can be used to call a function before main.The function
  must not returning anything other than void and must not contain any
  arguments.
  
  Syntax : #pragma startup function-name [priority]
  Here function-name is the name of a function and priority is optional.
  priority can be from 64 to 255.Do not use priority from 0 to 63 because
  they are used by C libraries.
  100 is a Default priority
  255 is a lowest priority
  Developed on       :- 28/03/2009
  Developed by       :- Malhar Vora 
  Email              :- vbmade2000@gmail.com         
  WebSite            :- http://malhar2010.blogspot.com
  Development Status :- Completed
  
******************************************************************/


 #include 

void PrintChar1()
{
   printf("Hello before main1\n");
}

void PrintChar2()
{

   printf("Hello before main2\n");
}


#pragma startup PrintChar1 64
#pragma startup PrintChar2 65

void main()
{

   printf("Hello from Main");

}

Sunday, August 8, 2010

C Program to print square of first and last nos of inputted no

/*Program to print square of first and last no of inputted no
  Created by : Malhar Vora
  Created on : 8-8-2010
  Email          : vbmade2000@gmail.com
  WebSite    :  http://malhar2010.blogspot.com
******************************************************************************************************/
#include

void main()
{
      int i=358,a=0,first=0,last=0,flgfirst=0;

    while(i>0)
   {

       a = i%10;

       if(flgfirst==0)
       {
              last=a;
              flgfirst=1;
       }

       first=a;

       i=i/10;
   }

   printf("Square of First no : %d",(first*first));
   printf("\nSquare of Second no : %d",(last*last));

} 

Saturday, July 24, 2010

Program to get data from user and store in STUDENT file, again read it from STUDENT file and write to DATA file and display same on screen ( GTU Sem I Program No : 41)

/*Program to get student data from user,
  write it to STUDENT file , read it again in
  store in DATA file and display same on screen
  Program No   : 41 of GTU Practice Programs SEM I
  Developed by : Malhar Vora
  Developed on : 21/07/2010
  Email        : vbmade2000@gmail.com
  Web Site     : http://malhar2010.blogspot.com
**************************************************/


struct studata
{
   int rollno;
   char name[20];
};

typedef struct studata student;
student s;

//Get Student data from user
void readData()
{
    short temp;
    printf("Enter Roll No of Student :");
    scanf("%d",&temp);
    s.rollno=temp;

    fflush(stdin);
    printf("\nEnter Name of Student :");
    gets(s.name);

}

//Write inputted data to STUDENT file
void writeStudentFile()
{
   FILE *stufile;
   stufile=fopen("STUDENT","wt");
   if(stufile==NULL)
   {
      printf("\nError in writing STUDENT file");
      return;
   }
   fwrite(&s,sizeof(s),1,stufile);
   fclose(stufile);
}

//Clear structure s to hold new data
void clearData()
{
   s.rollno=0;
   strcpy(s.name,"");
}

//Read data from STUDENT file
void readStudentFile()
{
   FILE *stufile;
   stufile=fopen("STUDENT","rt");
   if(stufile==NULL)
   {
      printf("\nError in reading STUDENT file");
      return;
   }
   fread(&s,sizeof(s),1,stufile);
   fclose(stufile);
}

//Write data to DATA file
void writeDataFile()
{
   FILE *datafile;
   datafile=fopen("STUDENT","wt");
   if(datafile==NULL)
   {
      printf("\nError in writing DATA file");
      return;
   }

   fwrite(&s,sizeof(s),1,datafile);
   fclose(datafile);
}

//Display data fetched from STUDENT file
void displayData()
{
   printf("\nData from STUDENT file");
   printf("\nRoll No : %d",s.rollno);
   printf("\nName    : %s",s.name);
}

void main()
{
  clrscr();
  readData();
  writeStudentFile();
  clearData();
  readStudentFile();
  writeDataFile();
  displayData();
}


Thursday, July 22, 2010

Program to create linear linked list and print contents and total items( GTU Sem I Program No : 42)

/*Program to create a linear linked list interactively and print its
  content and total no of items in list
  Program No   : 42 of GTU Practice Programs SEM I
  Developed by : Malhar Vora
  Developed on : 20/07/2010
  Email        : vbmade2000@gmail.com
  Web Site     : http://malhar2010.blogspot.com
****************************************************************************/


#include

#define LIMIT 5

//structure to hold data and link to next node
struct node
{
   int data;
   struct node *next;
};


short count=0; //Gloab lcounter to count no of items in list
typedef struct node *listnode;

listnode root=NULL;

void insert(int newdata)
{
    listnode newnode,temp;
    newnode=(listnode)malloc(sizeof(listnode));
    newnode->data=newdata;
    temp=root;
    while(temp->next!=NULL)
    {
       temp=temp->next;
    }
    temp->next=newnode;
    newnode->next=NULL;
    count++;
}

void print()
{
   listnode temp;
   temp=root;
   printf("\nPrinting items");
   while(temp->next!=NULL)
   {
       temp = temp->next;
       printf("\n%d",temp->data);
   }
}

void printcount()
{
   printf("\nTotal %d items are stored in linked list",count);
}

void main()
{
   clrscr();
   insert(1);
   insert(2);
   insert(3);
   insert(4);

   print();

   printcount();

}

Program to find maximum element from 1D array ( GTU Sem I Program No : 19)

/*Program to find maximum element from 1D array
  Program No   : 19 of GTU Practice Programs SEM I
  Developed by : Malhar Vora
  Developed on : 20/07/2010
  Email        : vbmade2000@gmail.com
  Web Site     : http://malhar2010.blogspot.com
****************************************************************************/


#include

#define LIMIT 5

int getMax(int *arr,int n)
{
   int i,max;
   max=arr[i];
   for(i=0;i
   {
      if(arr[i]>max)
     max=arr[i];
   }
   return max;
}

void main()
{
   int arr[LIMIT],i,max=0;
   clrscr();

   printf("Enter elements in array :");
   for(i=0;i
   {
      scanf("%d",&arr[i]);
   }


   printf("Max is : %d",getMax(arr,LIMIT));

}

Function to check that no is prime or not ( GTU Sem I Program No : 30)

/*Write a fucntion prime which returns 1 is argument is prime no otherwise 0
  Program No   : 30 of GTU Practice Programs
  Developed by : Malhar Vora
  Developed on : 20/07/2010
  Email        : vbmade2000@gmail.com
  Web Site     : http://malhar2010.blogspot.com
****************************************************************************/


#include


short prime(int no)
{
    if(no % 2==0)
       return 0;
    else
       return 1;
}


void main()
{
   int no;
   printf("Enter a no :");
   scanf("%d",&no);
   if(prime(no)==1)
   {
      printf("\nNo is prime");
   }
   else
   {
      printf("\nNo is not prime");
   }

} 


Program to count length of given string ( GTU Sem I Program No : 23)

/*Program to find length of inputted string
  Program No   : 23 of GTU Practice Programs
  Developed by : Malhar Vora
  Developed on : 20/07/2010
  Email        : vbmade2000@gmail.com
  Web Site     : http://malhar2010.blogspot.com
****************************************************************************/


#include 

int strlen(char *str)
{
    int count=0;
    while(str[count]!=0)
      count++;
    return count;
}

void main()
{
   char *str;
   printf("Enter a string :");
   gets(str);
   printf("\nLength of string is : %d",strlen(str));
}