Saturday, April 13, 2013

String: Copy one string to another string without liberty function

Copy one string to another string without liberty function 



#include<stdio.h>
main()
{
    char string1[80],string2[80];
    int i;
    printf("Enter the line: ");
    printf("\t");
    //gets(string2);
    scanf("%s",string2);
    for(i=0;string2[i]!='\0';i++)
    string1[i]=string2[i];
    //string1[i]='\0';
    printf("\n\%s\n",string1);
    printf("\nNumber of charcter is: %d\n",i);
}

Decimal To Binary Conversion

Decimal To Binary Conversion in C 



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

    long int decimalNumber,remainder,quotient;
    int binaryNumber[100],i=1,j;
    printf("Enter any decimal number: ");
    scanf("%ld",&decimalNumber);
    quotient = decimalNumber;
    while(quotient!=0)
    {
         binaryNumber[i++]= quotient % 2;
         quotient = quotient / 2;
    }
    printf("\nEquivalent binary value of decimal number %d: ",decimalNumber);
    for(j=i-1;j>0;j--)
    printf("%d",binaryNumber[j]);
    printf("\n");
}

Pattern: 1 23 456 78910

Write a program to print 1
                                    23
                                    456
                                    78910




#include<stdio.h>
#include<conio.h>
int main()
{
    int a,b,c=1;
    for(a=1;a<=4;a++)
    {
        for(b=1;b<=a;b++)
        {
            printf("%d",c);
            c++;
        }
        printf("\n");
    }
}

Pattern: 1 22 333 4444 55555

Write a program to print 1 
                                                                           22
                                   333
                                   4444
                                   55555 



#include<stdio.h>
#include<conio.h>
void main()
{
    int a,b;
    for(a=1;a<=5;a++)
    {
        for(b=1;b<=a;b++)
        {
            printf("%d",a);
        }
        printf("\n");
    }
}

Srting Array: Write a programe to find vowels,consonants,words,letters,alphabet form a given string array

 Find vowels,consonants,words,letters,alphabet form a given string array 



#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
 char a[100];
 int b,d,e,i,l,p;
 b=d=e=0;
 printf("\nEnter the string : ");
 gets(a);
 l=strlen(a);
 for(i=0;a[i]!='\0';i++)
  {
   if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u'||a[i]=='A'||a[i]=='E'||a[i]=='I'||a[i]=='O'||a[i]=='U')
   d++;
      if (a[i]==' ')
   e++;
   }
   p=l-(d+e);
   b=l-e;
   printf("\n\t No of vowels=%d \n",d);
   printf("\n\t No of consonants=%d \n ",p);
   printf("\n\t No of words=%d \n ",e+1);
   printf("\n\t No of total letters=%d \n",l);
   printf("\n\t No of alphabet=%d \n",b);
}

Serise Circuit: Sum of total registance of an Electric Circuit

Sum of total registance of an Electric Circuit
Ri=R1+R2+R3+............+R



#include<stdio.h>
#include<conio.h>
main()
{
    float sum=0.0,r;
    int i,j,n;
    printf("\t\tIts's a programe to find the total vale of serise circuit\n");
    printf("\n\nHow many registors you use in serise: ");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=1;j++)
        printf("\n\tEnter the valuse of %d registor:",i);
        scanf("%f",&r);
        sum+=r;
    }
    printf("\nThe total registance of the serise circuit is: %0.3f\n ",sum);
}

Power: Sum of total Power in Circuit.. P=P1+P2+P3+......+Pn

Power: Sum of total Power in Circuit.. P=P1+P2+P3+......+Pn
Where P=(I*I)R 



#include<stdio.h>
main()
{
    int i,n,j;
    float R,I,P=0.0,sum=0.0;
    printf("Enter the number which u want to use serise:\n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=1;j++)
        printf("Enter the value of current:\n");
         scanf("%f",&I);
        printf("Enter the value of resestence:\n");
        scanf("%f",&R);
        P=(I*I)*R;
    }
    sum+=P;
    printf("The totel Power is:%f",sum);
}
 




Array: Dimentional Arry: Multiplication Table

Multiplication Table 



#include<stdio.h>
#include<conio.h>
#define ROWS 5
#define COLUMS 5
main()
{
    int row,colum,product[ROWS][COLUMS];
    int i,j;
    printf("Multiplication Table\n\n");
    printf(" ");
    for(j=1;j<=COLUMS;j++)
    printf("%4d",j);
    printf("\n");
    printf("   ----------------------\n");
    for(i=0;i<ROWS;i++)
    {
        row=i+1;
        printf("%2d |",row);
        for(j=1;j<=COLUMS;j++)
        {
            colum=j;
            product[i][j]=row*colum;
            printf("%4d",product[i][j]);
            //printf("----------------------\n");
        }
        printf("\n");
    }
}

String Array: Check palindrom word or Not from given String

Check palindrom word or Not from given String 



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

#include<string.h>
int main()
{
char word[80], reverse_word[80];
int i, j, len;
scanf("%s", word);
len = strlen(word);
for(i = 0, j = len - 1; i < len; i++, j--)
{
reverse_word[i] = word[j];
}
reverse_word[i] = '\0';
printf("%s\n", reverse_word);
if (0 == strcmp(word, reverse_word))
{
printf("YES %s is a palindrome.\n", word);
}
else
{
printf("NO %s is not a palindrome.\n", word);
}
return 0;
}

Check Palindorm number or Not In c

Palindorm Number 



#include<stdio.h>
#include<conio.h>
main()
{
int n,rev=0,temp,a=10;
printf("Enter any number: ");
scanf("%d",&n);
temp=n;
while(temp!=0)
{
rev=rev*a;
rev=rev+temp%a;
temp=temp/a;
}
if(n==rev)
{
printf("%d is a palindrome number",n);
}
else
printf("%d is not a palindrome number",n);
return 0;
}

prime numbers between 1 to n in C program

prime numbers between 1 to n 





#include<stdio.h>


int main()
{

    int num,i,count,n;
    printf("Enter max range: ");
    scanf("%d",&n);

    for(num = 1;num<=n;num++)
{

         count = 0;

         for(i=2;i<=num/2;i++)
{
             if(num%i==0){
                 count++;
                 break;
             }
        }
        
         if(count==0 && num!= 1)
             printf("%d ",num);
    }
  
   return 0;
}
 

Check Prime Number or Not in C

Check Prime Number or Not 



#include<stdio.h>
#include<conio.h>
main()
{
 int pm,i,flag=1;
 printf("enter the number\n");
 scanf("%d",&pm);
 for(i=2;i<pm;i++)
 {
  if((pm % i)==0)
        
         {
          printf("Then given number is not prime\n");
          flag=0;
          break;
         }
 }
  if (flag==1)
     printf("The given number is prime\n");
}