0% found this document useful (0 votes)
31 views3 pages

04 While

This document provides problems regarding while loops and other mathematical and digit extraction problems in C programming. It includes 14 problems covering topics like printing numbers using while loops, finding GCD and LCM, digit extraction, number systems conversions, and determining if a number is prime, palindrome or Armstrong number.

Uploaded by

sahmed2330154
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)
31 views3 pages

04 While

This document provides problems regarding while loops and other mathematical and digit extraction problems in C programming. It includes 14 problems covering topics like printing numbers using while loops, finding GCD and LCM, digit extraction, number systems conversions, and determining if a number is prime, palindrome or Armstrong number.

Uploaded by

sahmed2330154
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

CSE 1110: Introduction to Computer Systems

Problem Set for C programming


Problems regarding while loop
From for to while
1. Write a C program that will print all integers between 1 and n. You must use while loop.
Sample input Sample output
5 12345
8 12345678
2. Write a C program that will print the first n odd numbers. You must use while loop.
Sample input Sample output
5 13579
8 1 3 5 7 9 11 13 15
3. Write a C program that will calculate the sum of the following series up to its nth term:

Sample input Sample output


5 387
8 5379
4. Write a C program that will take as input an integer n, and find out if it is prime or not.
Sample input Sample output
25 Not prime
29 Prime
Mathematical problems
1. Write a C program that will take as input two integers, and calculate their GCD.
Sample input Sample output
12 57 3
65 35 5
2. Write a C program that will take as input two integers, and calculate their LCM.
Sample input Sample output
24 60 120
25 75 75
Digit extraction
1. Write a C program to calculate the sum of the digits of an input integer.
Sample input Sample output
65237 23
2. Write a C program to find out the reverse of an input integer.
Sample input Sample output
65237 73256
3. Write a C program to find out if an input integer is palindrome or not.
Sample input Sample output
65237 Not palindrome
74947 Palindrome
4. Write a C program to find the frequency of each digit in an input integer.
Sample input Sample output
65526374 2 => 1
3 => 1
4 => 1
5 => 2
6 => 2
7 => 1
5. Write a C program to swap the first and the last digits of an input integer.
Sample input Sample output
65237 75236
6. Write a C program to find out if an input integer is an Armstrong number or not. An
Armstrong number is one for which the sum of each digit to the power of the number of
digits is the same as the number itself.
Sample input Sample output Explanation
371 Armstrong
1634 Armstrong
503 Not Armstrong
Number systems
1. Write a C program to convert an input integer to binary.
Sample input Sample output
27 11011
68 1000100
2. Write a C program to convert an input integer to octal.
Sample input Sample output
27 33
68 104
3. Write a C program to convert a binary integer to decimal.
Sample input Sample output
11011 27
1000100 68
4. Write a C program to convert an octal integer to decimal.
Sample input Sample output
33 27
104 68

You might also like