Programs
Programs
int A,B,C,D,E,F,G,i;
float res1,res2,res3,res4;
printf("Enter values for A,B,C,D,E,F,G,i \n");
scanf("%d%d%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F,&G,&i);
res1=A+B*C+(D*E)+F*G;
res2=A/B*C-B+A*D/3;
res3=A+++B---A;
res4=(i++)+(++i);
printf("The value for EXP1 is %f \n",res1);
printf("The value for EXP2 is %f \n",res2);
printf("The value for EXP3 is %f \n",res3);
printf("The value for EXP4 is %f \n",res4);
} Output:
39.c Wind-chill factor is the felt air temperature on exposed skin due
to wind. The wind-chill temperature is always lower than the air
temperature, and is calculated as per the following formula:
wcf=35.74+0.6215t+ (0.42751-35.75)*016. where t is temperature
and v is wind velocity. Write a program to receive values of t and v
and calculate wind-chill factor (wcf).
Program:
main()
{
double t, v, wcf;
printf("Enter the temperature (in Fahrenheit): ");
scanf("%lf", &t);
printf("Enter the wind velocity (in miles per hour): ");
scanf("%lf", &v);
wcf = 35.74 + 0.6215 * t + (0.4275 * t - 35.75) * pow(v, 0.16);
printf("The Wind-Chill Factor (WCF) is: %.2lf\n", wcf);
}
Output:
Unit -2
CONTROL STATEMENTS:
40.C write a c program to read a number from user and
print "It is negative" , if it is negative (simple if)
main()
{
int n;
printf("Enter a number \n");
scanf("%d",&n);
if(n<0)
{
printf("It is negative \n");
}
printf("Done");
}
Output:
41.C write a c program to read a number from the user
and print "It is even", if it is even (simple if)
main()
{
int n;
printf("Enter a number \n");
scanf("%d",&n);
if(n%2==0)
{
printf("It is even \n");
}
printf("Done");
}
Output:
42.C write a c program to a read a character from the
user and print "It is a vowel", if it is a vowel(simple if)
main()
{
char ch;
printf("Enter a character \n");
scanf("%c",&ch);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
{
printf("It is vowel \n");
}
}
Output:
Output:
48.C
write a c pragram to read the float values and perform
an arithmetic operation chosen by the user (switch
case)
main()
{
char operator;
int n1,n2,res;
printf("Enter an operator\n ");
scanf("%c",&operator);
printf("Enter 2 numbers \n");
scanf("%d %d",&n1,&n2);
switch(operator)
{
case'+':
res=n1+n2;
printf("%d+%d=%d \n",n1,n2,res);
case'-':
res=n1-n2;
printf("%d-%d=%d \n",n1,n2,res);
case'*':
res=n1*n2;
printf("%d*%d=%d \n",n1,n2,res);
case'/':
res=n1/n2;
printf("%d/%d=%d \n ",n1,n2,res);
default:
printf("wrong input \n");
}
}OUTPUT:
main()
{
int year;
printf("Enter any year:");
scanf("%d",&year);
if(year%4==0)
{
printf("%d is leap year\n", year);
}
else
{
printf("%d is non leap year\n", year);
}
}
OUTPUT:
}
65.c write a c program to construct a pyramid of
numbers
Program:
main()
{
int n,j,i;
printf("Enter the value for n:");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
for (j=1;j<=i;j++)
{
printf("%d",j);
}
printf( "\n");
}
OUTPUT:
}
OUTPUT: