This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

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

Thursday, November 22, 2012

C PROGRAM FOR REPLACING STRING


/* C PROGRAM FOR  REPLACING STRING*/

#include<stdio.h>
#include<conio.h>
#include<string.h>

 void main()
 {
          int slen,sublen,newlen,reslen,m,k,i,j,temp;
          char str[40],substr[20],newstr[20],resstr[25];
          clrscr();
          printf("\n\t\t STRING REPLACING");
          printf("\n\t\t ~~~~~~~~~~~~~~~~~");
          printf("\n Enter any string:");
          gets(str);
          slen=strlen(str);
          printf("\n Enter the substring:");
          gets(substr);
          sublen=strlen(substr);
          printf("\n Enter the replacement string:");
          gets(resstr);
          reslen=strlen(resstr);
          j=0;
          k=0;
for(i=0;i<slen;i++)
{
         newstr[k]=str[i];
         k++;
         if(str[i]==substr[j])
         j++;
else
         j=0;
if(j==sublen)
{
         k=k-sublen;
         j=0;
for(m=0;m<reslen;m++)
{
         newstr[k]=resstr[m];
         k++;
     }
   }
}
      newstr[k]='\0';
      printf("\n The replaced string is %s",newstr);
      getch();
}


OUTPUT:

                 STRING REPLACING
                 ~~~~~~~~~~~~~~~~~
 Enter any string: RAJ

 Enter the substring: R

 Enter the replacement string: T

 The replaced string is: TAJ





C PROGRAM FOR SALES REPORT


/*  C PROGRAM FOR  SALES REPORT */


#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
     int sal[5][5],s,p,i,j,row,col,temp,per,avg;
     char s_men[10][30],pr[10][30],waste[33];
     clrscr();
     printf("\n\t\t SALES REPORT");
     printf("\n\t\t -------------");
     printf("Enter how many salesman:");
     scanf("%d",&s);
     printf("Enter how many products:");
     scanf("%d",&p);
     clrscr();
     gets(waste);
for(i=1;i<=s;i++)
{
     printf("\n Enter the %d name of salesman:",i);
     gets(s_men[i]);
 }
for(j=1;j<=p;j++)
{
     printf("\n Enter the %d name of products:",j);
     gets(pr[j]);
}
for(i=1;i<=s;i++)
for(j=1;j<=p;j++)
     sal[i][j]=0;
     clrscr();
     printf("\n\t The salesman and products data:");
while(1)
{
     clrscr();
for(i=1;i<=s;i++)
     printf("\n%d salesman :%s",i,s_men[i]);
for(i=1;i<=p;i++)
{
      gotoxy(35,i+1);
      printf("%d Products:%s",i,pr[i]);
}
    


     gotoxy(5,10);
     printf("\n\n Enter which salesman connected with which products");
     printf("\n Enter the salesman no");
     scanf("%d",&row);
     printf("\n Enter the product no:");
     scanf("%d",&col);
     printf("\n Enter the sales rupees:");
     scanf("%d",&per);
     sal[row][col]=per;
     printf("\n\n Do you want to continue (1 for yes,2 for no):\n");
     scanf("%d",&temp);
     if(temp==1)
     continue;
     else
     break;
  }
  clrscr();
  printf("\n\n The salesman and products report:\n\n");
  gotoxy(8,5);
for(i=1;i<=p;i++)
   printf("\t Products %d",i);
   printf("\n");
for(i=1;i<=s;i++)
{
    printf("Salesman %d",i);
for(j=1;j<=p;j++)
    printf("\t%2d\t",sal[i][j]);
    printf("\n\n");
 }
    printf("\n\t Total details:");
for(i=1;i<=s;i++)
{
    avg=0;
for(j=1;j<=p;j++)
    avg=avg+sal[i][j];
    printf("\n The total rupees sold by salesman %d is %d",i,avg);
   }
 getch();
}







OUTPUT:
SALES REPORT
Enter how many salesmen:

Enter how many salesmen: 2
Enter how many products: 2

 Enter the 1 name of salesman: Raj
 Enter the 2 name of salesman: krk

 Enter the 1 name of products: bat
 Enter the 2 name of products: ball

1 salesman: raj                  1 Products: bat
2 salesmen: krk                  2 Products: ball

 Enter which salesman connected with which products:
