Wednesday, 2 March 2016

C++ Class program ,which calculates area and circumference of circle.

#include<iostream>

using namespace std;
class circle
{int radius;
public:
void setradius()
{cout<<"enter radius=";
cin>>radius;
}
int getdia()
{int d;
cout<<"diameter="<<2*radius<<endl;
}
double getarea()
{double x;
x=3.14*radius*radius;
cout<<"area="<<x<<endl;
}
double getcir()

{double cir;
cir=2*3.14*radius;
cout<<"circumference="<<cir;
}

};
int main()
{circle c;
c.setradius();
cout<<endl;
c.getdia();
cout<<endl;
c.getarea();
cout<<endl;
c.getcir();
return 0;
}

C++ ENTERING NAMES OF STUDENTS

#include<iostream>
#include<string>
using namespace std;
int main()
{ string s[5];
int i;
cout<<"enter the names"<<endl;
for(i=0;i<5;i++)
{

cin>>s[i];
}
cout<<"names are="<<endl;
for(i=0;i<5;i++)
{cout<<s[i]<<endl;
}
return 0;
}

Sunday, 28 February 2016

C++ ADDITION

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a,b,c;
cout<<"enter first number:";
cin>>a;
cout<<"enter second number:";
cin>>b;
c=a+b;
cout<<"the sum of two number:-"<<c<<endl;
return 0;
}

Monday, 30 November 2015

C PROGRAMMING --- SHIFT OPERATOR

#include<conio.h>
#include<stdio.h>
void main()
{       clrscr();
int a,b,c,ch;
printf("enter any integer\n\n");
scanf("%d",&a);
printf("\n\nenter the no of places to shift=");
scanf("%d",&c);
printf("\n\nenter 1 for left shift\tenter 2 for right shift=");
scanf("%d",&ch);
switch(ch)
{ case 1: { b=a<<c;
printf("\n\nshift left << of integer=%d.\n",b);
break;
}
case 2: { b=a>>c;
printf("\n\nshift right >> of integer=%d.\n",b);
break;
}
default : { printf("error\n");
 }
}
getch();
}

Saturday, 21 November 2015

C PROGRAMMING--- STRING FUNCTIONS

#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{    clrscr();
    char a[10];
    printf("enter string\n");
    gets(a);
    puts(strupr(a));
    puts(strlwr(a));
    getch();
}




#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    clrscr();
    char  a[10];
    printf("enter the string\n");
    gets(a);
    puts(strrev(a));
    getch();
}



#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    clrscr();
    char b[10];
    char  a[10];
    int i;
    printf("enter the string 1.\n");
    gets(a);
    printf("enter the string 2.\n");
    gets(b);
    if(strcmp(a,b)==0)
    {
        printf("equal!!");
    }
    getch();
}



#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    clrscr();
    char b[10];
    char  a[10];
    int i;
    printf("enter the string\n");
    gets(a);
    for(i=0;a[i]!='\0';i++)
    {     b[i]=a[i];
    }
    b[i]='\0';
    printf("copied string=");
    puts(b);
    getch();
}


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    clrscr();
    char b[10];
    char  a[10];
    int i;
    printf("enter the string\n");
    gets(a);
    strcpy(b,a);
    printf("copied string=");
    puts(b);
    getch();
}

C PROGRAMMING ---- ENUMERATIONS

#include <stdio.h>
#include <conio.h>
#include <stdio.h>
enum week{ sunday, monday, tuesday, wednesday, thursday, friday, saturday};
void main()
{
    clrscr();
    printf("%d day",wednesday);
    getch();
   }

Wednesday, 4 November 2015

C PROGRAMMING ----SUM OF TWO DISTANCE USING STRUCTURE

#include<stdio.h>
#include<conio.h>
struct distance
{    int ft1,ft2,
    sum1,sum2,
    inch1,inch2;
}d;
void main()
{       clrscr();
    d.sum1=0;d.sum2=0;
    printf("enter the distances\n1.\t 2.\n");
    scanf("%d%d\t%d%d",&d.ft1,&d.inch1,&d.ft2,&d.inch2);
    d.sum1=d.ft1+d.ft2;
    d.sum2=d.inch1+d.inch2;
    if(d.sum2>11)
    {      d.sum1++;
           d.sum2=d.sum2-12;
    }

    printf("total distance=%d.%d",d.sum1,d.sum2);
    getch();
}

Wednesday, 28 October 2015

C PROGRAMMING ---POINTER TO ARRARY

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{       clrscr();
    int a[5]={5,6,7,8,9};
    int *p=a,i;
    for(i=0;i<5;i++)
    {    printf("%u\n",(p+i));
        printf("%d\n",*(p+i));
    }
    getch();
}





Wednesday, 14 October 2015

CALCULATION OF STRING LENGTH


1.USING INBUILT FUNCTION

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    clrscr();
    char  a[10];
    printf("enter the string\n");
    gets(a);
    printf("length of string is %d.",strlen(a));
    getch();
}



2.WITHOU USING INBUILT FUNCTIONS

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    clrscr();
    int b=0;
    char  a[10];
    printf("enter the string\n");
    gets(a);
    while(a[b]!='\0')
    {    b++;
    }
    printf("%d",b);
    getch();
}

Tuesday, 13 October 2015

C PROGRAMMING -- SIMPLE INTEREST USING POINTER

