#include "stdio.h"# include "conio.h"#define NULL 0FILE *fpt;void main(){ int c1=0,c2=0,c3=0,c4=0,c5=0; char c,name[20],z; clrscr(); printf("Enter the name of file to be checked :- "); gets(name); fpt=fopen(name,"r"); if (fpt==NULL) printf("ERROR - can/'t open file %s",name); else { while ((c=getc(fpt))!=EOF) { if (c=='(') c1=c1+1; if (c==')') c1=c1-1; if (c=='[') c2=c2+1; if (c==']') c2=c2-1; if (c=='') { if (c1!=0) printf("ERROR - Unbalanced parenthesis ()"); if (c2!=0) printf("ERROR - Unbalanced brackets []"); } if (c=='{') c3=c3+1; if (c=='}') c3=c3-1; if ((int)c==39) { if (c1!=0) { if (c4==0) c4=c4+1; else c4=c4-1; } else printf("ERROR - Unbalanced ' "); } if ((int)c==34) { if (c1!=0) { if (c5==0) c5=c5+1; else c5=c5-1; } else { z=(char)34; printf("ERROR - Unbalanced %c ",z); } } } } if (c1!=0) printf("ERROR - Unbalanced parenthesis ()"); if (c2!=0) printf("ERROR - Unbalanced brackets []"); if (c3!=0) printf("ERROR - Unbalanced braces {}"); if (c4!=0) printf("ERROR - Unbalanced ' "); if (c5!=0) printf("ERROR - Unbalanced " "); if (c1==0 && c2==0 && c3==0 && c4==0 && c5==0) printf("Program is up to date. WELL DONE!"); fclose(fpt); getch();}
Related Links :
Program to Delete Duplicates values in Array
#include "stdio.h"
#include"conio.h"
#include"string.h"
#include"dos.h"
void main()
{
int i,j,l,t=1;
char y,s[15];
clrscr();
s[0]='E';
s[1]='n';
s[2]='t';
s[3]='e';
s[4]='r';
s[5]=' ';
s[6]='a';
s[7]=' ';
s[8]='s';
s[9]='t';
s[10]='r';
s[11]='i';
s[12]='n';
s[13]='g';
s[14]=NULL;
printf("Enter a string
");
gotoxy(1,2);
while((y=getchar())!='')
{
for(i=3,l=200;i<=24;i++,l=l+50)
{
gotoxy(t,i);
if(y!=' ')
{
printf("%c",y);
gotoxy(t,i-1);
printf(" ");
sound(l);
delay(80);
}
} t++;
} gotoxy(1,1);
t=1;
for(j=0,l=100;j<14;j++,l=l+50)
{ if(l>200)
l=100;
for(i=2;i<24;i++,l++)
{
gotoxy(t,i);
if(s[j]!=' ')
{
printf("%c",s[j]);
gotoxy(t,i-1);
printf(" ");
sound(l);
delay(80);
}
}
t++;
}
nosound();
getch();
}
Related Links :
#include "stdio.h"
#include "stdlib.h"
int lev=-1,n,val[50],a[50];
void main()
{
int i,j;
clrscr();
printf("Enter howmany numbers ");
scanf("%d",&n);
for(i=0;i
{
val[i]=0;
j=i+1;
scanf("%d",&a[j]);
}
visit(0);
getch();
}
visit(int k)
{
int i;
val[k]=++lev;
if(lev==n)
{
for(i=0;i
printf("%2d",a[val[i]]);
printf(" ");
}
for(i=0;i
if(val[i]==0)
visit(i);
lev--;
val[k]=0;
}
Related Links :
#include "stdio.h"
#define inf 9999
int min(int a,int b);
main()
{
int i,j,n,k,a[20][20],p[20][20],t;
printf("ENTER THE NO. OF VERTICES ");
scanf("%d",&n);
printf("ENTER THE WEIGHTED ADJACENCY MATRIX");
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(a[i][j]==0)
p[i][j]=inf;
else
p[i][j]=a[i][j];
}
for(k=1;k<=n;k++)
{
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
t=p[i][k]+p[k][j];
p[i][j]=min(p[i][j],t);
}
}
printf("\nSHORTEST PATH IS\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(p[i][j]==inf)
printf("- ");
else
printf("%d ",p[i][j]);
}
printf("\n");
}
}
int min(int a,int b)
{
if(a
return(a);
else
return(b);
}
Related Links :
#include "stdio.h"int q[20],top=-1,front=-1,rear=-1,a[20][20],vis[20],stack[20];int delete();void add(int item);void bfs(int s,int n);void dfs(int s,int n);void push(int item);int pop();main(){ int n,i,s,ch,j; char c,dummy; printf("ENTER THE NUMBER VERTICES "); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { printf("ENTER 1 IF %d HAS A NODE WITH %d ELSE 0 ",i,j); scanf("%d",&a[i][j]); } } printf("THE ADJACENCY MATRIX IS\n"); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { printf(" %d",a[i][j]); } printf("\n"); } do { for(i=1;i<=n;i++) vis[i]=0; printf("\nMENU"); printf("\n1.B.F.S"); printf("\n2.D.F.S"); printf("\nENTER YOUR CHOICE"); scanf("%d",&ch); printf("ENTER THE SOURCE VERTEX :"); scanf("%d",&s); switch(ch) { case 1:bfs(s,n); break; case 2: dfs(s,n); break; } printf("DO U WANT TO CONTINUE(Y/N)? "); scanf("%c",&dummy); scanf("%c",&c); }while((c=='y')||(c=='Y'));}void bfs(int s,int n){ int p,i; add(s); vis[s]=1; p=delete(); if(p!=0) printf(" %d",p); while(p!=0) { for(i=1;i<=n;i++) if((a[p][i]!=0)&&(vis[i]==0)) { add(i); vis[i]=1; } p=delete(); if(p!=0) printf(" %d ",p); } for(i=1;i<=n;i++) if(vis[i]==0) bfs(i,n);}void add(int item){ if(rear==19) printf("QUEUE FULL"); else { if(rear==-1) { q[++rear]=item; front++; } else q[++rear]=item; }}int delete(){ int k; if((front>rear)||(front==-1)) return(0); else { k=q[front++]; return(k); }} void dfs(int s,int n){ int i,k; push(s); vis[s]=1; k=pop(); if(k!=0) printf(" %d ",k); while(k!=0) { for(i=1;i<=n;i++) if((a[k][i]!=0)&&(vis[i]==0)) { push(i); vis[i]=1; } k=pop(); if(k!=0) printf(" %d ",k); } for(i=1;i<=n;i++) if(vis[i]==0) dfs(i,n);}void push(int item){ if(top==19) printf("Stack overflow "); else stack[++top]=item;}int pop(){ int k; if(top==-1) return(0); else { k=stack[top--]; return(k); }}
Related Links :
#include "stdio.h"
void check(char);
void push(char);
struct node
{
char info;
struct node *r,*l;
}temp,*operator[10],*operand[10];
typedef struct node N;
int p,top1=0,top2=0;
main()
{
char exp[20];
printf("\nENter the expression :: ");
gets(exp);
for(i=0;exp[i]!='\0';i++)
{
check(exp[i]);
printf("\nThe priority value of %c is %d \n",exp[i],p);
push(exp[i]);
}
}
void check(char x)
{
p=-1;
switch(x)
{
case '*' :
p=1;
break;
case '/' :
p=1;
break;
case '+' :
p=2;
break;
case '-' :
p=2;
break;
default :
p=3;
break;
}
}
void push(char x)
{
temp=(N*)malloc(sizeof(N));
temp->info=x;
temp->l=NULL;
temp->r=NULL;
switch(p)
{
case 1 :
break;
case 2 :
break;
case 3 :
operand[top1++]=temp;
break;
}
}
Related Links :
#include#include#define SIZE 20int binary_to_decimal(int);int decimal_to_binary(int);void binary_to_hexa(int);int hexa_to_binary(char []);void binary_to_octal(int);void octal_to_binary(int);int main(){ int choice=0,number=0; char hexa[10]; do { printf("\n\n\tMenu\n\t
1.Binary to Decimal
\n\t2.Decimal to Binary
\n\t3.Binary to Hexadecimal
\n\t4.Hexadecimal to Binary
\n\t5.Binary to Octal
\n\t6.Octal to Binary
\n\t7.Exit\n"); scanf("%d",&choice); switch(choice) { case 1: // Binary to Decimal printf("Enter Binary Number :\t"); scanf("%d",&number); printf("Decimal Number :\t%d",binary_to_decimal(number)); break; case 2: // Decimal to Binary printf("Enter Decimal Number :\t"); scanf("%d",&number); decimal_to_binary(number); break; case 3: // Binary to Hexadecimal printf("Enter Binary Number :\t"); scanf("%d",&number); binary_to_hexa(number); break; case 4: // Hexadecimal to Binary printf("Enter Hexadecimal Number :\t"); scanf("%s",&hexa); hexa_to_binary(hexa); break; case 5: // Binary to Octal printf("Enter Binary Number :\t"); scanf("%d",&number); binary_to_octal(number); break; case 6: // Octal to Binary printf("Enter Octal Number :\t"); scanf("%d",&number); octal_to_binary(number); case 7: // Exit break; default:break; } } while(choice!=7);}int binary_to_decimal(int num){ int i=0,sum=0; while(num!=0) { sum=sum+(num%10)*pow(2,i++); num/=10; } return sum;}int decimal_to_binary(int num){ int array[SIZE],i=0; while(num!=0) { array[i++]=num%2; num/=2; } printf("Binary Number :\t"); for(--i;i>=0;i--) printf("%d",array[i]);}void binary_to_hexa(int num){ int array[SIZE],i=0; num=binary_to_decimal(num); if(num==0) { array[i++]=0; } while(num!=0) { array[i++]=num%16; num/=16; } printf("\nHexadecimal No :\t"); for(--i;i>=0;i--) { if(array[i]>=10&&array[i]<=15) printf("%c",array[i]+55); else printf("%d",array[i]); }}int hexa_to_binary(char s[]){ int a[SIZE],i,dn=0,j=0; for(i=0;s[i]!=NULL;i++) { if(s[i]<=57&&s[i]>=48) a[i]=s[i]-48; if(s[i]>=65&&s[i]<=70) a[i]=s[i]-55; else { printf("Wrong Input"); return; } } for(;--i>=0;) { dn+=a[i]*pow(16,j++); } decimal_to_binary(dn);}void binary_to_octal(int num){ int array[SIZE],i=0; num=binary_to_decimal(num); if(num==0) { array[i++]=0; } while(num!=0) { array[i++]=num%8; num/=8; } printf("Octal Number :\t"); for(--i;i>=0;i--) printf("%d",array[i]);}void octal_to_binary(int num){ int i=0,sum=0; while(num!=0) { sum=sum+(num%10)*pow(8,i++); num/=10; } decimal_to_binary(sum);}
Related Links :
#include "stdio.h"
#include "malloc.h"
#define MAXSIZE 10
void insertion();
void deletion();
void display();
struct node
{
int info;
struct node *link;
}
*new,*temp,*p,*front=NULL,*rear=NULL;
typedef struct node N;
main()
{
int ch;
do
{
printf("\n\t\t\tLinked queue");
printf("\n 1.Insertion");
printf("\n 2.Deletion");
printf("\n 3.Display");
printf("\n 4.Exit");
printf("\n Enter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
insertion();
break;
case 2:
deletion();
break;
case 3:
display();
break;
default:
break;
}
}
while(ch<=3);
}
void insertion()
{
int item;
new=(N*)malloc(sizeof(N));
printf("\nEnter the item : ");
scanf("%d",&item);
new->info=item;
new->link=NULL;
if(front==NULL)
front=new;
else
rear->link=new;
rear=new;
}
void deletion()
{
if(front==NULL)
printf("\nQueue is empty");
else
{
p=front;
printf("\nDeleted element is : %d",p->info);
front=front->link;
free(p);
}
}
void display()
{
if(front==NULL)
printf("\nQueue is empty");
else
{
printf("\nThe elements are : ");
temp=front;
while(temp!=NULL)
{
printf("%d",temp->info);
temp=temp->link;
}
}
}
Related Links :
#include "stdio.h"#include "malloc.h"#define maxsize 10void push();void pop();void display();struct node{int info;struct node *link;}
*start=NULL, *new,*temp,*p;typedef struct node N;main(){int ch,a;do{printf("\t\t\tLinked stack");printf("\n 1.Push");printf("\n 2.Pop");printf("\n 3.Display");printf("\n 4.Exit");printf("\n Enter your choice : ");scanf("%d",&ch);switch(ch){case 1:push();break;case 2:pop();break;case 3:display();break;case 4:exit(0);default:printf("\nInvalid choice");break;}}while(ch<=3);}void push(){new=(N*)malloc(sizeof(N));printf("\nEnter the item : ");scanf("%d",&new->info);new->link=NULL;if(start==NULL)start=new;else{p=start;while(p->link!=NULL)p=p->link;p->link=new;}}void pop(){if(start==NULL)printf("\nStack is empty");else if(start->link==NULL){printf("\nThe deleted element is : %d",start->info);free(start);start=NULL;}else{p=start;while(p->link!=NULL){temp=p;p=p->link;}printf("\nDeleted element is : %d\n", p->info);temp->link=NULL;free(p);}}void display(){if(start==NULL)printf("\nStack is empty");else{printf("\nThe elements are : ");p=start;while(p!=NULL){printf("%d",p->info);p=p->link;}printf("\n");}}
Related Links :
#include "stdio.h"
int main()
{
int c,w=0,ch=0,l=0;
while((c=getchar())!=-1)
{
++ch;
if (c=='\n')
{
++l;
++w;
}
if (c==' ')
++w;
}
printf("characters = %d, words = %d, lines = %d",ch,w,l);
}
Related Links :
int main(){char c;c=getchar();if(c>65&&c<90)
c=c+32;
if(c>=97&&c<=122){c=c-32;printf("%c",c);}}
Related Links :
#include "stdio.h"
void matmul(int[][],int[][],int,int,int,int);
main()
{
int matrix_1[20][20],matrix_2[20][20],i,j,r1,r2,c1,c2;
printf("Enter the number of rows and columns of first matrix :\t");
scanf("%d%d",&r1,&c1);
printf("Enter the number of rows and columns of second matrix :\t");
scanf("%d%d",&r2,&c2);
if(c1==r2)
{
printf("Enter the elements of first matrix :\n");
for(i=0;i
{
for(j=0;j
{
scanf("%d",&matrix_1[i][j]);
}
}
printf("The first matrix is :\n");
for(i=0;i
{
for(j=0;j
{
printf("%d\t",matrix_1[i][j]);
}
printf("\n");
}
printf("Enter the elements of first matrix :\n");
for(i=0;i
{
for(j=0;j
{
scanf("%d",&matrix_2[i][j]);
}
}
printf("The second matrix is :\n");
for(i=0;i
{
for(j=0;j
{
printf("%d\t",matrix_2[i][j]);
}
printf("\n");
}
matmul(matrix_1,matrix_2,r1,c1,r2,c2);
}
else
printf("Multiplication not possible.\n");
}
void matmul(int num1[20][20],int num2[20][20],int r1,int c1,int r2,int c2 )
{
int k,c[30][30],i,j;
printf("The product matrix is :\n");
c[i][j]=0;
for(i=0;i
{
for(j=0;j
{
for(k=0;k
{
c[i][j]=c[i][j]+(num1[i][k]*num2[k][j]);
}
}
}
for(i=0;i
{
for(k=0;k
{
printf("%d\t",c[i][k]);
}
printf("\n");
}
}
Related Links :
/* Implentation of queue using arrays */# include "stdio.h"# define SIZE 10int arr[SIZE], front = -1, rear = -1, i ;void enqueue() ;void dequeue() ;void display() ;int main(){int ch ;do{printf("\n[1].ENQUEUE [2].DEQUEUE [3].Display [4].Exit\n") ;printf("Enter your choice [1-4] : ") ;scanf("%d", &ch) ;switch(ch){case 1 :enqueue() ;break ;case 2 :dequeue() ;break ;case 3 :display() ;break ;case 4 :break ;default :printf("Invalid option\n") ;}} while(ch != 4) ;}void enqueue(){if(rear == SIZE - 1){printf("Queue is full (overflow)\n") ;return ;}rear++ ;printf("Enter the element to ENQUEUE : ") ;scanf("%d", &arr[rear]) ;if(front == -1)front++ ;}void dequeue(){if(front == -1){printf("Queue is empty (underflow)\n");return ;}printf("The DEQUEUE element is : %d\n", arr[front]) ;if(front == rear)front = rear = -1 ;elsefront++ ;}void display(){if(front == -1){printf("Queue is empty (underflow)\n") ;return ;}printf("The elements in queue are : FRONT -> ") ;for(i = front ; i <= rear ; i++) printf(" ... %d", arr[i]) ; printf(" ... <- REAR\n") ; }
Related Links :
#define SIZE 100
#include "stdio.h"
float mean_function(float[],int);
float median_function(float[],int);
float mode_function(float[],int);
int main()
{
int i,n,choice;
float array[SIZE],mean,median,mode;
printf("Enter No of Elements\n");
scanf("%d",&n);
printf("Enter Elements\n");
for(i=0;ia[j])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
if(n%2==0)
return (a[n/2]+a[n/2-1])/2;
else
return a[n/2];
}
float mode_function(float a[],int n)
{
return (3*median_function(a,n)-2*mean_function(a,n));
}
Related Links :
#define SIZE 100
#include "stdio.h"
int hcf_function(int,int);
int lcm_function(int,int);
int main()
{
int array[SIZE],n,i,choice,lcm,hcf;
printf("Enter No of Elements\n");
scanf("%d",&n);
printf("Enter Elements\n");
for(i=0;i
scanf("%d",&array[i]);
do
{
printf("\n\nEnter Choice\n\n1.HCF\n2.LCM\n3.Exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1: hcf=array[0];
for(i=1;i
hcf=hcf_function(hcf,array[i]);
printf("\nHCF = %d",hcf);
break;
case 2: lcm=array[0];
for(i=1;i
lcm=lcm_function(lcm,array[i]);
printf("\nLCM = %d",lcm);
break;
case 3: break;
default:printf("Wrong Choice");
break;
}
}while(choice!=3);
}
int hcf_function(int m,int n)
{
int temp,reminder;
if(m
{
temp=m;
m=n;
n=temp;
}
while(1)
{
reminder=m%n;
if(reminder==0)
return n;
else
m=n;
n=reminder;
}
}
int lcm_function(int m,int n)
{
int lcm;
lcm=m*n/hcf_function(m,n);
return lcm;
}
Related Links :
#include "stdio.h"void solution(int a[][],int n);int main(){ int a[20][20],n,i,j,k,l; printf("\nENTER THE NUMBER OF VARIABLES:\n"); scanf("%d",&n); for(i=0;i\ { printf("\nENTER THE EQUATION%d:\n",i+1); for(j=0;j { printf("ENTER THE COEFFICIENT OF x%d:\n",j+1); scanf("%d",&a[i][j]); } printf("\nENTER THE CONSTANT:\n"); scanf("%d",&a[i][n]); } solution(a,n);}/************FUNCTION TO FIND THE SOLUTION OF THE EQUATION***************/void solution(int a[20][20],int n){ int k,i,l,j; for(k=0;k { for(i=0;i<=n;i++) { l=a[i][k]; for(j=0;j<=n;j++) { if(i!=k) a[i][j]=a[k][k]*a[i][j]-l*a[k][j]; } } } printf("\nSOLUTIONS:"); for(i=0;i { printf("\nTHE VALUE OF x%d IS %f\n",i+1,(float)a[i][n]/(float)a[i][i]); }}
Keys : C Programming, Programming in C, average of two numbers, c program to find average, program for average, average of 2 numbers.
Related Links :
/* PROGRAM TO IMPLEMENT BINARY SEARCH TREE IN C*/#include"stdio.h"struct BT{ int data; struct BT *right,*left;};void insert(struct BT ** ptr,int d){ if((*ptr)==NULL) { (*ptr)=(struct BT*)malloc(sizeof(struct BT)); (*ptr)->data=d; (*ptr)->left=(*ptr)->right=NULL; } else { if((*ptr)->data>d) insert(&((*ptr)->left),d); else insert(&((*ptr)->right),d); } return;}int search(struct BT *ptr,int no){ if(ptr==NULL) return(0); if(ptr->data==no) return(1); if(ptr->data>no) return(search(ptr->left,no)); else return(search(ptr->right,no));}void inorder(struct BT *ptr){ if(ptr==NULL) return; else { inorder(ptr->left); printf("\t%d",ptr->data); inorder(ptr->right); }}void preorder(struct BT*ptr){ if(ptr==NULL) return; else { printf("\t%d",ptr->data); preorder(ptr->left); preorder(ptr->right); }}void postorder(struct BT*ptr){ if(ptr==NULL) return; else { postorder(ptr->left); postorder(ptr->right); printf("\t%d",ptr->data); }}main(){ struct BT*root; int ch,d,no,f; root=NULL; while(ch!=6) { printf("\n 1.Insert\n 2.Search\n 3.Inorder\n 4.Preorder\n 5.Postorder\n 6.Exit\n"); printf("\n Enter the choice:"); scanf("%d",&ch); switch(ch) { case 1:
printf("Enter the data:"); scanf("%d",&d); insert(&root,d); break; case 2:
printf("Enter the node:"); scanf("%d",&no); f=search(root,no); if(f==0) printf("Node is not present"); else printf("Node is present"); break; case 3:
inorder(root); break; case 4:
preorder(root); break; case 5:
postorder(root); break; case 6: break; } }}
Related Links :
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 ();
}