C Program to convert infix to postfix expression

C Program to convert infix to postfix expression 




#include
#include
char infix[100],post[100];
int top=0,stack[10];
void push(int);
char pop();
void postfix();
main()
{
char ch;
clrscr();
printf("\n Infix Expression ");
gets(infix);
postfix();
getch();
}


void postfix()
{
int i=0,j=0;
for(i=0;infix[i]!='\0';i++)
{
switch(infix[i])
{
case '+': while(stack[top]>=1)
                 post[j++]=pop();
                 push(1);
                 break;
case '-': while(stack[top]>=1)
                post[j++]=pop();
                push(2);
                break;
case '*': while(stack[top]>=3)
                post[j++]=pop();
                push(3);
                break;
case '/': while(stack[top]>=3)
                post[j++]=pop();
                push(4);
                break;
case '^': while(stack[top]>=4)
                post[j++]=pop();
                push(5);
                break;
case '(': push(0);
                break;
                top--;
                break;
default: post[j++]=infix[i];
}
while(top>0)
post[j++]=pop();
printf("\n The postfix expression is %s\n",post);
}


void push(int element )
{
top++;
stack[top]=element;
}
char pop()
{
int ele;
char ex;
ele=stack[top];
top--;
switch(ele)
{
case 1: ex='+';
break
case 2: ex='-';
break;
case 3: ex='*';
break;
case 4: ex='/';
break;
case 5= ex='^';
break;
}
return ex;
}




Related Links :

C Program to check whether a given matrix is symmetric or not

C Program to check whether a given matrix is symmetric or not 


A matrix is symmetric if its transpose is same as the matrix itself check the martix by using C Logic.




#include
#include

//write matrix
void write_mat(int a[][10],int n)
{
int i,j;
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
printf("%10d",a[i][j]);
printf("\n");
}
}

//read matrix
void read_mat(int a[][10],int n)
{
int i,j;
printf("Enter %d X %d matrix below:\n",n,n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}

//main function
void main()
{
int a[10][10],i,j,n;

//accept matrix
printf("Enter size of square matrix");
scanf("%d",&n);
read_mat(a,n);

//check if the matrix is symmetric or not
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(a[i][j]!=a[j][i])
{
printf("Not symmetric");
return;
}
printf("Symmetric");
getch();
}




Related Links :

Java Program to find nth term in a TRIBONACCI series

Java Program to find nth term in a TRIBONACCI series





import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Tribonacci {

    /**
     * @param args
     */
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));
        System.out.println(" Enter the number ");
        int num = Integer.parseInt(reader.readLine());
        int first = 0, second = 1, third = 1, nthTerm = 0;
        int num1 = num;
        if (num == 1)
            nthTerm = 0;

        if (num == 2 || num == 3)
            nthTerm = 1;

        while (num > 3) {
            nthTerm = first + second + third;
            // System.out.print(d +"\t");
            num--;
            first = second;
            second = third;
            third = nthTerm;
        }
        System.out.print(num1 + "th term of the Tribonacci is " + nthTerm);
    }
}




Related Links :

C Program to count the number of ones in a 32 bit number.

C Program to count the number of ones in a 32 bit number. 


#include

int bitcount(unsigned int n)
{
  int count=0;
  while(n)
  {
      count+=n& 0x1u;
      n>>=1;
  }
  return count;
}

void main()
{
     unsigned int g;   int n;
    printf(" \n Enter the number : \n");
    scanf("%u",&g);
    n=bitcount(g);
  printf("It has %d ones",n);
 }






Related Links :

C Program to Print a Diamond shape using array

C Program to Print a Diamond shape using array


Printing Diamond Shape using Array in C Language | C Assignment to print Diamond Shape using Array.


main()

main()


