Saturday, September 27, 2014

Largest Palindrome of 3 Numbers

If you have any doubts, let me know
#include <stdio.h>
#include <string.h>
#include<limits.h>

main()
{
    int i=999,j=999,sum=0,r=0,y,x,sum1=0,a[3000],k=0,temp;
    for(i=999;i>100;i--)
    {
        for(j=999;j>100;j--)
        {
            sum=i*j;
            x=sum;
            while(sum>0)
            {
             sum1=sum1*10;
             sum1=sum1+sum%10;
             sum=sum/10;
            }
            if(sum1==x)
         {
             a[k]=x;
             k++;
         }
            sum1=0;
        }
    }
   
    for(i=0;i<k;i++)
    for(j=0;j<k;j++)
    {
        if(a[i]<a[j])
        {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
printf("%d",a[k-1]);

}

Tuesday, September 23, 2014

Program to print out the letters present in one word and absent in the other.

If you have any doubts, please do ask.

#include<stdio.h>
main()
{
    int i,j,flag=0;
char name1[10],name2[10];
scanf("%s",name1);
scanf("%s",name2);
for(i=0;i<strlen(name2);i++)
{
for(j=0;j<strlen(name1);j++)
{
if(name2[i]==name1[j])
flag=1;
}
if(flag==0)
{printf("%c",name2[i]);

}
else
    flag=0;
}}

Program to print out numbers separated by stars with the occurrence defined by the number printed.

This will print out something like this
1
2*2
3*3*3
4*4*4*4
and then the reverse image.
If you have any doubt, please do ask.

#include<stdio.h>
main()
{
int i=1,j=2,z=4,k;
printf("%d\n",i);
for(k=0;k<3;k++)
{
for(i=2;i<z-1;i++)
{
printf("%d*",j);
}
printf("%d\n");
j++;
z++;
}
j=4;
for(k=0;k<3;k++)
{
for(i=2;i<z-2;i++)
{
printf("%d*",j);
}
printf("%d\n");
j--;
z--;
}
printf("%d",1);
}

String reversal without string.h

This is a program to reverse a string without the string.h header. If you have any doubts, please do ask.

#include<stdio.h>
main()
{
int i,count=0,j=0;
char string[10],final[10];
scanf("%s",string);
for(i=0;string[i]!='\0';i++)
count++;
count--;
for(i=count;i>=0;i--)
{
final[j]=string[i];
j++;
}
final[j]='\0';
printf("%s",final);
}

Monday, September 15, 2014

Decrypting a message program

Feel free to use it, modify it or anything.
Try using the input

y!sr@xo#dt$pa%or^ko*vb(da&ql

You'll get the output laboratory
I've wrote in the comments what each function does. According to that, modify it to make a suitable input


#include <stdio.h>
#include <string.h>
char string[50],t;
int l,k;
main()
{
int i,j;
  
  gets(string);
   printf(" string is %s\n",string);
    l=strlen(string);
    k=l;
    letsreverse();
}
letsreverse() //function reverses a string
{
    
int i=0,j,q;
char *ptr;
ptr=string; 
q=l;
q--;
for(i=0;i<=(l/2)-1;i++)
  {
 t=*(ptr+i);
 *(ptr+i)= *(ptr+q);
 *(ptr+q)=t;
 q--;
 }
 printf("Reverse string is %s\n",string);
 wedontlikejunk();

}
wedontlikejunk()     // kills off junk
 {
    int i=0,z,c=0,x;
    char clean[20];
    for(x=0;x<k;x++)
    {
         if(string[c] >= 'a' && string[c] <= 'z')
         {
         clean[i]=string[c];
         i++;
         }
         c++;
         
    }
    clean[i]='\0';
    printf("semi string is %s\n",clean);
    for(i=0;clean[i]!='\0';i++)
    string[i]=clean[i];
    string[++i]='\0';
    letskillsomeletters();
}
letskillsomeletters()     //kills alternate letters
{
    int i=0,z;
    char final[20];
    for(z=(10%10);z<k;z++)
    {
        final[i]=string[z];
        i++;
        z++;
        
    
    }
    printf("Final string is %s\n",final);
}