In this article, we are gonna to discuss questions to expert using variables and data types
Here you can find the tutorial 07 questions pdf to practice variables and data types concepts ;
https://www.thecn.com/uploads/645f3d/645f3d43df99ceb29000fe42/s3/NjMzNWEyM2JhOGE1NWUxZjk5NWIzNTcxLzY0NWYzZDQwMjE2NjkzNjI4MjBjOTliMi9JQ1QxNDAyX1R1dG9yaWFsXzA3LnBkZg/847168f361ab90c0e145fbc0623903b6.pdf
Before doing the tutorial 7, watch this video to get an idea about The Variables .
#include <stdio.h>
int main (){
int x ,y , z;
x = 87;
y = 15;
z = x - y;
printf("The difference between %d and %d is %d", x, y, z);
return 0;
}
2. Identify the syntactic errors in the following program. Then type in and run the corrected program to ensure you have correctly identified all the mistakes.
#include
printf ("The answer is %i\n" sum);
return 0;
}
Answer
#include <stdio.h>
int main (void)
{
int sum;
/* COMPUTE RESULTS */
sum = 25 + 37 - 19;
/*display results;*/
printf("The result is %i\n", sum);
return 0;
}
3. What output might you expect from the following program?
#include <stdio.h>
answer = 100;
result = answer - 10;
printf ("The result is %i\n", result + 5);
return 0;
}
Answer
The result is 95
4. Which of the following are invalid variable names? Why?
Int char 6_05
Calloc Xx alpha_beta_routine
floating _1312 z
ReInitialize _ A$
Answer
Int char 6_05 - Invalid Because space is not a valid character
Calloc Xx alpha_beta_routine -Invalid Because space is not a valid character
floating _1312 z -Invalid Because space is not a valid character
ReInitialize _ A$- Invalid Because $ is not a valid character in variable name
5. Which of the following are invalid constants? Why?
123.456 0x10.5 0X0G1
0001 0xFFFF 123L
0Xab05 0L -597.25
123.5e2 .0001 +12
98.6F 98.7U 17777s
0996 -12E-12 07777
1234uL 1.2Fe-7 15,000
1.234L 197u 100U
0XABCDEFL 0xabcu +123
Answer
0x10.5: Invalid, because the 'x' is not a valid hexadecimal digit.
0X0G1: Invalid, because 'G' is not a valid hexadecimal digit
17777s: Invalid, 's' is not a valid suffix for a numeric constant
17777s: Invalid, 's' is not a valid suffix for a numeric constant
1.2Fe-7: Invalid, 'Fe' is not a valid part of a floating-point constant.
15,000: Invalid, commas are not allowed in numeric constants
6.What output would you expect from the following program?
#include <stdio.h>
}
Answer
d=d
7. Convert given value in Meter to centimeter.
Answer
#include <stdio.h>
int main()
{
int x,y;
printf("\nEnter the meter value : ");
scanf("%i", &x);
y= x*100;
printf("The centimeter value is %i cm", y);
return 0;
}
8. Calculate the volume of a cylinder. PI * r2h
Answer
#include <stdio.h>
#define PI 3.142
int main()
{
float r, h;
printf("\nEnter the radius : ");
scanf("%f", &r);
printf("\nEnter the height : ");
scanf("%f", &h);
printf("\nVolume is %f", PI*r*r*h);
return 0;
}
9. Calculate average marks of 4 subjects which, entered separately.
Answer
#include <stdio.h>
int main(){
float mark1, mark2, mark3, mark4, total, average;
printf("\nEnter the subject 1 mark : ");
scanf("%f", &mark1);
printf("\nEnter the subject 2 mark : ");
scanf("%f", &mark2);
printf("\nEnter the subject 3 mark : ");
scanf("%f", &mark3);
printf("\nEnter the subject 4 mark : ");
scanf("%f", &mark4);
total = mark1+mark2+mark3+mark4;
average = total/4;
printf("\nAverage is %.2f", average);
return 0;
}
10. Convert the given temperature in Celsius to Fahrenheit. T(°F) = T(°C) × 1.8 + 32
Answer
#include <stdio.h>
int main(){
float Tc, Tf;
printf("\nEnter temparature in celsius : ");
scanf("%f",&Tc);
Tf = (Tc*1.8)+32;
printf("\nTemperature in fahrenheit is %.2f", Tf);
return 0;
}
Answer
#include <stdio.h>
int main(){
float x, y;
x = 5.23;
y = 3.5*x +5;
printf("\nValue of y is %.2f", y);
return 0;
}
#include <stdio.h>
int main(){
float a, b;
a= 10.50;
b= 5*a;
printf("\nCostprice of 5 items is %.2f", b);
return 0;
}
#include <stdio.h>
int main(){
char n[10];
float h, w, bmi;
printf("\nEnter the name : ");
scanf("%s", n);
printf(" \nEnter the height : ");
scanf("%f", &h);
printf(" \nEnter the weight : ");
scanf("%f", &w);
bmi = w/(h*h);
printf("\n%s's BMI is %.2fKg", n, bmi);
return 0;
}
14.Write a program that converts inches to centimeters. For example, if the user enters 16.9 for a Length in inches, the output would be 42.926cm. (Hint: 1 inch = 2.54 centimeters.)
Answer
#include <stdio.h>
int main(){
float i, c;
printf("\nEnter the value in inches : ");
scanf("%f", &i);
c = i*2.54;
printf("\nThe centimeter value is %.2fcm", c);
return 0;
}
15. The figure gives a rough sketch of a running track. It includes a rectangular shape and two semi-circles. The length of the rectangular part is 67m and breadth is 21m. Calculate the distance of the running track
Answer
#include <stdio.h>
int main(){
const float pi = 3.142;
int l;
float r, d;
l = 67;
r = 21/2;
d = (2*l)+(2*pi*r);
printf("\nThe distance if the running track is %.2fm", d);
return 0;
}
BMS Group Members :
· 01)M.G. Janeesha Sinty
Registration number-ICT/21/22/043
CN- JG1539
· 02)R.D. Malsha Nethmini Premathilaka
Registration number- ICT/21/22/085
CN- MN1032
· 03)S. Basuru Rupasinghe
Registration number- ICT/21/22/132
CN- SR1777