Enter the salesman no: 1

Enter the product no: 1

Enter the sales rupees: 1000

Do you want to continue (1 for yes, 2 for no): 1

 Enter which salesman connected with which products
 Enter the salesman no: 2

 Enter the product no: 2

 Enter the sales rupees: 500

Do you want to continue (1 for yes, 2 for no): 2

 The salesman and products report:

                    Products 1           Product 2
Salesman 1      1000                     0

Salesman 2         0                       500


       

 Total details:

 The total rupees sold by salesman 1 is 1000

 The total rupees sold by salesman 2 is 500


C PROGRAM FOR BOOK SEARCHING AND SORTING



/* C PROGRAM FOR BOOK SEARCHING AND SORTING*/


#include<stdio.h>
#include<conio.h>
#include<string.h>
void newentry();
void sort();
void search();
void list();
struct books
{
    char authname[50];
    char title[50];
}b[10];
int c=1;
void main()
{
int k,i,ch,n;
char w[30];
clrscr();
printf("\n\t\t\tBOOK OPERATION\n");
printf("\n\t\t\t--------------\n");
printf("\nEnter how many book you want to enter:");
scanf("%d",&n);
for(i=0;i<n;i++)
newentry();

while(1)
{
 clrscr();
 printf("\nMain Menu");
 printf("\n1.Newentry\n");
       printf("\n2.Search");
       printf("\n3.Sort");
       printf("\n4.List");
       printf("\n5.Exit\n");
       printf("\nEnter your choice:");
       scanf("%d",&ch);
switch(ch)
{
 case 1:
                   newentry();
                         break;
       case 2:
                   search();
                   break;
       case 3:
                   sort();
                   break;
       case 4:
                   list();
                   break;
       case 5:
                   exit();
            break;
}
}
}


void search()
{
char tit[44],w[22],d,authname[44];
int i,a=0,z;
clrscr();
gets(w);
printf("\nDo you want to search using author name(Y/N)!");
scanf("%c",&d);

if(d=='y'||d=='n')
{
gets(w);
printf("\nEnter any author name you want to search:");
gets(authname);

for(i=0;i<=c;i++)
{
z=strcmp(authname,b[i].authname);
if(z==0)
{
printf("\n\nThe book have been found");
printf("\n\nThe book title is %s", b[i].title);
printf("\n\nThe book author name is : %s",b[i].authname);
a=1;
}
}
if(a==0)
printf("\n\nThe book was not found:");
}
getch();
}


void sort()
{
char temp[50],t_tit[44][44];
int i,j,z;
clrscr();
printf("\nThe Sorted book are");
for(i=0;i<=c;i++)
strcpy(t_tit[i],b[i].title);
for(i=0;i<=c;i++)
{
for(j=0;j<=c;j++)
{
z=strcmp(t_tit[i],t_tit[j]);





if(z>0)
{
strcpy(temp,t_tit[i]);
strcpy(t_tit[i],t_tit[j]);
strcpy(t_tit[j],temp);
}
}
}
for(i=0;i<=c;i++)
printf("%s\n",t_tit[i]);
getch();
}


void newentry()
{
char titles[20],author[50],was[22];
clrscr();
gets(was);
c++;
printf("Enter any author:");
gets(b[c].authname);
printf("Enter any title:");
gets(b[c].title);
printf("%s",b[c].title);
printf("\n%s",b[c].authname);
printf("\n%s",b[c].authname);
getch();
}


void list()
{
int i;
clrscr();
printf("AUTHOR NAME  \t\tTITLES");
for(i=0;i<=c;i++)
printf("\n\n%s\t\t%s",b[i].authname,b[i].title);
getch();
}






















OUTPUT


BOOK OPERATION

                                               
Enter how many book you want to enter: 2

Enter any author: R.Balaguruswamy

Enter any title: Programming in C

Programming in C
R.Balaguruswamy

Enter any author: Morris Mano

Enter any title: Computer System Architecture

Computer System Architecture
Morris Mano

Main Menu

1. New entry
2. Search
3. Sort
4. List
5. Exit

Enter your choice: 1

Enter any author: Problem Solving Techniques

Enter any title:  R.G.Dromey


