0% found this document useful (0 votes)
6 views

Lab 03

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lab 03

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Tasks:

1. Write a program that reads in 8 numbers and prints their mean.

2. Convert Celsius to Fahrenheit units. Take the value of C as input from


the user and calculate the value of F.
Hint: F = C * (9/5) + 32

3. Write a program that will prompt the user for two integers a and b.
Then swap (interchange) the values of a and b. That means, a should
get the value of b and b should get the value of a.
Hint: You can use a temporary variable.

Solution:
#include <stdio.h>

int main()
{
int a = 5, b = 4;

printf("Before swapping:\n");
printf("\ta = %d",a);
printf("\n\tb = %d",b);

int temp;

temp = a;
a = b;
b = temp;

printf("\nAfter swapping:\n");
printf("\ta = %d",a);
printf("\n\tb = %d",b);

return 0; }
4. Write a program that will swap (interchange) the values of two
variables: a and b. That means, a should get the value of b and b
should get the value of a.
Note: You cannot use any temporary variable.
Solution:
#include<stdio.h>
#include<math.h>
int main()
{
int a = 5;
int b = 4;

printf("Before swapping:\n");
printf("\ta = %d",a);
printf("\n\tb = %d",b);

//Method 01:
//a = a+b;
//b = a-b;
//a = a-b;

//Method 02:
b = a^b;
a = b^a;
b = b^a;

printf("\nAfter swapping:\n");
printf("\ta = %d",a);
printf("\n\tb = %d",b);

return 0;
}
5. Write a C program to print the following Christmas tree:
Solution:
#include <stdio.h>

int main()
{
printf(" * \n");
printf(" *** \n");
printf(" ***** \n");
printf("*******\n");
printf(" | \n");
printf(" | \n");

return 0;
}

You might also like