#include<stdio.h>
#include<conio.h>
void main()
{       clrscr();
int p,r,t;
printf("enter the principal,rate,time\n");
scanf("%d\t%d\t%d",&p,&r,&t);
float si;
int *a=&p,*b=&r,*c=&t;
float *d=&si;
*d=(*a)*(*b)*(*c)/100;
printf("simple interest=%f",*d);
getch();
}

C PROGRAMMING -- BINARY SEARCH

#include<conio.h>
#include<stdio.h>
void main()
{ int i,last,first,middle,n,search,a[100];
printf("enter the no of elements=\n");
scanf("%d",&n);
printf("enter %d integers\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the element to search-\n");
scanf("%d",&search);
first=0;
last=n-1;
middle=(first+last)/2;
while(first<=last)
{
if(a[middle]<search)
first=middle+1;
else if(a[middle]==search)
{
printf("%d found at %d.\n",search,middle+1);
break;
}
else last=middle-1;
middle=(first+last)/2;
}
if(first>last)
printf("not found %d sorry.\n",search);
getch();
}

Wednesday, 7 October 2015

C PROGRAMMING -- MATIX ADDITION

#include <stdio.h>
#include <conio.h>
void main()
{
    clrscr();
    int c[3][3],a[3][3],b[3][3],i,j;
    printf("enter the 1st matrix =\n");
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {    scanf("%d",&a[i][j]);
    }
    printf("enter the 2nd matrix =\n");
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {    scanf("%d",&b[i][j]);
    }
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {        c[i][j]=a[i][j]+b[i][j];
    }
    for(i=0;i<3;i++)
       {    {    for(j=0;j<3;j++)

            printf("\t%d",c[i][j]);
        }
            printf("\n");
    }
    getch();
}

C PROGRAMMING -- TRANSPOSE OF A MATRIX

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

C PROGRAMMING -- SUM OF ALL ELEMENTS OF MATRIX

#include <stdio.h>
#include <conio.h>
void main()
{
    clrscr();
    int sum=0,a[3][3],i,j;
    printf("enter the matrix=\n");
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {
        scanf("%d",&a[i][j]);
        sum=sum+a[i][j];
    }
    printf("\n%d",sum);
    getch();
}

Thursday, 24 September 2015

C PROGRAMMING -- LINEAR SEARCH

#include<stdio.h>
#include<conio.h>
void main()
{       clrscr();
int a[5],i,n,flag=0,c=0;

printf("enter the array\n");
for(i=0;i<5;i++)
{ scanf("\t%d",&a[i]);
}
printf("enter the searching element=");
scanf("%d",&n);
for(i=0;i<5;i++)
{ if(a[i]==n)
{ flag=1;
c++;

}
}
if(flag==1)
{ printf("element found !! %d times",c);
}
else
{ printf("element not found");
}
getch();
}

C PROGRAMMING -- NUMBER PATTERN IN MATRIX

#include<conio.h>
#include<stdio.h>
void main()
{       clrscr();
    int i,j,k=1;
    for(i=0;i<5;i++)
    {    for(j=0;j<=i;j++)
    {    printf("\t%d",k);
        k++;
        }
        printf("\n\n");
     }


    getch();
}

Wednesday, 23 September 2015

C PROGRAMMING -- STAR PATTERNS

1.
 
#include<conio.h>
#include<stdio.h>
void main()
{       clrscr();
    int i,j;
    for(i=0;i<5;i++)
    {    for(j=0;j<=i;j++)
        {    printf("\t*");
        }
        printf("\n\n");
     }


    getch();
}

2.
#include<conio.h>
#include<stdio.h>
void main()
{       clrscr();
    int i,j;
    for(i=0;i<5;i++)
    {    for(j=4;j>=i;j--)
        {    printf("\t*");
        }
        printf("\n\n");
     }


    getch();
}


3.
#include<conio.h>
#include<stdio.h>
void main()
{       clrscr();
    int i,j,k;
    for(i=0;i<5;i++)
    {    for(k=0;k<4-i;k++)
        {    printf("\t-");
        }
        for(j=0;j<=i;j++)
        {    printf("\t*");
        }
        printf("\n\n");
     }


    getch();
}
 

C PROGRAMMING -- MINIMUM OF ALL THE EMENTS OF A 3*3 MATRIX

#include<conio.h>
#include<stdio.h>
void main()
{       clrscr();
    int a[3][3],i,j,min; //take max for maximum
    printf("enter the matrix=\n");
    for(i=0;i<3;i++)
    {    for(j=0;j<3;j++)
        {    scanf("\t%d",&a[i][j]);
        }
        printf("\n");
    }
    min=a[0][0];
    for(i=0;i<3;i++)
    {    for(j=0;j<3;j++)
        {    if(a[i][j]<min)
            {    min=a[i][j];
            }
        }
    }
        printf("minimum=%d",min);


    getch();
}

C PROGRAMMING -- SUM OF ALL ELEMENTS OF A MATRIX OF 3*3

#include<conio.h>
#include<stdio.h>
void main()
{       clrscr();
    int a[3][3],i,j,sum=0;
    printf("enter the matrix=\n");
    for(i=0;i<3;i++)
    {    for(j=0;j<3;j++)
        {    scanf("\t%d",&a[i][j]);
        }
        printf("\n");
    }
    for(i=0;i<3;i++)
    {    for(j=0;j<3;j++)
        {
            sum=sum+a[i][j];
        }
     }
    printf("sum of all elements=%d",sum);
    getch();
}

C PROGRAMMING --SUM OF DIAGONAL ELEMENTS IN MATRIX OF 3*3

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