Problem Solving Techniques
R.G.Dromey


Main Menu

1. New entry
2. Search
3. Sort
4. List
5. Exit

Enter your choice: 2

Do you want to search using author name(Y/N)!  Y

Enter any author name you want to search: R.Balaguruswamy

The book have been found

The book title is Programming in C

The book author name is: R.Balaguruswamy

Main Menu

1. New entry
2. Search
3. Sort
4. List
5. Exit

Enter your choice: 2

Do you want to search using author name(Y/N)!  Y

Enter any author name you want to search: Richard hall

The book was not found

Main Menu

1. New entry
2. Search
3. Sort
4. List
5. Exit




Enter your choice: 3

The Sorted books are

Programming in C
Problem Solving Techniques
Computer System Architecture



Main Menu

1. New entry
2. Search
3. Sort
4. List
5. Exit

Enter your choice: 4


AUTHOR NAME                              TITLES
----------------------                              ----------

R.Balaguruswamy                      Programming in C

Morris Mano                              Computer System Architecture

R.G.Dromey                               Problem Solving Techniques

Main Menu

1. New entry
2. Search
3. Sort
4. List
5. Exit

Enter your choice: 5




C PROGRAM FOR BANK OPERATION USING FUNCTIONS


/* C PROGRAM FOR  BANK OPERATION USING FUNCTIONS*/


#include<stdio.h>
#include<conio.h>
int amt=10000,b,w,d,n;
void deposit()
{
     printf("Enter amount\n");
     scanf("%d",&d);
     amt=amt+d;
     printf("Your amount is:%d\n",amt);
 }

void withdraw()
{
     printf("Enter amount\n");
     scanf("%d",&w);
     if(amt>=100)
     {
      amt=amt-w;
      printf("Your amt is:%d\n",amt);
     }
     else
     printf("You have below 100 Rs\n");
}

void balance()
{
      printf("The balance amount is :%d\n",amt);
 }
















void main()
{
      int ba;
      clrscr();
      printf("\t\t BANKING OPERATION USING FUNCTION \n\n");
      printf("1.Deposit\n2.Withdraw\n3.Balance\n4.Exit\n");
     do
    {

       printf("\n Enter any choice:");
        scanf("%d",&ba);
        switch(ba)
        {
          case 1:
                    deposit();
                    break;
          case 2:
                    withdraw();
                     break;
          case 3:
                    balance();
                    break;
          case 4:
                        getch();
                        break;
       }
    }while(ba!=4);
     getch();
}
















OUTPUT:


                 BANKING OPERATION USING FUNCTION


1. Deposit
2. Withdraw
3. Balance
4. Exit

 Enter any choice: 1
Enter amount:
1200
Your amount is: 11200

 Enter any choice: 2
Enter amount:
11200
Your amt is: 0

 Enter any choice: 2
Enter amount:
1000
You have below 100 rs

 Enter any choice: 1
Enter amount:
15000
Your amount is: 15000

 Enter any choice: 3
The balance amount is: 15000

 Enter any choice: 4





C PROGRAM FOR STUDENTS MARKSHEET USING STRUCTURES


/*  C PROGRAM FOR STUDENTS MARKSHEET USING STRUCTURES */

#include<stdio.h>
#include<conio.h>

struct stu
{
      int rn,grade,a[5];
      float avg;
  }s[2];

void main()
{
      int i,j,sum,n;
      float avg;
      clrscr();
      printf("\t STUDENT MARKSHEET USING STRUCTURES\n\n");
      printf("Enter the no of students");
      scanf("%d",&n);

for(i=0;i<n;i++)
{
      scanf("%d",s[i].rn);

for(j=0;j<=5;j++)
{
      scanf("%d",&s[i].a[j]);
   }
 }

for(i=0;i<n;i++)
{
       sum=0;

for(j=0;j<5;j++)
{
        sum=sum+s[i].a[j];
        s[i].avg=(float)(sum/5);
        if(s[i].avg>=60)
        s[i].grade=1;
        else if(s[i].avg>50&&s[i].avg<60)
        s[i].grade=2;
else
       s[i].grade=3;
  }
}

       printf("****************************************\n");
       printf("rn\ts1\ts2\ts3\ts4\ts5\tavg\t grade\n");
       printf("*****************************************\n");

for(i=0;i<n;i++)
{
       printf("%d\t",s[i].rn);

for(j=0;j<5;j++)
{
       printf("%d\t",s[i].a[j]);
    }
      printf("%f\t%d\n",s[i].avg,s[i].grade);
  }
  getch();
}































