Showing posts with label easy. Show all posts
Showing posts with label easy. Show all posts

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]);

}

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

Tuesday, August 12, 2014

Program to copy a file

C program to copy file. If you have any doubts, let me know

#include <stdlib.h>
#include <stdio.h>
main()
{
   
FILE *source, *target;
char x, sourcef[100], targetf[100];
printf("File to copy?"); gets(sourcef);   source=fopen(sourcef, "r");  printf("Target File?"); gets(targetf);   target=fopen(targetf, "w");   while((x=fgetc(source))!=EOF) fputc(x, target);   printf("The file has been copied."); }