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();
}