HOME

Wednesday, April 29, 2015

SORTING OF NUMBER IN DESCENDING ORDER USING SELECTION SORT METHOD IN C PROGRAM

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[20],i,j,n,temp;
    printf("enter the limit n\n");
    scanf("%d",&n);
    printf("enter the %d numbers\n",n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]<a[j])
            {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
            }
        }
    }
    printf("the sorted data are:\t");
    for(i=0;i<n;i++)
    {
        printf("%d\t",a[i]);
    }

}

TO FIND OUT SUM OF DIAGONAL ELEMENT OF MATRIX USING C PROGRAM

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[2][2],i,j,sum=0;
    printf("enter the matrix:\n");
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            scanf("%d",&a[i][j]);
            printf("\t");
        }
        printf("\n");
    }
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
    {
        if(i==j)
        {
            sum+=a[i][j];
        }
    }
     }
printf("the sum of diagonal element of matrix is %d",sum);
}

C PROGRAM TO FIND THE TRANSPOSE OF GIVEN 2X2 MATRIX

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[2][2],i,j;
    printf("enter the matrix:\n");
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            scanf("%d",&a[i][j]);
            printf("\t");
        }
        printf("\n");
    }
    printf("the transpose of matrix is:\n");
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
    {
        printf("%d\t",a[j][i]);
    }
    printf("\n");
    }
}

Thursday, April 23, 2015

C PROGRAM TO SWAP NUMBER BY PASSING POINTER TO FUNCTION

#include<stdio.h>
#include<conio.h>
int swap(int **c,int **d);
void main()
{
    int a,b,*c,*d;
    printf("enter the value\n");
    printf("a=");
    scanf("%d",&a);
    printf("\nb=");
    scanf("%d",&b);
    c=&a;
    d=&b;
    swap(&c,&d);
}
int swap(int **c,int **d)
{
    **c=**c+**d;
    **d=**c-**d;
    **c=**c-**d;
    printf("after swapping\n");
    printf("a=%d",**c);
    printf("\nb=%d",**d);
    return 0;
}

Saturday, April 18, 2015

C PROGRAM USING MACRO TO FIND AREA OF CIRCLE

#include<stdio.h>
#include<conio.h>
#define pie 3.14
#define circle(pie,r) (pie*r*r)
void main()
{
    float r,a;
    printf("enter the radius:\t");
    scanf("%f",&r);
    a=circle(pie,r);
    printf("the area of circle is %f",a);
getch();
}

C PROGRAM TO KNOW ASCII VALUE OF KEY WHICH YOU HAVE ENTERED

#include<stdio.h>
#include<conio.h>
void main()
{
    char a,b;
    do{
    printf("Enter the key which you want to know ASCII value\t");
a=getch();
    printf("\n\nthe ASCII value of key you have entered is: %d",a);
    printf("\n\nwant to know more 'y' for yes, 'n' for no(Y/N)\n\n");
    b=getch();
    }while(b=='y' || b=='Y');
getch();
}

Tuesday, April 14, 2015

C PROGRAM TO READ THE DATA FROM THE FILE

#include<stdio.h>
#include<conio.h>
void main()
{
    FILE *fp;
    char *p,data[20];
    fp=fopen("file.txt","r");
    while((p=fgets(data,40,fp))!=NULL)
    {
        printf("%s\n",data);
    }
    fclose(fp);
}

C PROGRAM FOR FILE HANDLING TO WRITE DATA IN FILE

#include<stdio.h>
#include<conio.h>
struct student
{
    char name[20];
    int age;
    int mark;
};
void main()
{
    FILE *fp;
    int i,n;
    char name[20];
    fp=fopen("file.txt","w");
    printf("how many data you want to store\n");
    scanf("%d",&n);
    struct student s[20];
    for(i=0;i<n;i++)
    {
    printf("name%d=\t",i+1);
    scanf("%s",s[i].name);
    fprintf(fp,"%s\t",s[i].name);
    printf("age%d=\t",i+1);
    scanf("%d",&s[i].age);
    fprintf(fp,"%d\t",s[i].age);
    printf("mark%d=",i+1);
    scanf("%d",&s[i].mark);
    fprintf(fp,"%d\n",s[i].mark);
    }
    fclose(fp);
}

Saturday, April 11, 2015

C PROGRAM CODE FOR HOTEL BILL

