C programs Archive

Mean, Variance and SD in C

C Language moz screenshot 2 Mean, Variance and SD in C

C Programs moz screenshot 1 Mean, Variance and SD in C

  • Share/Bookmark
Send article as PDF to PDF Printer

Sum of cosines using c

C Language

C Programs

/* Write a C program to find the sum of cos(x) series */

#include
#include

void main()
{
int n,x1,i,j;
float x,sign,cosx,fact;

printf(“Enter the number of the terms in aseries\n”);
scanf(“%d”,&n);

printf(“Enter the value of x(in degrees)\n”);
scanf(“%f”,&x);

x1=x;

x=x*(3.142/180.0); /* Degrees to radians*/

cosx=1;

sign=-1;

for(i=2;i<=n;i=i+2)
{
fact=1;

for(j=1;j<=i;j++)
{
fact=fact*j;
}

cosx=cosx+(pow(x,i)/fact)*sign;
sign=sign*(-1);
}

printf(“Sum of the cosine series = %7.2f\n”,cosx);
printf(“The value of cos(%d) using library function = %f\n”,x1,cos(x));

} /*End of main() */

/*——————————————————–
Output
Enter the number of the terms in aseries
5
Enter the value of x(in degrees)
60
Sum of the cosine series = 0.50
The value of cos(60) using library function = 0.499882
——————————————————–*/

  • Share/Bookmark
Send article as PDF to PDF Printer

Bitwise operators usage in c

C Language

C Programs

/* Write a c program to multifly given number by 4 *
* using bitwise operators */

#include

void main()
{
long number, tempnum;

printf(“Enter an integer\n”);
scanf(“%ld”,&number);
tempnum = number;
number = number << 2; /*left shift by two bits*/

printf(“%ld x 4 = %ld\n”, tempnum,number);
}

/*——————————
Output
Enter an integer
15
15 x 4 = 60

RUN2
Enter an integer
262
262 x 4 = 1048
———————————*/

  • Share/Bookmark
Send article as PDF to Create PDF

Binary To Decimal Conversion in C

C Language

C Programs

Binary To Decimal Conversion in C

/* Write a C program to convert the given binary number into its equivalent decimal */

#include

void main()
{
int num, bnum, dec = 0, base = 1, rem ;

printf(“Enter the binary number(1s and 0s)\n”);
scanf(“%d”, &num); /*Enter maximum five digits or use long int*/

bnum = num;

while( num > 0)
{
rem = num % 10;
dec = dec + rem * base;
num = num / 10 ;
base = base * 2;
}

printf(“The Binary number is = %d\n”, bnum);
printf(“Its decimal equivalent is =%d\n”, dec);

} /* End of main() */

/*—————————————————
Outpput
Enter the binary number(1s and 0s)
1010
The Binary number is = 1010
Its decimal equivalent is =10
—————————————————-*/

  • Share/Bookmark
Send article as PDF to PDF Creator
  • Blogroll
  •  
    September 2010
    M T W T F S S
    « Aug    
     12345
    6789101112
    13141516171819
    20212223242526
    27282930  
  • RSS Tech WAS updates