Programs
Programs
Programs
/*calculation freezer temperature */
#include<stdio.h>
//#define degree 3.8 fahrenheit //macro constant
void main(){
double hr,mnt,t;
double T;
printf("enter elapse time(hr,mnt) of freezer from power failure \n");
scanf("%lf%lf",&hr,&mnt);
printf("power elaqpse time is hour=%.2lf and minute =%.2lf",hr,mnt);
t=hr+(mnt/60.0);
printf("time is %.2lf",t);
T=((4*t*t)/(t+2))-20;
printf("Freezer temperature in degree celsius = %.2lf \n",T);
}
2. Q2.
3. //loical structure
4. #include <stdio.h>;
5. void main()
6. {
7. int k;
8. int m=5;
9. k=22;
10. int t=m&k;//bitwise or operator
11. printf("t=%d",t);
12. //output=4
13. }
Question.3
14. /*WAP in c to find out division of a student as per followind data
15. if avg>=60 =>1st division
16. avg>=50 =>2nd division
17. avg>=40 =>3rd division
18. other wise FAIL.*/
19. #include <stdio.h>
20. void main(){
21. double avg;
22. printf("enter average mark \n");
23. scanf("%lf",&avg);
24. if(avg>=60)
25. printf("1st\n");
26. else if(avg>=50)
27. printf("2nd\n");
28. else if(avg>=40)
29. printf("3rd\n");
30. else
31. pri }
28.printf("FAIL\n");
32.
4.
/*function recursion vs loop
Example : factorial of a number.*/
/*#include<stdio.h>
void main(){
int num;
}*/
#include<stdio.h>
void main(){
int num;
Celsius. */
#include<stdio.h>
void main(){
int far; //far=fahrenheit
double cel;//cel=celsius
printf("Enter the degree fahrenheit temperature : ");
scanf("%d",&far);
cel=((far-32)*5)/9;
printf(" degree fahrenheit to degree celsius is %.2lf \n",cel);
}
6.
/* WAP in c to find division of any student for following set of data
if avg>=60 =>1st
if avg>=50 =>2nd
if avg>=40 =>3rd
other wise fail*/
#include <stdio.h>
void main()
{
int avg;
printf("Enter avg mark\n");
scanf("%d",&avg);
if(avg>=60)
printf("you got 1st division\n");
else if(avg>=50)
printf("2nd\n");
else if(avg>=40)
printf("3rd\n");
else
printf("fail\n");
}
7.
//jump control structure
void main()
{
goto delhi;
int i=10;
while(i<5)
{delhi: //colision
printf("hello \n");
i++;
printf("i=%d\n",i);
}
}
8.
/*1.ADDITION
2.SUBTRACTION
3.MULTIPLICATION
4.DIVISION*/
void main(){
char z;
printf("A Addition\n");
printf("B subtraction\n");
printf("C Multiplication\n");
printf("D Division\n");
printf("enter your choice \n");
scanf("%c",&z);
switch(z)
{
case 'A':
case 'a':
add();
break;
case 'B':
case 'b':
sub();
break;
case 'C':
case 'c':
mul();
break;
case 'D':
case 'd':
div();
break;
default:
printf("You enter wrong choice\n");
}
void add()
{
int a,b,r;
printf("enter the values of a and b\n");
scanf("%d%d",&a,&b);
r=a+b;
printf("summation = %d",r);
}
void sub()
{
int a,b,r;
printf("enter the values of a and b\n");
scanf("%d%d",&a,&b);
r=a-b;
printf("subtraction = %d",r);
}
void mul()
{
int a,b,r;
printf("enter the values of a and b\n");
scanf("%d%d",&a,&b);
r=a*b;
printf("multiplication= %d",r);
}
void div()
{
float a,b,r;
printf("enter the values of a and b\n");
scanf("%f%f",&a,&b);
r=a/b;
printf("division = %f",r);
}
9.
//WAP in c to compute and display absolute difference of two variables x&y
usinng predefined function.
#include <stdio.h>
void main()
{
int x,y,diff,abs_diff;
printf("ntr values of x and y");
scanf("%i%i",&x,&y);
diff=x-y;
abs_diff=abs(x-y);
printf("difference=%d and absolute diff=%d\n",diff,abs_diff);
}
10.
#include <stdio.h>
void main(){
int num;
printf("Ntr a number :\n");
scanf("%d",&num);
int c=prime(num);
if(c==2||c==1)
printf("prime");
else
printf(" not prime");
}
int prime(int n)
{
int cnt=0;
for(int i=0;i>n;i++){
if(n%i==0){
cnt++;
}
}
return cnt;
11.
/*function recursion vs loop
Example : Check a number is prime or not
#include<stdio.h>
void main(){
int num;
}
*/
/*function recursion vs loop
Example : Check a number is prime or not(recursion)*/
#include<stdio.h>
void main(){
int num;
12.
/*function recursion vs loop
Example : 1 to 10.
#include<stdio.h>
void main(){
int i=1;
for(i=1;i<=10;i++){
printf("%3d",i);
}
printf("\n");
}*/
/*# include <stdio.h>
void main()
{
int static i=1;//initialize the variable only once.
if(i<=10)
{
printf("%3d",i);
i++;
main();//function recursion
}*/
/*function recursion vs loop
Example : factorial of a number.*/
#include<stdio.h>
void main(){
int num;
}
/*function recursion vs loop
Example : factorial of a number.
#include<stdio.h>
void main(){
int num;
}
return f;
}*/
13.
/*function recursion vs loop
Example : 1 to 10 */
void main(){
int i=1;
for(i=1;i<=10;i++){
printf("%3d",i);
}
printf("\n");