OUTPUT:
STUDENTS MARKSHEET USING STRUCTURES
 
Enter the no of students: 5
1
89        90        90        99        82

2
67        73        77        60        88

3
56        54        59        76        66

4
45        44        56        34        65

5
56        76        90        85        64

*********************************************************
Rn       s1        s2         s3         s4         s5         avg                  grade
*********************************************************
1          89        90        90        99        82        90.000000           1
2          67        73        77        60        88        71.000000           1
3          56        54        53        76        66        62.000000           1
4          45        44        56        34        65        48.000000           3
5          56        76        90        35        64        74.000000           1

C PROGRAM FOR TOWERS OF HANOI


/* C PROGRAM FOR  TOWERS OF HANOI */


#include<stdio.h>
#include<conio.h>

void transfer(int t,char,char,char);
void main()
{
      int n;
      clrscr();
      printf("\n\n\t\t TOWERS OF HANOI");
      printf("\n\n\t\t ~~~~~~~~~~~~~~~~");
      printf("\n\n Enter the no of disk:");
      scanf("%d",&n);
      transfer(n,'l','r','c');
      getch();
  }

void transfer(int n,char from,char to,char temp)
{
if(n>0)
{
       transfer(n-1,from,temp,to);
       printf("\n Move disk %d From %c To %c",n,from,to);
       transfer(n-1,temp,to,from);
    }
 }






















OUTPUT:

                 TOWERS OF HANOI

                 ~~~~~~~~~~~~~~~~

 Enter the no of disk:4

 Move disk 1 From l To c
 Move disk 2 From l To r
 Move disk 1 From c To r
 Move disk 3 From l To c
 Move disk 1 From r To l
 Move disk 2 From r To c
 Move disk 1 From l To c
 Move disk 4 From l To r
 Move disk 1 From c To r
 Move disk 2 From c To l
 Move disk 1 From r To l
 Move disk 3 From c To r
 Move disk 1 From l To c
 Move disk 2 From l To r
 Move disk 1 From c To r





C PROGRAM FOR PRIME NUMBER GENERATION


/* C PROGRAM FOR  PRIME NUMBER GENERATION */



#include<stdio.h>
#include<conio.h>
void main()
{
             int a,b,c=0,r;
 clrscr();
             printf("\n\t\tPRIME NUMBER");
             printf("\n\t\t~~~~~~~~~~~~~");
             printf("\nEnter range:");
             scanf("%d",&r);
             a=1;
            while(a<=r)
             {
                   b=1;c=0;
                   while(b<=a)
                   {
                      if(a%b==0)
                       c=c+1;
                       b++;
                   }           
             if(c==2)
             printf("\n %d is a prime number",a);
             a++;
           }
          getch();
}

         
















OUTPUT:



      PRIME NUMBER
                ~~~~~~~~~~~~~
Enter range: 50

 2 is a prime number
 3 is a prime number
 5 is a prime number
 7 is a prime number
 11 is a prime number
 13 is a prime number
 17 is a prime number
 19 is a prime number
 23 is a prime number
 29 is a prime number
 31 is a prime number
 37 is a prime number
 41 is a prime number
 43 is a prime number
 47 is a prime number


C PROGRAM FOR ARMSTRONG NUMBER



/*  C PROGRAM FOR  ARMSTRONG NUMBER */


#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
     int s,x,i,n;
     clrscr();
     printf("\n\t\tARMSTRONG NUMBER");
     printf("\n\t\t~~~~~~~~~~~~~~~~");
     printf("Armstrong no's are\n");

       for(i=100;i<=1000;i++)
      {
         s=0;
         x=i;

          while(x>0)
          {
              n=x%10;                      
              x=x/10;                  
               s+=pow(n,3);             
           }                       

            if(i==s)                
            printf("%d\n\n",i);     
       }                       
     getch();
}                     

             















OUTPUT:



ARMSTRONG NUMBER
  
 Armstrong no's are:

153

370

371

407