Professional Documents
Culture Documents
National University: of Computer & Emerging Sciences Peshawar Campus
National University: of Computer & Emerging Sciences Peshawar Campus
National University: of Computer & Emerging Sciences Peshawar Campus
NOTE: Attempt all questions. Please try your best to solve the questions in the order they are given.
Write a program to print all Armstrong's numbers from 1 to 10000. A number is an Armstrong’s number if it
is equal to the sum of its own digits with each digit raised to the power of the number of digits. For example
371 and 1634 are Armstrong’s numbers as 371 = 33 + 73 + 13 and 1634 = 14 + 64 + 34 + 44.
a. A function num_digits with an integer parameter n that returns the number of digits in n.
b. A function power with two positive integer parameters x and y that returns the value of x
raised to power y.
c. A function armstrong with a positive integer parameter n that returns 1 if n is an Armstrong’s
number, else 0.
d. A function print_armstrong that prints all Armstrong's numbers from 1 to 10000.
Question 2 (CLO 1): Write the output of the following program: Marks: 10
#include <stdio.h>
void towers(int,char,char,char);
int main()
{
towers(3,'A','C','B');
return 0;
}
if(n == 1)
printf("\t\t\t\tStep %3d: Move from %c to %c\n", ++step, source, dest);
else
{
towers(n - 1, source, auxiliary, dest);
printf("\t\t\t\tStep %3d: Move from %c to %c\n", ++step, source, dest);
towers(n - 1, auxiliary, dest, source);
}
return ;
Consider the following program that has to print the number of vowels and the number of consonants in the
given array, but the program may contain syntactical or logical errors.
Rewrite the given program after removing syntactical and logical errors if any. Write the type of error
(syntactical or logical) in the form of a comment in front of each line if that line contains any error.
#include <stdio.h>
#define a 'a';
int main()
{
int vowel_count = 1;
int consonant_count = 1;
switch(arr)
{
case a:
case 'e':
case 'i':
case 'o':
case 'u':
vowel_count++;
break;
default:
break;
consonant_count++;
}
------------------------------------------------------Best of luck--------------------------------------------------------