Friday, April 12, 2013

Sum of Current supply I=I1+I2+I3+.....................+In

Sum of Current supply I=I1+I2+I3+.....................+In 

 

#include<stdio.h>
#include<conio.h>
main()
{
    int n,i,j,I=0,v,r,sum=0;
    printf("\t*Its's a programe to find the total current supply of a circuit bord*\n");
    printf("\n\nHow many curent supply point you use in serise bord: ");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=1;j++)
        {
            printf("\nEnter the value of %d voltage: ",i);
            scanf("%d",&v);
            printf("\nEnter the valo of %d registance: ",i);
            scanf("%d",&r);
            I=v/r;
        }
        //printf("\n\tEnter the valuse of %d registor:",i);
        //scanf("%d",&j);
        sum+=I;
    }
    printf("\n\tThe total current supply of circuit board is: %d\n ",sum);
}

Parallel Resistance (1/Ri=1/R1+1/R2+1/R3+.......+1/Rn)

Parallel Resistance


#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
    int i,j,n;
    float a=1.0,b,c=0.0,sum=0.0,temp=0.0;
    printf("\tIt's a programe of 1/Ri=1/R1+1/R2+1/R3+.......+1/Rn\n");
    printf("\n\nEnter the number of registors in parallel: ");
    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",&b);
        c=a/b;
        sum+=c;
    }
    temp=a/sum;
    printf("\n\nThe total registance(1/Ri) of parallel is: %0.3f\n ",sum);
    printf("\nThe total registance(Ri) of parallel is: %0.3f\n\n ",temp);

}

Voltage,Registance,Current flow

V=IR
I=V/R
R=V/I

#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
    float v,i,r,sum=0.0;
    char ch;
    printf("\t\t\tWell Come to V=IR programe:\n");
    printf("\nPlease press a for V, b for I and c  for R : ");
    scanf("%c",&ch);
    switch (ch)
    {
        case 'a':
        printf("\n\tEnter the value of current: ");
        scanf("%f",&i);
        printf("\n\tEnthe the value of rigistance: ");
        scanf("%f",&r);
        sum=i*r;
        printf("\nThe result is V= %0.3f\n",sum);
        break;
        case 'b':
        printf("\n\tEnthe the value of voltage: ");
        scanf("%f",&v);
        printf("\n\tEnthe the value of rigistance: ");
        scanf("%f",&r);
        sum=v/r;
        printf("\nThe result is I= %0.3f\n",sum);
        break;
        case 'c':
        printf("\n\tEnthe the value of voltage: ");
        scanf("%f",&v);
        printf("\n\tEnther the value of current: ");
        scanf("%f",&i);
        sum=v/i;
        printf("\nThe result is R= %0.3f\n",sum);
        break;
    }


}

Array: Height & lowest value from an Array

Find the Height & Lowest value from a give array 



#include<stdio.h>
    int main ()
    {
      int i,n;
      int a[100];
    printf("Enter the array size: ");
    scanf("%d",&n);
     for(i = 0; i < n; i++)
    {
       printf("\n Enter %d value: ",i+1);
       scanf("\n %d", &a[i]);
       }
      int max = a[0];
      int min = a[0];

      for (i = 0; i <n; i++)
        {
          if (a[i] > max)
            {
              max = a[i];
            }
          else if (a[i] < min)
            {
              min = a[i];
            }
        }
      printf ("Maximum element in an array : %d\n", max);
      printf ("Minimum element in an array : %d\n", min);

      return 0;
    }
 

Find ASCII value

ASCII Code 



#include <stdio.h>
#include <conio.h>
main()
{
int a=1;
while(a<=255)
{
printf("%d=%c\n,",a,a );
a++;
}
return 0;
}

permutation

permutation 



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

    }
    return 0;
}

Find the biggest number without if condition

Biggest number among 3 number 



#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,big;
printf("Enter the 1st number: ");
scanf("%d",&a);
printf("Enter the 2nd Number: ");
scanf("%d",&b);
printf("Enter the 3rd Number: ");
scanf("%d",&c);
big=(a>b&&a>c?a:b>c?b:c);
printf("\nThe biggest number is: %d",big);
return 0;
}

Created Pyramid

Created a Pyramid 



 #include<stdio.h>
#include<conio.h>
main()
{
    int i,j,k, n;
    printf("Enter number of rows for pyramid: ");
    scanf("%d",&n);
    //printf("\n");
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=(n-i);j++)
            printf("+");
        for(j=1;j<=i;j++)
            printf("*");
        for(k=1;k<i;k++)
            printf("*");
        printf("\n");
    }
    printf("\n\n");

    return 0;
}

Sum of EVEN number from given range

Sum of EVEN Numbers 



#include <stdio.h>
void main()
{
    int index, begno, endno, sum = 0;
    printf("Program for sum of even numbers in the given range\n");
    printf("Enter Beg. No.: ");
    scanf("%d", &begno);
    printf("Enter End. No.: ");
    scanf("%d", &endno);
    index = begno;
    if( (begno % 2) == 1) // If it ODD, then make it EVEN
        index = begno + 1;
    for(; index <= endno; index += 2)
    {
        sum = sum + index;
    }
    printf("The sum of even numbers between %d and %d is: %d", begno, endno, sum);
}

Sum of ODD Numbers form given Range

Sum of ODD number from Given Range 



#include <stdio.h>
void main()
{
    int index, begno, endno, sum = 0;
    printf("Program for sum of odd numbers in the given range");
    printf("Enter Beg. No.: ");
    scanf("%d", &begno);
    printf("Enter End. No.: ");
    scanf("%d", &endno);
    index = begno;
    if( (begno % 2) == 0)
        index = begno + 1;
    for(; index <= endno; index += 2)
    {
        sum = sum + index;
    }
    printf("The sum of odd numbers between %d and %d is: %d", begno, endno, sum);
}

Fibonacci sequence whose values do not exceed four million

Excercise in C: Fibonacci Sequence

Problem:

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

 

output is 4613732
------------------------------- 



#include<stdio.h>
#include<conio.h>
int main()
{
long total=0,one=1,two=2,three=0;
while (two <= 4000000)
{
three = one + two;
if (two % 2 == 0)
total += two;
one = two;
two = three;
}
printf("%d",total);
return 0;
}

Largest Prime Factors

Prime Factors in C 

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

Output is 6857
--------------------------------

 

#include
int main()
{
long long count=2,b=2,x=600851475143,c=0,prime=0;
while(count<x)
{
if(x%count==0)
{c=count;
b=2
while(b<=c)
{if(c%b!=0)
{b++;}
else
{b+=c;}
if(b==c)
{prime=c;
printf("prime: %d\n",prime);
}
count++;}
else
count++;
}
printf("The largest prime factor of %d is: \n%d\n",x,prime);
return 0;
}

Smallest Positive Number

Smallest Positive Number

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?