0% found this document useful (0 votes)
19 views11 pages

10 Year Programs Final 2010 To 2019

This document contains solutions to coding exercises in C programming. It includes programs to print tables, find maximum of two numbers, calculate powers, print factorials, swap numbers, calculate area of a rectangle, print number tables using loops, calculate circle area, find largest of three numbers, call functions, print patterns, use switch statements, generate prime numbers, print squares, print ASCII characters, compare ages, and generate odd numbers. Solutions range from basic math/logic programs to those utilizing functions, loops, and other C programming concepts.

Uploaded by

muzzamila08
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)
19 views11 pages

10 Year Programs Final 2010 To 2019

This document contains solutions to coding exercises in C programming. It includes programs to print tables, find maximum of two numbers, calculate powers, print factorials, swap numbers, calculate area of a rectangle, print number tables using loops, calculate circle area, find largest of three numbers, call functions, print patterns, use switch statements, generate prime numbers, print squares, print ASCII characters, compare ages, and generate odd numbers. Solutions range from basic math/logic programs to those utilizing functions, loops, and other C programming concepts.

Uploaded by

muzzamila08
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/ 11

An effort by Sameer Muavia, Huzaifa Abdul Aziz & Sir Arif ARMY PUBLIC COLLEGE SADAR

Write a C program to show the table of an inputted number.


Ans: ( See Book Page # 183 )
Write a function that receives two integers and returns the maximum of the two.

OutPut:

Extra Practice (With the use of Function


Write a C program to calculate the power of numbers from 1-5.

Out Put:

Write a program that prints the factorial of any inputted number. (2010)
Ans: (See Book Page #180)
Write a program that swap two inputted numbers. (2014)

#include<stdio.h>
int main() {
double first, second, temp;
printf("Enter first number: ");
scanf("%lf", &first);
printf("Enter second number: ");
scanf("%lf", &second);

// Value of first is assigned to temp


temp = first;

// Value of second is assigned to first


first = second;

// Value of temp (initial value of first) is assigned to second


second = temp;

// %.2lf displays number up to 2 decimal points


printf("\nAfter swapping, firstNumber = %.2lf\n", first);
printf("After swapping, secondNumber = %.2lf", second);
return 0;
}

Output:

Enter first number: 1.20


Enter second number: 2.45

After swapping, firstNumber = 2.45


After swapping, secondNumber = 1.20

For Extra Practice (Without using Temp Variable)

#include <stdio.h>
int main() {
double a, b;
printf("Enter a: ");
scanf("%lf", &a);
printf("Enter b: ");
scanf("%lf", &b);

// Swapping
// a = (initial_a - initial_b)
a = a - b;

// b = (initial_a - initial_b) + initial_b = initial_a


b = a + b;

// a = initial_a - (initial_a - initial_b) = initial_b


a = b - a;

// %.2lf displays number up to 2 decimal points


printf("After swapping, a = %.2lf\n", a);
printf("After swapping, b = %.2lf", b);
return 0;
}

Write a program to calculate the area of a rectangle. (Hint A= w x h)

Output:
7. Draw a flowchart that prints the table of any inputted number.
Ans: (See Book Page # 182)
8. Write a program in C language to print the number from 4-9 with their squares.
(using do while loop)

Output:
9. Write a program that reads radius of a circle and displays the circle/s area. Use this formula
area= IPx3.1459

Output:

10.Write a program that reads 3 numbers and prints the largest. (2012)

#include <stdio.h>
int main() {
double n1, n2, n3;
printf("Enter three numbers: \n");
scanf("%lf %lf %lf", &n1, &n2, &n3);

// if n1 is greater than both n2 and n3, n1 is the largest


if (n1 >= n2 && n1 >= n3)
printf("%.2lf is the largest number.", n1);

// if n2 is greater than both n1 and n3, n2 is the largest


else if (n2 >= n1 && n2 >= n3)
printf("%.2lf is the largest number.", n2);

// if both above conditions are false, n3 is the largest


else
printf("%.2lf is the largest number.", n3);

return 0;
}
OUTPUT:

Enter three numbers: -4.5


3.9
5.6
5.60 is the largest number.

11.Write a program in C to call a function that returns the cube of a given number. (2014)

OUTPUT:
12. Write a program in C which prints the following: (2011)
1
22
333
4444
55555

13. Write a program that uses switch statement.


Ans: Use any Example from book.
14. Write a C language program of character I/O which reads a character from a text file name
ABC.TXT.
Ans: Out of Reduced Syllabus.
15. Write a program to generate prime numbers up to 11 (Like 2, 3, 5, 7, 11).

OUTPUT:
16. Write a program that prints the squares of all the numbers from 1-20.

17. Write a program that prints all the ASCII characters from 0-255.

#include<stdio.h>
#include<conio.h>
int main()
{
char ascii;
int i;
for(i=0;i<=255;i++)
{
printf("%c = %d\n", i, i);
}
}
18. Write a program that inputs your age and your sisters age and then displays who is older of
the two.
Ans: Same as Question of 2019 see above.
19.. Write a program that generates the odd number from 101-150.

OutPut:

You might also like