1. What is structured programming?
Give any four examples of structured
programming languages.
Structured programming is a method of writing programs by dividing them into small, clear
parts (functions/blocks).
It reduces complexity and makes programs easier to understand.
Examples: C, Pascal, Fortran, Java.
2. Write the advantages of structured programming.
- Easy to read and understand.
- Easy to debug and test.
- Easy to modify and update.
- Reusability of code (can use again).
3. Write the features of C language.
- Simple and powerful.
- Portable (runs on different computers).
- Structured programming supported.
- Supports functions and modular programming.
- Fast execution.
4. Define C language.
C is a structured, high-level programming language developed by Dennis Ritchie in 1972
at Bell Labs.
It is widely used because it is simple, portable, and powerful.
5. List the data types supported by the C language.
- int → integers (whole numbers)
- float → decimal numbers
- double → larger decimal numbers
- char → single characters
- void → no value
6. Explain the structure of the C program.
1. Header files (e.g., #include )
2. main() function – starting point of the program
3. Variable declaration
4. Statements / logic
5. Return statement
7. What is a loop? List the different looping statements used in C language.
A loop is used to repeat a set of instructions multiple times.
Loops in C:
- for loop
- while loop
- do…while loop
8. Differentiate between int and float data types in C.
- int: Stores whole numbers (e.g., 5, -10).
- float: Stores decimal numbers (e.g., 3.14, -7.5).
9. Explain the different looping statements used in C.
- for loop → used when we know the number of repetitions.
- while loop → runs as long as the condition is true.
- do…while loop → runs at least once, then checks the condition.
10. Write the format specifier of basic data types of C language.
- int → %d
- float → %f
- double → %lf
- char → %c
- string → %s
11. What is a variable in C and how is it declared?
A variable is a name given to memory to store data.
Example:
int age;
float price;
char grade;
12. Difference between while and do-while loops in C.
- while: Condition is checked first, then loop runs.
- do-while: Loop runs first, then condition is checked (runs at least once).
13. What is a function in C and why is it used?
A function is a block of code that performs a task.
It is used to make the program short, reusable, and organized.
14. What is the purpose of the return statement in C functions?
It sends a value back from a function to the main program.
15. Difference between global and local variables in C.
- Global variable: Declared outside all functions, used anywhere in the program.
- Local variable: Declared inside a function, used only inside that function.
16. What is a header file? Give any two examples.
A header file contains pre-written functions.
Examples:
- → input/output functions
- → mathematical functions
17. What is preprocessor in C?
Preprocessor gives instructions to the compiler before compiling.
Example: #include
18. Program to find sum of two numbers.
#include
int main() {
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d %d", &a;, &b;);
sum = a + b;
printf("Sum = %d", sum);
return 0;
}
19. Program to find the largest among two numbers.
#include
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a;, &b;);
if(a > b)
printf("%d is largest", a);
else
printf("%d is largest", b);
return 0;
}
20. Program to display first 10 natural numbers.
#include
int main() {
int i;
for(i=1; i<=10; i++) {
printf("%d ", i);
}
return 0;
}
21. Program to check whether the given number is odd or even.
#include
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n;);
if(n % 2 == 0)
printf("Even number");
else
printf("Odd number");
return 0;
}
22. Program to display multiplication table of a given number.
#include
int main() {
int n, i;
printf("Enter a number: ");
scanf("%d", &n;);
for(i=1; i<=10; i++) {
printf("%d x %d = %d\n", n, i, n*i);
}
return 0;
}
23. Program to calculate the factorial of a given number.
#include
int main() {
int n, i, fact = 1;
printf("Enter a number: ");
scanf("%d", &n;);
for(i=1; i<=n; i++) {
fact *= i;
}
printf("Factorial = %d", fact);
return 0;
}
24. Program to display Fibonacci series up to 10 terms.
#include
int main() {
int a=0, b=1, c, i;
printf("%d %d ", a, b);
for(i=3; i<=10; i++) {
c = a + b;
printf("%d ", c);
a = b;
b = c;
}
return 0;
}
25. Program to find the sum of digits of a number.
#include
int main() {
int n, sum=0, rem;
printf("Enter a number: ");
scanf("%d", &n;);
while(n > 0) {
rem = n % 10;
sum += rem;
n /= 10;
}
printf("Sum of digits = %d", sum);
return 0;
}
26. Program to display the series with their sum: 1, 2, 3, 4 up to 10 terms.
#include
int main() {
int i, sum = 0;
for(i=1; i<=10; i++) {
printf("%d ", i);
sum += i;
}
printf("\nSum = %d", sum);
return 0;
}
27. Program to display the series: 2, 4, 6, 8 up to 20 terms.
#include
int main() {
int i;
for(i=2; i<=40; i+=2) {
printf("%d ", i);
}
return 0;
}
28. Program to display the series: 1, 3, 5, 7 up to 15 terms.
#include
int main() {
int i;
for(i=1; i<=29; i+=2) {
printf("%d ", i);
}
return 0;
}
29. Program to display the series: 1, 4, 9, 16 up to 10 terms.
#include
int main() {
int i;
for(i=1; i<=10; i++) {
printf("%d ", i*i);
}
return 0;
}
30. Program to display the series: 1, 8, 27, 64 up to 10 terms.
#include
int main() {
int i;
for(i=1; i<=10; i++) {
printf("%d ", i*i*i);
}
return 0;
}
31. Program to display the series: 1/1, 1/2, 1/3, 1/4 up to 10 terms.
#include
int main() {
int i;
for(i=1; i<=10; i++) {
printf("1/%d ", i);
}
return 0;
}
32. Program to display the series: 1²+2²+3²+…+n².
#include
int main() {
int n, i, sum=0;
printf("Enter n: ");
scanf("%d", &n;);
for(i=1; i<=n; i++) {
sum += i*i;
}
printf("Sum = %d", sum);
return 0;
}
33. Program to display the series: 1³+2³+3³+…+n³.
#include
int main() {
int n, i, sum=0;
printf("Enter n: ");
scanf("%d", &n;);
for(i=1; i<=n; i++) {
sum += i*i*i;
}
printf("Sum = %d", sum);
return 0;
}
34. Program to display prime numbers up to n.
#include
int main() {
int n, i, j, isPrime;
printf("Enter n: ");
scanf("%d", &n;);
for(i=2; i<=n; i++) {
isPrime = 1;
for(j=2; j<=i/2; j++) {
if(i % j == 0) {
isPrime = 0;
break;
}
}
if(isPrime == 1)
printf("%d ", i);
}
return 0;
}