C Assignment Day 1&2
C Assignment Day 1&2
1. The distance between two cities (in km.) is input through the keyboard.
Write a program to convert and print this distance in meters, feet, inches
and centimeters.
2. Ramesh’s basic salary is input through the keyboard. His dearness allowance
is 40% of basic salary, and house rent allowance is 20% of basic salary.
Write a program to calculate his gross salary
4. 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.4275t
- 35.75 ) * v 0.16 where t is the temperature and v is the wind velocity.
Write a program to receive values of t and v and calculate wind chill factor (wcf).
5. Two numbers are input through the keyboard into two locations C and D. Write
a program to interchange the contents of C and D.
8. Given the length and breadth of a rectangle, write a program to find whether
the area of the rectangle is greater than its perimeter. For example, the
area of the rectangle with length = 5 and breadth = 4 is greater than its
perimeter.
Day 2:
2. Write a program to print out all Armstrong numbers between 1 and 500.
If sum of cubes of each digit of the number is equal to the number itself, then
the number is called an Armstrong number. For example, 153 = ( 1 * 1 * 1 ) + ( 5 *
5 * 5 ) + ( 3 * 3 * 3 ).
#include <stdio.h>
int main() {
int num,rem,temp,i,sum = 0;
float cube;
printf("The armstrong number between 1 and 500 are :");
for(i=1;i<=500;i++)
{
sum=0;
temp=i;
num=i;
while(num>0){
rem=num % 10;
cube= rem*rem*rem;
sum=sum+cube;
num = num/10;
}
if(sum==temp)
{
printf("%d\n",temp);
}
}
return 0;
}
Output-
The armstrong number between 1 and 500 are :1
153
370
371
407
3. Write a program to enter numbers till the user wants. At the end it should
display the count of positive, negative and zeros entered.
#include <stdio.h>
int main() {
int n,arr[30];
int i,count=0,c=0,C=0;
printf("Enter number to be entered:");
scanf("%d",&n);
printf("Enter the numbers :");
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
if(arr[i]>0){
count++;
}
else
if(arr[i]<0){
c++;
}
else
{
C++;
}
}
printf("Positive numbers are : %d\n",count);
printf("Negative numbers are : %d\n",c);
printf("Zero entered is : %d\n",C);
return 0;
}
Output-
Enter number to be entered:5
Enter the numbers :70
32
-98
43
0
Positive numbers are : 3
Negative numbers are : 1
Zero entered is : 1
4. Write a program to print all prime numbers from 1 to 300. (Hint: Use nested
loops, break and continue)