Saturday 24 March 2012

Swap two string in Python using third string


-def InputString():
    Str1=raw_input("Enter your first string")
    Str2=raw_input("Enter your second string")
    print("Befor swaping")
    print'string 1 is=>',Str1
    print'string 2is=>',Str2

    Temp=Str1
    Str1=Str2
    Str2=Temp
    print("\nAfter swapping")
    print 'string 1 is=>',Str1
    print 'string 2is=>',Str2

-def main():
    InputString()

main()

Swap two string in C using third variable


/*Swap two string using third string*/
//swap one by one character using while loop



#include<stdio.h>
int main()
{
  int i=0,j=0;
  char String1[20],String2[20],Temp[20];
  puts("Enter first string");//can use "printf" also
  gets( String1 );//for read the input from user
  puts("Enter second string");
  gets( String2 );
  printf("Before swaping the strings are\n");
  puts( String1);
  puts( String2);
     while( String1 [i]!='\0')//loop till null character
      {
        Temp[j++]= String1[i++];
      } 

Wednesday 21 March 2012

Reverse of any string using C language


/*Print Reverse of a string*/

#include<stdio.h>
int main()
{
    char string[]="hi i am Nilesh";
    char RevString[50];
    int i=-1,j=0;
   
      while(str[++i]!='\0');//logic to print reverse strin
        { //we can use "strrev" function also
         while(i>=0)
           {
            rev[j++] = str[--i];
           }
       rev[j]='\0';
      }
    printf("Reverse of string is : %s",rev);
  
    return 0;

} //End of main

C program to print Pascal Triangle programme


/* Pascal triangle in c*/

#include<stdio.h>
int main()
 {
    int line,a,b,c;
    printf("Enter the no. of lines: ");
    scanf("%d",&line);
    for(a=1;a<=line;a++)
       {
           for(b=1;b<=line-a;b++)
           printf(" ");
          for(c=1;c<a;c++)
          printf( "%d" ,c);
         for(c=a;c>=1;c--)
       

Tuesday 20 March 2012

C++ Program to subtract two numbers without using minus (' - ') operator


/*logic to add two numbers in c++ without using plus operator*/
//for positive output use if condition this code will show negative output 

#include<stdio.h>
using namespace std;
int main()
 {
       int a=25,j=200,i;
      for(i=0;i<j;i++)
           {
             a--;
            }
      cout<<a<<endl;
 }
/* output will=> -175 */

C Program to subtract two numbers without using Minus (' - ') operator


/*perform subtraction of two integer without using Minus (" -- ") operator*/
//for positive output use if condition this code will show negative output


#include<stdio.h>


void main()
 {
          int a=10,b=20;
          while(b--) //start decrement b and also decrese a also
          {
            a-- ;
          }     
    printf("Sum of two number is=>%d",a); 
 } 

C++ Program to add two numbers without using plus('+') operator


/*logic to add two numbers in c++ without using plus operator*/
#include<stdio.h>
using namespace std;
int main()
 {
       int a=25,j=200,i;
      for(i=0;i<j;i++)
           {
             a++;
            }
      cout<<a<<endl;
 }

C Program to add two numbers without using plus('+') operator


/*perform addtion of two integer without using plus ("+") sign*/
#include<stdio.h>
void main()
 {
          int a=10,b=20;
          while(b--)//decrease value of b one by one and increase the value of a
          {
            a++ ;
          }    
    printf("Sum of two number is=>%d",a);
 }

Thursday 15 March 2012

C Program to find Length of Link List


/*this programme create three nodes in link list and print the lenght of 
  link list*/
#include<stdio.h>
#include<stdlib.h>

struct node
   {
    int data;
    struct node* next;
   };

struct node* CreateLinkList()
   {
    struct node* head = NULL;
    struct node* second = NULL;
    struct node* third = NULL;
    head = malloc(sizeof(struct node)); // declare 3 nodes in the heap
    second = malloc(sizeof(struct node));
    third = malloc(sizeof(struct node));
   

Programme to create a Link List in c


/*this programme create three nodes in link list then you can
  perform any further action*/
#include<stdio.h>
#include<stdlib.h>

struct node
   {
    int data;
    struct node* next;
   };

struct node* CreateLinkList()
   {
    struct node* head = NULL;
    struct node* second = NULL;
    struct node* third = NULL;
    head = malloc(sizeof(struct node)); // declare 3 nodes in the heap
    second = malloc(sizeof(struct node));
    third = malloc(sizeof(struct node));
   

C program to Calculate string length without using predefine function


/*Calculate string length without using predefine function in C language*/


#include<stdio.h>

void main()
 {
        char str[100]="I am the best",*ptr;
            ptr=str ;
         int count = 0,i;
           for(i=0;ptr[i]!='\0';i++)//can use also--while(*(ptr+count))
             {
                 count++;
              }
     
        printf("\nThe length of the string is %d.",count);

}//End of  main


:-Programming Error
carefully use ++ oprator and pointer.
loop should be run till null

:-Details of Programme
*ptr = its a pointer which is use for reference ;
count=0 count shuld initialize here with 0 because if its not then compiler assign garbage value to count and output will be diferent.


Tuesday 13 March 2012

GUI interface in python programme display window and four button


#show window and four button on that window
from Tkinter import *

root = Tk()
frame = Frame(root)
frame.pack()

bottomframe = Frame(root)
bottomframe.pack( side = BOTTOM )

redbutton = Button(frame, text="Red", fg="red",bd='4',activebackground="cyan")
redbutton.pack( side = RIGHT)

greenbutton = Button(frame, text="green",bd=4 ,fg="green",bg="violet")
greenbutton.pack( side = LEFT )

Monday 12 March 2012

Print string or other symbol without using semicolon in programme in c


//here programme to print hello world without using semicolon
//anywhere programme


#include<stdio.h>


void main()
 {
   if(printf("hello world!"))
    {
       //when it print hello world printf will return 1
       //which is true condition for if and programme 
      //do not show any error 
    }
 }//end of main

Read date of birth from user in dd-mm-yyyy format and show the day of birth in pytho


#Program to find your Day of Birth given Date of Birth
#indent and syntax problem may occur for different IDE 


-def main():
     
     d=input("Enter your date")
     m=input("Enter your month in mm format")
     y=input("Enter your year in yyyy format")
-     if( d>31 or m>12 or (y<1900 or y>=2000) ):
         print('INVALID INPUT')
     year = y-1900
     year = year/4
     year = year+y-1900
-     if m==1 or m==10:
           month = 1

Wednesday 7 March 2012

Swap two variable in c using pointer and third or temporary variable

/*Swap two variable using pointer and third variable*/
//here we use pointer to swap value of two variable
#include<stdio.h>
void main()
  {
     int a,b;
     printf("enter the value of a ");
     scanf("%d",&a);
     printf("enter the value of b");
     scanf("%d",&b);
   

File handling programme in python perform read write operation


#file handling in python
#create a new file and perform read,write operaion


str1="this is a test string" 


file=open("NewFile.txt","w")#open file in write mode
txt=file.write(str1)#this will overwrite the file
file.close()#close file after operation 


file1=open("NewFile.txt","r")#open file in read mode
txt2=file1.read()
file1.close()


print ("content of file:-")
print(txt2)

File handling programme in c read six input from user and write even and odd no. to different file



  /*even and odd no.using file handelling*/
 #include<stdio.h>
void main()
 {
    FILE *f1,*f2,*f3;
    int number,i;
    printf("contents of data file\n\n");
    f1=fopen("data","w");
    for(i=0;i<=6;i++)//enter six values 
      {
        scanf("%d",&number);//read from user
         if(number==-1)
         break;
         putw(number,f1);//write data into file 1(source,destination)
       }
 

Tuesday 6 March 2012

Python programme read three inputs from user and show whether or not they are a Pythagorean triple or right angle traingle


#Pythagoras theorem
# a*a + b*b = c*c
#Show input are pythgorean triple or not


-def PythaGorean(a,b,c):
    x=a*a+b*b
    y=c*c
    if (x==y) :
        print 'It is a right angle traingle or Pythagorean triple'
    else:
        print 'It is not a right angle traingle'


 -def ReadValues():
 

Sunday 4 March 2012

Read the radious of circle from user and gives area,diameter and circumference of circle programme in python


#read the radious of circle from user and display area,diameter and #circumference of circle
- def Radious(x):
    area=x*x*3.141
    dia=2*x
    circum=2*x*3.141
    print 'area is ',area
    print 'diameter of circle is ',dia
    print 'circumference of circle is',circum


- def main():
    rad=input("Enter the radius of the circle:-")
    Radious(rad)
main()    

Saturday 3 March 2012

Read three input from user and show largest number programme in c


/*read three inputs from user and return the largest number*/


#include<stdio.h>
void main()
{
     int a,b,c;
     printf("enter your number");
     scanf("%d%d%d",&a,&b,&c);
        if((a!=b) && (b!=c) && (a!=c))
         {
             if((a>b) && (a>c))
                {
                    printf("largest number is a->%d",a);
                }
             else
               {
                 

Read three numeric values from the user, and then print the largest of the three in python

#programme for python language
#output will be largest value


-def InputVal(x,y,z):  #logic for highest value
    print 'values are ',x,y,z
    if (x>y)and(x>z):
        print'a is largest=>',x
    elif(x<y)and(y>z):
        print 'b is largest=>',y
    else:
        print'c is largest=>',z

-def Main():
    a=input("Enter first value:")
    b=input("Enter second value:-")
    c=input("Enter third value:-")
    InputVal(a,b,c)
Main()     

Compiler for C,C++ and Python {paste your programme to see the output}