#include<stdio.h>
#include<conio.h>
#include<windows.h>
void bill(char name[], char add[], int o[],char *s[],int p[]);
void main()
{
int i,o[10],p[]={40,60,55,85,95,90,130,25,20,10};
char *s[]={"Rice       ","Fried Rice  ","Sahi Paneer  ","Chicken Kosa  ","Chicken Kabab","Chilli Chicken","Mutton Kosa","Salad       ","Soft Drinks","Sweets        "};
char name[20],add[20];
char a,b;
printf("\t ****************WELCOME TO HOTEL LOVELY***************** \n");
printf("\t\t\tNH-1, PHAGWARA, PUNJAB\n");
printf("\t\t\t MOBILE-+91-9872300000\n");
printf("\n\t Enter Your Name:\t ");
gets(name);
printf("\t Enter Your Address:\t");
gets(add);
printf("\n\t **** DEAR CUSTOMER, TODAY WE HAVE SPECIALY ITEM FOR YOU ****\n\n");
printf(" \t ITEMS \t\t\t PRICE\n");
for(i=0;i<10;i++)
{
printf(" %d. %s \t\t %d (Per Plate)\n",i+1,s[i],p[i]);
}
printf("\nDear customer, would you like to give order?(y for yes/ n for no) : ");
scanf("%c",&a);
if(a=='y'||a=='Y')
{
printf("\n\t Your Order ......");
printf("\n \t Please Select Your Order(Enter Quantity only):\n");

for(i=0;i<10;i++)
{
printf("\n  %d  \t   %s   \t\t   :\t",i+1,s[i]);
scanf("%d",&o[i]);
}
printf("\n\n \t In 10 Minutes, food will be on the Table");
printf("\n \t Please Wait....!\n");
printf("\n\n\n\t Want bill, Sir...?(y for yes)\t:\t ");
scanf(" %c",&b);

if(b=='y'||b=='Y')
{
   bill(name,add,o,s,p);
   }
}
printf("\n\n\n\t\t Thank You Sir, Visit Again...!");
printf("\n___________________________________________________DEVELOPED BY BIKASH THAPA\n");
}
void bill(char name[], char add[], int o[],char *s[],int p[])
   {
       int i,tot=0;
       system("cls");
       printf("\n\t******************WELCOME TO HOTEL LOVELY********************* \n");
printf("\t\t\t NH-1, PHAGWARA, PUNJAB\n");
printf("\t\t\t MOBILE-+91-9872350000\n");
printf("\n\t Customer Name: \t");
puts(name);
printf("\t Customer Address: \t");
puts(add);
printf("\n\t Your Today's Bill is.....\n");
printf(" \t\t\t    ITEMS       \t\t\t\t TOTAL");
printf("\n\t____________________________________________________________________");
for(i=0;i<10;i++)
{
if(o[i]!=0)
{
printf("\n\t\t    %s    \t(%d X %d)\t\t    %d",s[i],o[i],p[i],o[i]*p[i]);
}
}
printf("\n\t____________________________________________________________________");
for(i=0;i<10;i++)
{
tot=tot+o[i]*p[i];
}
printf("\n\t Your Total Billing amount is\t:\t\t\t    %d\n",tot);
}

Friday, April 10, 2015

C PROGRAM FOR QUIZ

