Archive for the ‘Lab 7’ Category

#include<stdio.h>
#include<math.h>
int main()
{
float sin=0,x,fact;
int i,j,f=-1;
printf("Enter x:");
scanf("%f",&x);
for(i=1;i<10;i+=2)
{
fact=1;
for(j=1;j<=i+2;j++)
fact=fact*j;
sin=sin+(f*pow(x,i+2))/fact;
if(f>0)
f=-1;
else
f=1;
}
printf("\n\nsinX=%f",x+sin);
return 0;
}
Advertisements
#include <stdio.h>
int main()
{
   int n, reverse = 0;
   printf("Enter a number to reverse\n");
   scanf("%d",&n);
   while (n != 0)
   {
      reverse = reverse * 10;
      reverse = reverse + n%10;
      n = n/10;
   }
   printf("Reverse of entered number is = %d\n", reverse);
   return 0;
}
#include<stdio.h>
int main()
{
int n,x,sum=0;
printf("Enter a number=");
scanf("%d",&n);
while(n>0)
{
x=n%10;
sum=sum+x;
n=n/10;
}
printf("Sum of digits of a number=%d",sum);
return 0;
}
#include<stdio.h>
int main()
{
int n,m,i,max;
printf("How many numbers(n) you going to enter:");
scanf("%d",&n);
printf("Enter the numbers:");
scanf("%d",&m);
max=m;
for(i=2;i<=n;i++)
{
scanf("%d",&m);
if(m>max)
max=m;
}
printf("The Largest Number is %d",max);
	return 0;
}

#include<stdio.h>
int main()
{
	int num,bin=0,base=1,rem;
	printf("Enter Decimal Number:");
	scanf("%d",&num);
	while(num>0)
	{
		rem=num%2;
		bin=bin+rem*base;
		num=num/2;
		base=base*10;
	}
	printf("Its Binary Equivalent is=%d\n",bin);
	return 0;
}
#include<stdio.h>
int main()
{
	int num,dec=0,base=1,rem;
	printf("Enter Binary Number(1s & 0s):");
	scanf("%d",&num);
	while(num>0)
	{
		rem=num%10;
		dec=dec+rem*base;
		num=num/10;
		base=base*2;
	}
	printf("Its Decimal Equivalent is=%d\n",dec);
	return 0;
}
#include<stdio.h>
int main()
{
	int i,n,sum=0,num;
	float avg;
	printf("How many numbers you enter");
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&num);
		sum+=num;
	}
	avg=sum/n;
	printf("avg=%f",avg);
	return 0;
}
#include<stdio.h>
int main()
{
	int a,i,b,ans=0;
printf("Enter first number:");
	    scanf("%d",&a);
    printf("Enter Second number:");
	    scanf("%d",&b);
	for(i=0;i<b;i++){
	ans+=a;
	}
printf("%d",ans);
return 0;
}