write a c program that returns the position of the largest element in an array.


#include<stdio.h>
void main()
{
int array[100],j=0,n,i;
printf("enter the no of elemnts in the array\n");
scanf("%d",&n);
printf("enter the elements of the array\n");
for(i=0;i<n;i++)
scanf("%d",&array[i]);
for(i=1;i<n;i++)
{
if(array[j]<array[i])
j=i;
}
printf("\nthe position of largets element is= %d",j+1);
}

define a macro that does not make use of a bitwise XOR operator to swap the contents of two variables.


#include<stdio.h>
#define swap(a,b) {a=a+b;b=a-b;a=a-b;printf("x=%d y=%d",a,b);}
void main()
{
    int x,y;
    printf("enter the two numbers\n");
    scanf("%d%d",&x,&y);
    printf("the numbers before swapping are\n x=%d y=%d\n",x,y);
    printf("the numbers after swapping are\n");
    swap(x,y);
}

NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last.

output image


wap to find whether a number entered by user is automorphic or not.

if u want to know what is automorphic number then go to-http://en.wikipedia.org/wiki/Automorphic_number

#include<stdio.h>
void main()
{
    long int count=1,n,a,m,div=1,i;
    printf("enter the number \n");
    scanf("%d",&n);
    a=n;
    while((n/10)!=0)
    {
    n=n/10;
    count++;
    }
    m=a*a;
    for(i=1;i<=count;i++)
        div=div*10;
    if(m%div==a)

    printf("\nit is an automorphic number");
        else
    printf("\nit is not an automorphic number");


}

NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last.


output window (click to enlarge).



define a macro to find the factors of a number.

#include<stdio.h>
#define factor(num) {do{if(num%a==0){num=(num/a);printf("\n%d",a);}else a++;}while(num!=1);}
void main()
{
    int a=2,num;
    printf("enter the number\n");
    scanf("%d",&num);
    printf("%d",1);
    factor(num);
}


NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last.


output image  (click to enlarge).


wap to find the lcm of three numbers.


#include<stdio.h>
void main()
{

    int num,num2,num3,a=2,lcm=1;
    printf("enter the three numbers\n");
    scanf("%d%d%d",&num,&num2,&num3);
    while((num!=1)||(num2!=1)||(num3!=1))
        if((num%a==0)||(num2%a==0)||(num3%a==0))
        {
        if(num%a==0)num=num/a;
    if(num2%a==0)num2=num2/a;
    if(num3%a==0)num3=num3/a;
    lcm=lcm*a;
        }
        else
            a++;
        printf("\nthe lcm of the three numbers is  %d",lcm);
}


NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last.


here is the proof of the code running..........(click on the image to enlarge)




wap to find the factors of a number.


#include<stdio.h>
void main()
{
    int a=2,num;
    printf("enter the number");
    scanf("%d",&num);
    printf("the factors of the number are\n%d",1);
    do
    {
        if(num%a==0)
        {
            num=(num/a);
        printf("\n%d",a);
        }
        else
            a++;
    }while(num!=1);

}

NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last.

Implemet Stack in python

  class Stack : def __init__ ( self , data ): self . stack = [] if ( data ): self . stack . append ( da...