#include<stdio.h>
#include<conio.h>
void main()
{
    int counter;
    char name[10],z,b,x,w;
    printf("*******************************************************************************\n");
        counter=0;
    printf("-----*********************WELCOME TO QUIZ CONTEST ***********************------\n");
    printf("\t           IF YOU WANT TO PLAY QUIZ THEN PRESS 'Y'\n");
    b=getch();
    if(b=='y' || b=='Y')
    {
        do
    {
        printf("\nENTER YOUR NAME? \n");
        scanf("%s",name);
        printf("\nHey %s, You are most welcome to our quiz contest.\n",strupr(name));
        printf("-------------------------------------------------------------------------\n");
        printf("PLEASE READ RULES AND INSTRUCTION CAREFULLY BEFORE ATTENDING TO QUIZE: \n");
        printf("-------------------------------------------------------------------------\n");
        printf("Press 'a' if answer of 'a' is correct.\nPress 'b' if answer of 'b' is correct.\nPress 'c' if answer of 'c' is correct.\nPress 'd' if answer of 'd' is correct.\nIf you press any key beside a or b,\nor c or d,then answer is counted as wrong.\n");
        printf("If you have completed by reading rules and instruction.\n");
        printf("------------------------PRESS 'C' TO CONTINUE----------------------------------");
        x=getch();
        if(x=='c' || x=='C')
        {
               printf("\n------------------FINALLY QUESTION GOES HERE:------------------------\n");
               printf("****************************BEST OF LUCK*******************************\n");
               printf("-------------------------------------------------------------------------");
               printf("\n\n1.Who is knowns father of computer science? \n");
               printf("a.Charles Babbage\t b.Mahatma Gandhi\nc.Bill grates     \t d.Lady Ada ");
                      z=getch();
                      switch(z)
                      {
                          case 'a':
                            printf("\n***********correct************");
                              counter=counter+1;
                              break;

                          default:
                            printf("\n************wrong**************");
                            break;
                      }

                      printf("\n\n2.Who is known as light of Asia?");
               printf("\na.Charles Babbage\t b.Mahatma Gandhi\nc.Bill grates     \t d.Gautam Buddha ");
                    z=getch();
                      switch(z)
                      {
                          case 'd':
                            printf("\n************correct************");
                            counter=counter+1;
                            break;
                          default:
                            printf("\n*************wrong**************");
                            break;
                      }
                         printf("\n\n3.'OS' computer abbreviation usually means ?\n");
               printf("a.operating shutdown\t b.open software\nc.operating system \t d.optical sensor");
                      z=getch();
                      switch(z)
                      {
                          case 'c':
                            printf("\n***********correct************");
                              counter=counter+1;
                              break;

                          default:
                            printf("\n************wrong**************");
                            break;
                      }
                      printf("\n\n4.'.MOV' extension refers usually to what kind of file?\n");
               printf("a.Image file\t b.Animation/Movie\nc.Audio file\t d.Ms office document");
                      z=getch();
                      switch(z)
                      {
                          case 'b':
                            printf("\n***********correct************");
                              counter=counter+1;
                              break;

                          default:
                            printf("\n************wrong**************");
                            break;
                      }
                      printf("\n\n5.Which of the following special symbol allowed in a variable name? \n");
               printf("a.*(asterisk)\t b.|(pipeline)\nc.-(hyphen) \t d._(underscore)");
                      z=getch();
                      switch(z)
                      {
                          case 'd':
                            printf("\n***********correct************");
                              counter=counter+1;
                              break;

                          default:
                            printf("\n************wrong**************");
                            break;
                      }
                      printf("\n\n6.By default a real number is treated as a:? \n");
               printf("a.float\t\tb.double\nc.long double \t d.far double");
                      z=getch();
                      switch(z)
                      {
                          case 'b':
                            printf("\n***********correct************");
                              counter=counter+1;
                              break;

                          default:
                            printf("\n************wrong**************");
                            break;
                      }
                      printf("\n\n7.Array is the collection of similar:? \n");
               printf("a.data type\tb.variable\nc.constant\t d.data");
                      z=getch();
                      switch(z)
                      {
                          case 'a':
                            printf("\n***********correct************");
                              counter=counter+1;
                              break;

                          default:
                            printf("\n************wrong**************");
                            break;
                      }
        printf("\n\n8.Which of the following is not a user defined data types?\n");
               printf("a.int\t\tb.enum\nc.struct\td.union");
                      z=getch();
                      switch(z)
                      {
                          case 'a':
                            printf("\n***********correct************");
                              counter=counter+1;
                              break;

                          default:
                            printf("\n************wrong**************");
                            break;
                      }
                      printf("\n\n9.2 byte is equal to:\n");
               printf("a.1 bit\t\tb.16 bit\nc.32 bit\td.8 bit");
                      z=getch();
                      switch(z)
                      {
                          case 'b':
                            printf("\n***********correct************");
                              counter=counter+1;
                              break;

                          default:
                            printf("\n************wrong**************");
                            break;
                      }
                      printf("\n\n10.Network of network is known as ?\n");
               printf("a.URL\t\tb.MAN\nc.LAN\t\td.WAN");
                      z=getch();
                      switch(z)
                      {
                          case 'd':
                            printf("\n***********correct************");
                              counter=counter+1;
                              break;

                          default:
                            printf("\n************wrong**************");
                            break;
                      }
                      printf("\n\n%d answer is correct",counter);
    }
                           else
    {
        printf("\n\n**************HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHA********************");
        printf("\n*************|| YOU ARE LOSER READ INSTRUCTION PROPERLY || ****************");
        printf("\n**************************||GET LOST||***********************************");

    }
    if(counter>=8)
    {
        printf("\n****************CONGRATULATION YOU HAVE WON THE QUIZ**********************\n");
    }
    else
    {
        printf("\n********************YOU ARE LOSER || TRY AGAIN***************************\n");
    }
     printf("\n***************Thanks Mr/s. %s for participating in our quiz*************",name);

     printf("\nDO YOU WANT TO TRY AGAIN IF YES THEN PRESS 'Y'");
        w=getch();
    }
while(w=='y' || w=='Y');
}
else
{
printf("\nPlease read instruction properly and try again later\n");
}
printf("\n************************************************DEVELOPED BY MR.BIKASH THAPA");
}