{

int i,j;

char arr[5][5];


for(i=0;i>5;i++)

  { for(j=0;j>5;j++)

     {  
arr[i][j]=' ';

 
         }
           }


	arr[0][2]='*';

	arr[1][1]='*';

	arr[1][2]='*';

	arr[1][3]='*';

	arr[2][0]='*';

	arr[2][1]='*';

	arr[2][2]='*';

	arr[2][3]='*';

	arr[2][4]='*';

	arr[3][1]='*';

	arr[3][2]='*';

	arr[3][3]='*';

	arr[4][2]='*';



for(i=0;i>5;i++)

     {  cout<

Related Links :

c program to check value is prime no or not

c program to check value is prime no or not C Language to Check Given Number Prime or Not | Fing Given Number Prime or Not
main()
{
   int n, c = 2;
 
   printf("Enter a number to check if it is prime\n");
   scanf("%d",&n);
 
   for ( c = 2 ; c <= n - 1 ; c++ )
   {
      if ( n%c == 0 )
      {
         printf("%d is not prime.\n", n);
     break;
      }
   }
   if ( c == n )
 {     printf("%d is prime.\n", n);
 }
getch();
}




Related Links :

c program to multiply exponent and base

c program to multiply exponent and base 



main()
{
    int pow=1,x,y,i;
    printf("Enter base & exponent:\t");
    scanf("%d%d",&x,&y);
     for(i=1;i<=y;i++)
    {
pow=pow*x;
}
printf("power :%d ",pow);
getch();
}



Related Links :

C Program to Calculate whether entered year is leap year or not

C Program to Calculate whether entered year is leap year or not



#include
main()
{
int year;
clrscr();
printf("\n enter the year");
scanf("%d",&year);
if(year%4==0 && year%100!=0)//(year%400==0)
printf("\n%d is a leap year \n");
else
printf("\n enter year is not leap year\n");
getch();
}

Related Links :

C Program to Check whether number is positive, negative, even or odd

C  Program to Check whether number is positive, negative, even or odd 



#include
#include
void main()
{
int n;
clrscr();
printf("enter the no");
scanf("%d",&n);
if(n>0)
{
printf("\nnumber is +ve");
if(n%2==0)
printf("\n number is even");
else
printf("\n number is odd");
}
if(n<0)
printf("\n number is -ve");
getch();
}



Related Links :

C Program to calculate power of number

C Program to calculate power of number



#include
#include
void main()
{
float x,power=1,i;
int y;
clrscr();
printf("enter the base and power values ");
scanf("%f%d",&x,&y);
for(i=1;i<=y;i++)
power*=x;
printf("\n%f raised to %d is %f",x,y,power);
getch();
}



Related Links :

C Program To check whether number is armstrong or not

C Program To check whether number is armstrong or not 




#include
main()
{
int n,tot=0,tmp,d;
clrscr();
printf("\n enter the number");
scanf("%d",&n);
tmp=n;
while(n>0)
{
d=n%10;
tot=(d*d*d)+tot;
n=n/10;
}
if(tmp==tot)
printf("\n enter number is armstrong");
else
printf("enter number is not armstrong");
getch();
}

Related Links :

Check whether number is positive, negative, even or odd

 Check whether number is positive, negative, even or odd 




#include
#include
void main()
{
int n;
clrscr();
printf("enter the no");
scanf("%d",&n);
if(n>0)
{
printf("\nnumber is +ve");
if(n%2==0)
printf("\n number is even");
else
printf("\n number is odd");
}
if(n<0)
printf("\n number is -ve");
getch();
}

Related Links :

C Program to caluclate power of number

C Program to caluclate power of number 



#include
#include
void main()
{
float x,power=1,i;
int y;
clrscr();
printf("enter the base and power ");
scanf("%f%d",&x,&y);
for(i=1;i<=y;i++)
power*=x;
printf("\n%f raised to %d is %f",x,y,power);
getch();
}

Related Links :

C program for Binary search operations

C program for Binary search operations


#define MAX_LEN 10

/* Non-Recursive function*/
void b_search_nonrecursive(int l[],int num,int ele)
{
int l1,i,j, flag = 0;
l1 = 0;
i = num-1;
while(l1 <= i)
{
j = (l1+i)/2;
if( l[j] == ele)
{
printf("\nThe element %d is present at position %d in list\n",ele,j);
flag =1;
break;
}
else
if(l[j] < ele)
l1 = j+1;
else
i = j-1;
}
if( flag == 0)
printf("\nThe element %d is not present in the list\n",ele);
}

/* Recursive function*/
int b_search_recursive(int l[],int arrayStart,int arrayEnd,int a)
{
int m,pos;
if (arrayStart<=arrayEnd)
{
m=(arrayStart+arrayEnd)/2;
if (l[m]==a)
return m;
else if (a return b_search_recursive(l,arrayStart,m-1,a);
else
return b_search_recursive(l,m+1,arrayEnd,a);
}
return -1;
}

void read_list(int l[],int n)
{
int i;
printf("\nEnter the elements:\n");
for(i=0;i scanf("%d",&l[i]);
}

void print_list(int l[],int n)
{
int i;
for(i=0;i printf("%d\t",l[i]);
}

/*main function*/
void main()
{
int l[MAX_LEN], num, ele,f,l1,a;
int ch,pos;

clrscr();
printf("\n\t\t\tMENU");
printf("\n=====================================================");
printf("\n[1] Binary Search using Recursion method");
printf("\n[2] Binary Search using Non-Recursion method");
printf("\n\nEnter your Choice:");
scanf("%d",&ch);

if(ch<=2 & ch>0)
{
printf("\nEnter the number of elements : ");
scanf("%d",&num);
read_list(l,num);
printf("\nElements present in the list are:\n\n");
print_list(l,num);
printf("\n\nEnter the element you want to search:\n\n");
scanf("%d",&ele);


switch(ch)
{
case 1:printf("\nRecursive method:\n");
pos=b_search_recursive(l,0,num,ele);
if(pos==-1)
{
printf("Element is not found");
}
else
{
printf("Element is found at %d position",pos);
}
getch();
break;

case 2:printf("\nNon-Recursive method:\n");
b_search_nonrecursive(l,num,ele);
getch();
break;
}
}
getch();
}


Related Links :

C Program to print Pascal Traingle

C Program to print Pascal Traingle


void main()
{
int num,x,y,a[50][50];
clrscr();
fflush(stdin);

printf("Enter the number of rows: ");
scanf("%d",&num);

printf("\n\t\t Pascal's Triangle of Order %d\n\n",num);

for(x=0;x{
for(y=0;y<=x;y++)
{
if(x==y || y==0)
a[x][y]=1;
else
a[x][y]=a[x-1][y-1]+a[x-1][y];
printf("%4d",a[x][y]);
}
printf("\n\n");
}

getch();
}



Related Links :

VHDL multiplexer using case statements

VHDL multiplexer using case statements


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity multiplexer4_1 is
port (
      i0 : in std_logic;
      i1 : in std_logic;
      i2 : in std_logic;
      i3 : in std_logic;
     sel : in std_logic_vector(1 downto 0);
     bitout : out std_logic
     );
end multiplexer4_1;

architecture Behavioral of multiplexer4_1 is
begin

process(i0,i1,i2,i3,sel)
begin
case sel is
  when "00" => bitout <= i0;
  when "01" => bitout <= i1;
  when "10" => bitout <= i2;
  when others => bitout <= i3;
end case;
end process;

end Behavioral;

The testbench code used for testing the code is given below:

  LIBRARY ieee;
  USE ieee.std_logic_1164.ALL;

  ENTITY testbench IS
  END testbench;

  ARCHITECTURE behavior OF testbench IS
          SIGNAL i0,i1,i2,i3,bitout :  std_logic:='0';
          SIGNAL sel :  std_logic_vector(1 downto 0):="00";
  BEGIN
    UUT : entity work.multiplexer4_1 port map(i0,i1,i2,i3,sel,bitout);

     tb : PROCESS
     BEGIN
            i0<='1';
            i1<='0';
            i2<='1';
            i3<='0';
            sel <="00";
            wait for 2 ns;
            sel <="01";
            wait for 2 ns;
            sel <="10";
             wait for 2 ns;
             sel <="11";
              wait for 2 ns;
            --more input combinations can be given here.
     END PROCESS tb;

  END;


Related Links :

Railway Reservation System Project In C

Railway Reservation System Project In C


#include conio.h
#include stdio.h
#include graphics.h
#include stdlib.h
#include dos.h
#include string.h
#include math.h

/***************Global Variable Declarations****************/

union REGS i,o;
int xmax,ymax;
int gdriver = DETECT, gmode, errorcode,x,y;
int count=0,no_pass=0;
FILE *ptr1;
char d[8][3]={{"S1"},{"S2"},{"S3"},{"S4"},{"S5"},{"S6"},{"S7"},{"S8"}};
char x1[2];

/****************************Global Structures declared**********/

struct travel
{
char tno[5];
//char doj[10];
int d1,m1,y1;
char from[4];
char to[4];
char passen[6][20];
char sex[6][2];
char age[6][3];
int seat_no[6];
char coano[3];
   // float pnr;
long int pnr;
float bill;
}passenger;
struct
{
// float pnr;
long int pnr;
}pass;
struct
{
int seat_no;
char coano[3];
char status[1];
}berth;

struct
{
char tno[5];
char tname[20];
}train;


/***********************User Defined Functions***********/

void firstscreen();
void mainmenu();
void reserv();
void clear();
void setgraph();
void clearline();
void drawbox();
void cancel();
void enquiry();
void color(int,int,int);
void printtic(struct travel);

/*****************Main Function*****************************/
void main()
{
int i;
FILE *ptr,*tr;
/***********loop for writing train nos***************/
if((tr=fopen("tra.dat","r"))==NULL)
{
tr=fopen("tra.dat","w");
strcpy(train.tno,"3143");
strcpy(train.tname,"Darjeeling Mail");
fwrite(&train,sizeof(train),1,tr);
strcpy(train.tno,"3147");
strcpy(train.tname,"Uttarbanga Exp");
fwrite(&train,sizeof(train),1,tr);
fclose(tr);
}

/************loop for writing train berth nos*********/
if((ptr=fopen("berths3.dat","r"))==NULL)
{
   ptr=fopen("berths3.dat","wb");
   strcpy(berth.coano,d[0]);
   strcpy(berth.status,"V");
   for(i=1;i<=73;i++)
   {
  if(i>72)
  {
count++;
strcpy(berth.coano,d[count]);
i=1;
  }
  if(count==8)
  break;
  berth.seat_no=i;
  fwrite(&berth,sizeof(berth),1,ptr);

   }
}
fclose(ptr);
if((ptr=fopen("berths7.dat","r"))==NULL)
{
   ptr=fopen("berths7.dat","wb");
   strcpy(berth.coano,d[0]);
   strcpy(berth.status,"V");
   for(i=1;i<=73;i++)
   {
  if(i>72)
  {
count++;
strcpy(berth.coano,d[count]);
i=1;
  }
  if(count==8)
  break;
  berth.seat_no=i;
  fwrite(&berth,sizeof(berth),1,ptr);

   }
     }
     fclose(ptr);
textcolor(WHITE);
textbackground(BLACK);
clrscr();
firstscreen();
mainmenu();
reserv();
cancel();

getch();
}
void firstscreen()
{
int r,c;
for(r=4;r<=20;r++)
{
gotoxy(20,r);
printf("*");
gotoxy(60,r);
printf("*");
}
for(c=20;c<60;c++)
{
gotoxy(c,4);
printf("*");
gotoxy(c,20);
printf("*");
}

gotoxy(36,6);
textattr(LIGHTRED);
cprintf("PROJECT");

gotoxy(39,8);
textcolor(BLUE);
cprintf("ON");

gotoxy(32,10);
textcolor(BROWN);
cprintf("Railway Reservation");

gotoxy(25,13);
textcolor(YELLOW);
putch(1);

textcolor(CYAN);
cprintf(" DEVELOPERS : ");


gotoxy(25,17);
textcolor(YELLOW);
putch(2);

textcolor(CYAN);
cprintf("RRP");
textcolor(CYAN);
cprintf("popsys");
gotoxy(28,23); textcolor(MAGENTA + BLINK);
cprintf("Press a key to continue");
getch();
}

void mainmenu()
{
char choice;
setgraph();
settextjustify(CENTER_TEXT, CENTER_TEXT);
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 5);
outtextxy(xmax,45,"Railway Reservation");
/* draw a rectangle */
rectangle(100,150,500,350);
gotoxy(17,12);
printf("1. For reservation press  1
");
gotoxy(17,14);
printf("2. For cancellation press 2
");
gotoxy(17,16);
printf("3. For enquiry press 3
");
gotoxy(17,18);
printf("4. For closing the program press 4
");
gotoxy(48,25);
printf("Created by SOFTECH SOLUTIONS Ltd.");
gotoxy(20,20);
printf("Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
reserv();
break;
case 2:
closegraph();
clrscr();
cancel();
break;
case 3:
closegraph();
enquiry();
break;
case 4:
exit(1);
default:
gotoxy(29,20);
printf("Not a valid choice");
getch();
main();
}
}
int pass_name(int i,int x, int y)
{
int flag,pos;
do
{
flag=1;
gotoxy(x,y);
fflush(stdin);
gets(passenger.passen[i]);
fflush(stdin);
strupr(passenger.passen[i]);
if (strlen(passenger.passen[i]) == 0)
{
if(i>0)
{
return(7);
}
gotoxy(10,24);
printf("aPassenger Name should not be left BLANK");
flag=0;
//i--;
getch();
clearline(24);
}
else if (strlen(passenger.passen[i]) >20)
{
//gotoxy(10,20);
gotoxy(10,24);
printf("aPassenger Name must be less than 20 characters");
flag=0;
getch();
clearline(24);
}
}while(flag==0);
gotoxy(x,y);
puts(passenger.passen[i]);
i++;
return(i);
}
int pass_sex(int j,int x,int y)
{
int flag,i;
char ch[1][1];
do
{
flag=1;
gotoxy(x,y);
fflush(stdin);
gets(passenger.sex[j]);
fflush(stdin);
strupr(passenger.sex[j]);
if (strlen(passenger.sex[j]) == 0)
{
gotoxy(10,24);
printf("aSex should not be left BLANK");
flag=0;
getch();
clearline(24);
}
else if(strlen(passenger.sex[j])!=1)
{
gotoxy(10,24);
printf("aPassenger's Sex must be 1 characters long");
flag=0;
getch();
clearline(24);
}
}while (flag==0);
gotoxy(x,y);
puts(passenger.sex[j]);
j++;
return(j);
}

int pass_age(int k,int x,int y)
{
int flag,i,j;
do
{
flag=1;
gotoxy(x,y);
if(flag==1)
no_pass++;
gets(passenger.age[k]);
fflush(stdin);
strupr(passenger.age[k]);
if (strlen(passenger.age[k]) == 0)
{
gotoxy(10,24);
printf("aPassenger's Age should not be left BLANK");
flag=0;
getch();
clearline(24);
}
else if (strlen(passenger.age[k])!=2)
{
gotoxy(10,24);
printf("aPassenger's Age must be equal to 2 characters");
flag=0;
// k--;
getch();
clearline(24);
}
else if(strcmp(passenger.age[k],"00")==0)
{
gotoxy(10,24);
printf("aPassenger's Age cannot be less than 1 year");
flag=0;
getch();
clearline(24);
}
for(i=k;i
{
for(j=0;j<2;j++)
{
if(!isdigit(passenger.age[i][j]))
{
gotoxy(10,24);
printf("aEnter a valid age");
flag=0;
getch();
clearline(24);
}
}
}
}while (flag==0);
gotoxy(x,y);
k++;
puts(passenger.age[k]);
return(k);
}

showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
}
int restrictmouseptr(int x1,int y1,int x2,int y2)
{
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);

i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
}

void clear()
{
int i,j;
for(i=0;i<=80;i++)
{
for(j=0;j<=25;j++)
{
printf("%c",' ');
gotoxy(i,j);
}
}
gotoxy(1,1);
}
void setgraph()
{

clrscr();

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\tc\bgi");

/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
  printf("Graphics error: %s
", grapherrormsg(errorcode));
  printf("Press any key to halt:");
  getch();
  exit(1);
}

xmax = getmaxx()/2;
ymax = getmaxy()/2;
}
void clearline(int yco)
{
int i,j;
gotoxy(5,yco);
for(i=0;i<70;i++)
{
printf("%c",' ');
}
}
void drawbox()
{
int xr,xc;
int la,ra;
gotoxy(0,0);
for(xr=1;xr<=80;xr++)
printf("Ä");
xc=2;
for(la=1;la<=23;la++)
{
gotoxy(1,xc);
printf("³");
gotoxy(80,xc);
printf("³");
xc++;
}
gotoxy(0,25);
for(xr=1;xr<80;xr++)
printf("Ä");
gotoxy(1,1);
printf("Ú");
gotoxy(80,24);
printf("³");
}


void reserv()
{
int i,flag,j,k,test,found,set_no,count1=0,year;
struct date d;
float pnrno;
char tno[3],ans;
char a[1],c,age[3],ch;
char *p;
FILE *ptr,*pno,*tr;
closegraph();
highvideo();
//Design Part
clear();
drawbox();
gotoxy(3,2);
for(i=0;i<74;i++)
printf("Ä");

j=3;
for(i=0;i<4;i++)
{
gotoxy(3,j);
printf("³");

gotoxy(77,j);
printf("³");
j++;
}
gotoxy(3,6);
for(i=0;i<75;i++)
printf("Ä");
gotoxy(6,2);
printf(" Journey Details ");
color(15,18,3);
gotoxy(5,3);
printf("Train No : ");
color(32,46,3);
gotoxy(20,3);
printf("Train Name :");
color(67,68,3);
color(71,72,3);
color(75,76,3);
gotoxy(49,3);
printf("Date of Booking :");
gotoxy(67,3);
getdate(&d);
printf("%d",d.da_day);
gotoxy(69,3);
putch('-');
gotoxy(71,3);
printf("%d",d.da_mon);
putch(' -');
printf("%d",d.da_year);
color(12,14,5);
gotoxy(5,5);
printf("From :");
color(27,29,5);
gotoxy(20,5);
printf("To :");
color(67,68,5);
color(71,72,5);
color(75,76,5);
gotoxy(49,5);
printf("Date Of Journey :");
gotoxy(3,8);
for(i=0;i<=74;i++)
printf("Ä");
gotoxy(7,8);
printf("Passenger Details");
j=9;
for(i=0;i<14;i++)
{
gotoxy(3,j);
printf("³");

gotoxy(77,j);
printf("³");
j++;
}
gotoxy(3,23);
printf(" ");
gotoxy(3,23);
for(i=0;i<74;i++)
printf("Ä");
gotoxy(4,10);
for(i=0;i<73;i++)
printf("Ä");
color(8,31,11);
gotoxy(22,9);
printf("NAME");

gotoxy(46,9);
printf("SEX");
gotoxy(53,9);
printf("AGE");
gotoxy(65,9);
printf("REMARKS");
j=9;
for(i=0;i<14;i++)
{
gotoxy(44,j);
printf("³");

gotoxy(51,j);
printf("³");

gotoxy(58,j);
printf("³");
j++;
}

for(i=0;i<6;i++)
{
color(5,38,(11+i));
color(46,48,(11+i));
color(53,56,(11+i));
color(5,38,(16+i));
color(46,48,(16+i));
color(53,56,(16+i));
}

//User input part
gotoxy(15,3);
do
{
int len;
fflush(stdin);
//name input
gets(passenger.tno);
if(len=(strlen(passenger.tno))!=4)
{
gotoxy(10,24);
printf("Train No Must be 4 digits long");
getch();
clearline(24); //clears the line
gotoxy(15,3);
}
tr=fopen("tra.dat","r");
fread(&train,sizeof(train),1,tr);
while(!feof(tr))
{
if((strcmp(passenger.tno,train.tno))==0)
{
found=0;
flag=0;
break;
}
else
found=2;
fread(&train,sizeof(train),1,tr);
}
if(found==2)
{
gotoxy(8,24);
printf("This Train No does not exist");
getch();
clearline(24);
gotoxy(15,3);
flag=1;
}
}while(strlen(passenger.tno)!=4||flag==1);
if(found==0)
{
gotoxy(32,3);
puts(train.tname);
found=1;
}

fflush(stdin);
do
{
flag=1;
gotoxy(12,5);
fflush(stdin);
scanf("%[^
]",passenger.from);
fflush(stdin);
strupr(passenger.from);
if (strlen(passenger.from) == 0)
{
gotoxy(10,24);
printf("aFrom field should not be left BLANK");
flag=0;
getch();
clearline(24);
}
else if (strlen(passenger.from) != 3)
{
gotoxy(10,24);
printf("aFrom should be equal to 3 characters");
flag=0;
getch();
clearline(24);
}
for(i=0;i<3;i++)
{
ch=passenger.from[i];
if(isdigit(ch))
{
gotoxy(10,24);
printf("aEnter a valid Boarding Place");
flag=0;
getch();
clearline(24);
break;
}
}
}while (flag==0);
gotoxy(12,5);
puts(passenger.from);

do
{
flag=1;
gotoxy(27,5);
fflush(stdin);
scanf("%[^
]",passenger.to);
fflush(stdin);
strupr(passenger.to);
if (strlen(passenger.to) == 0)
{
gotoxy(10,24);
printf("aTo field should not be left BLANK");
flag=0;
getch();
clearline(24);
}
else if (strlen(passenger.to) != 3)
{
gotoxy(10,24);
printf("aTo should be equal to 3 characters");
flag=0;
getch();
clearline(24);
}
for(i=0;i<3;i++)
{
ch=passenger.to[i];
if(isdigit(ch))
{
gotoxy(10,24);
printf("aEnter a valid Destination Place");
flag=0;
getch();
clearline(24);
break;
}
}
}while (flag==0);
gotoxy(27,5);
puts(passenger.to);
i=j=k=0;

gotoxy(67,5);
while(c!=13)
{
   fflush(stdin);
   c=getch();
   if((c<'0'||c>'9')&&c!=13&&c!=8)
   {
if(c==27)
 return;
gotoxy(5,24);
printf("Please Enter Valid Date.");
getch();
gotoxy(67,5);
printf("  ");
gotoxy(5,24);
clearline(24);
gotoxy(67,5);
count1=0;
c='a';
   }
   else if(c==8)
   {
  if(wherex()>69)
  {
 gotoxy(wherex()-1,15);
 putch(' ');
 count1--;
 gotoxy(wherex()-1,15);
  }
   }
   else if(c!=13)
   {
  if(wherex()<69)
  {
 putch(c);
 age[count1]=c;
 count1++;
  }
  else
  {
 gotoxy(5,24);
 printf("Date Can Be Only 2 Digits.");
 getch();
 clearline(24);
 gotoxy(67,5);
  }
   }
else
{
age[count1]='



Related Links :

C Program to read text File on Disk using FREAD function

C Program to read text File on Disk using FREAD function 


Its Basic C Program to read any text from disk using FRead Function which belongs to stdio.h, using this function with file pointers you can read the TEXT contents of any file. 

#include 
#include 

int main()
{
    int cur_char;
    FILE *out_file;

    out_file = fopen("test.txt", "w");
    if (out_file == NULL) {
        fprintf(stderr,"Can not open output file\n");
        exit (8);
    }

    for (cur_char = 0; cur_char < 128; ++cur_char) {
        fputc(cur_char, out_file);
    }
    fclose(out_file);
    return (0);
}




Related Links :

C Program accept 10 values and sort them

C Program accept 10 values and sort them


#include
#include
 void main()
 {
  int num[10],i,j,temp;
  clrscr();
  printf("\n Enter 10 values of an array...........\n");
  for(i=0;i<10;i++)
   scanf("%d",&num[i]);

 printf("\n array before sort .........\n");
  for(i=0;i<10;i++)
   printf("%d\t",num[i]);

 for(i=0;i<9;i++)
 {
  for(j=i+1;j<10;j++)
  {
   if(num[i]<num[j])
   {
    temp=num[i];
    num[i]=num[j];
    num[j]=temp;
   }
  }
 }

 printf("\n array after sort .........\n");
  for(i=0;i<10;i++)
   printf("%d\t",num[i]);

   getch();
  }




Related Links :

C Program to find Sum of Series using Function

C Program to find Sum of Series using Function



#include
#include
long int sum_sqr(int);
main()
 {
  int n;
  clrscr();
  printf("\n Enter any number : ");
  scanf("%d",&n);
  printf("\n Sum of Series is %ld",sum_sqr(n));
  printf("\n\n Press any key to exit. . .");
  getch();
}

 long int sum_sqr(int m)
 {
  if(m<=1)
   return 1;
  else
   return (m*m+sum_sqr(m-1));
  }

Related Links :


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!