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
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 :
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
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 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
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
#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
#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
#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
#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
#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
#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 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 :
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
#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
#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 :
C Program to calculate Sum and Average of Marks and validate also
#include
#include
main()
{
int m[5],i,sum=0,avg;
clrscr();
printf("Enter the marks of five subjects=");
for(i=0;i<=4;i++)
{
scanf("%d",&m[i]);
}
for(i=0;i<=4;i++)
{
if(m[i]>100)
{
printf("Invalid\n");
break;
}
else
{
sum=sum+m[i];
}
}
printf("Sum=%d\n",sum);
avg=sum/5;
printf("Avg=%d",avg);
getch();
}
Related Links :
C While Loop Program to show Difference Between Pre-Increment and Post-Increment
#include
int main(void) {
int i;
i = 0;
while(i++ < 5) {
printf("%d\n", i);
}
printf("\n");
i = 0;
while(++i < 5) {
printf("%d\n", i);
}
return 0;
}
Related Links :
C Program to show Example of While .. Continue
#include
int main()
{
int i;
i = 0;
while ( i < 20 )
{
i++;
printf(" to see\n");
continue;
printf("Nothing to see\n");
}
return 0;
}
Related Links :
C Program to print 1 to 10 Numbers using While and Break
#include
int main()
{
int i;
i = 0;
while ( i < 20 )
{
i++;
if ( i == 10)
break;
}
return 0;
}
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 ();
}