SAMPLE C PROGRAM USING UNION

#include<stdio.h>
#include<conio.h>
union employ
{
    char name[20];
    int age;
    float salary;
};
void main()
{
    union employ e;
    printf("enter the employ name\n");
    gets(e.name);
    printf("%s",e.name);
    printf("\nenter the age\n");
    scanf("%d",&e.age);
    printf("%d",e.age);
    printf("\nenter the salary\n");
    scanf("%f",&e.salary);
    printf("%f",e.salary);
    printf("\nthe size is %d",sizeof(e));
}

COUNT VOWEL, CONSONANT, NUMBER, WHITE SPACE & LENGTH PRESENT IN GIVEN STRING USING C PROGRAM

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char string[100];
int v=0,c=0,w=0,nu=0,n,i;
printf("enter the string\n");
gets(string);
n=strlen(string);
for(i=0;i<n;i++)
{
    if(string[i]=='a'||string[i]=='A'||string[i]=='e'||string[i]=='E'||string[i]=='i'||string[i]=='I'||string[i]=='o'||string[i]=='O'||string[i]=='u'||string[i]=='U')
    {
        v++;
    }
    else if(string[i]>='a' && string[i]<='z' || string[i]>='A' && string[i]<='Z')
    {
        c++;
    }
    else if(string[i]==' ')
    {
        w++;
    }
    else if(string[i]>='0'&& string[i]<='9')
    {
        nu++;
    }
}
printf("total number of word letter present is %d\n",v);
printf("total number of consonant letter present is %d\n",c);
printf("total number of number present is %d\n",nu);
printf("total number of white space present is %d\n",w);
printf("total number of letter present is %d",n);
}

Thursday, April 9, 2015

Thursday, April 2, 2015

C PROGRAM OF STRUCTURE ARRAY TO TAKE DATA AND DISPLAY IT

#include<stdio.h>
#include<conio.h>
struct student
{
    char name[20];
    int roll,age;
};
void stud(struct student s[],int n);
void main()
{
    struct student s[10];
 int i,n;
 printf("how many data you want to print\n");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
    printf("enter the name %d\n",i+1);
    scanf("%s",s[i].name);
    printf("enter the roll no\n");
    scanf("%d",&s[i].roll);
    printf("enter the age\n");
    scanf("%d",&s[i].age);
 }
     stud(s,n);
}
stud(struct student s[],int n)
{
    int i;
    printf("the data you have entered are:\n");
    printf("name\troll no\tage\n");
    for(i=0;i<n;i++)
    {
        printf("%s\t%d\t%d\n",s[i].name,s[i].roll,s[i].age);
    }
}

C PROGRAM TO DISPLAY DATA USING POINTER TO STRUCTURE

#include<stdio.h>
#include<conio.h>
struct student
{
    char name[20];
    int roll,age;
};
void main()
{
    struct student s,*p;
    p=&s;
    printf("enter the name\n");
    scanf("%s",p->name);
    printf("enter the roll no\n");
    scanf("%d",&p->roll);
    printf("enter the age\n");
    scanf("%d",&p->age);
    printf("name\troll no\tage");
    printf("\n%s\t%d\t%d\n",p->name,p->roll,p->age);
}

2D ARRAY SORTING OF COLUMNS AND ROWS

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

int main( )
{

    int a[][6]={
                {25,64,96,32,78,27},      //from here begins my Desired solution : {25,27,32,64,78,96},
                {50,12,69,78,32,92}       //                   {50,92,78,12,32,69}
                };
     int i, j, k, temp, temp1 ;

    //
     for(j=1;j<6;j++)
     {
          for(i=0; i<5; i++)
          {
                if(a[0][i]>a[0][i+1])
                {
                    temp=a[0][i];
                    a[0][i]=a[0][i+1];
                    a[0][i+1]=temp;

                    temp1 = a[1][i];
                    a[1][i] = a[1][i+1];
                    a[1][i+1]=temp1;
                }
          }
     }

     printf ( "\n\nArray after sorting:\n") ;
     for ( i = 0 ; i <2; i++ )
     {
        for(j=0; j<6; j++)
        {
            printf ( "%d\t", a[i][j] ) ;        // from here am printing sorted array
        }
        printf("\n");
     }
     getch();
 }

PPT – Malware PowerPoint presentation | free to view

PPT – Malware PowerPoint presentation | free to view