Professional Documents
Culture Documents
c) It is assumed that arithmetic operators (*) are already present when they are not
f) no error
h) (*) is repeated
5b)
#include<stdio.h>
int main()
{
float km, m, cm, f, in;
printf("Enter distance in kilometers: ");
scanf("%f", &km);
/* calculate the conversion */
m = km * 1000;
cm = km * 1000 * 100;
f = km * 3280.84;
in = km * 39370.08;
printf("The distance in Feet: %f\n", f);
printf("The distance in Inches: %f\n", in);
printf("The distance in Meters: %f\n", m);
printf("The distance in Centimeters: %f\n", cm);
return (0);
}
5c)
#include<stdio.h>
#include<conio.h>
void main()
{
int spanish, math, english, science, art, total;
float percentage;
printf("Enter the marks of Spanish: ");
scanf("%d", &spanish);
printf("Enter the marks of Math: ");
scanf("%d", &math);
printf("Enter the marks of English: ");
scanf("%d", &english);
printf("Enter the marks of Science: ");
scanf("%d", &science);
printf("Enter the marks of Art: ");
scanf("%d", &art);
total = spanish+math+english+science+art;
percentage = total/5;
printf("\nAggregate marks: %d", total);
printf("\nPercentage marks: %0.2f %%", percentage);
getch();
}
d)
#include<Stdio.h>
int main()
{
int C, D, T;
printf("Enter the value of C: ");
scanf("%d", &C);
printf("Enter the value of D: ");
scanf("%d", &D);
C = C+D; //c=30, d=20
D = C-D; //d=10, c=30
C = C-D; //c=20
printf("\n The value of C: %d", C);
printf("\n The value of D: %d", D);
getch();
}
e)
#include<stdio.h>
int main()
int d1,d2,d3,d4,d5,sum;
long num;
scanf("%ld",&num);
d1=(num%10);
d2=(num%100)/10;
d3=(num%1000)/100;
d4=(num%10000)/1000;
d5=(num/1000);
sum=d1+d2+d3+d4+d5;
return 0;
f)
#include<stdio.h>
int main()
{
int number=0, n;
printf("Enter a number: ");
scanf("%d", &n);
while(n!=0)
{
number = number * 10;
number = n % 10 + number;
n = n/10;
}
printf("%d", number);
return 0;
}
g)
#include<stdio.h>
#include<conio.h>
int main()
{
int num, sum, i, number, count=0, n=1;
printf("Enter N Digit's Number: ");
scanf("%d", &num);
number = num;
//get the counter till then we have to run the loop
while(number!=0)
{
number = number/10;
count = count + 1;
}
for(i=1;i<count;i++)
{
n = n * 10; //n = 10
n = n + 1; //n = 11
}
sum = num + n;
printf("Output: %d", sum);
}
Rafid Khan
1720027