0% found this document useful (0 votes)
14 views2 pages

C Programming QnA

The document contains a series of C programming questions and answers covering data types, algorithms, and basic programming concepts. It includes example programs for calculating GCD, average of numbers in an array, and a menu-driven calculator. Additionally, it discusses string handling, arrays, pointers, and the generations of computers.

Uploaded by

raj.kp2211
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)
14 views2 pages

C Programming QnA

The document contains a series of C programming questions and answers covering data types, algorithms, and basic programming concepts. It includes example programs for calculating GCD, average of numbers in an array, and a menu-driven calculator. Additionally, it discusses string handling, arrays, pointers, and the generations of computers.

Uploaded by

raj.kp2211
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/ 2

C Programming Questions and Answers

Answer 1: 2x5=10

1. Data types define the type of data a variable can hold (e.g., int, float, char).
2. i++ returns the original value before incrementing, whereas ++i increments first.
3. Variable names must start with a letter/underscore, can contain letters/digits, and are
case-sensitive.
4. (9AE.BC)16 to Binary: 1001 1010 1110 .1011 1100
5. Algorithm: A step-by-step procedure to solve a problem.
6. Base values: Octal = 8, Hexadecimal = 16.
7. Goto statement leads to difficult-to-maintain "spaghetti code."
8. Break terminates a loop; Continue skips the current iteration.

Answer 2: 5x2=10

C program to determine GCD of two integers:


#include <stdio.h>
int gcd(int a, int b) {
while (b != 0) { int temp = b; b = a % b; a = temp; }
return a;
}
int main() {
int num1, num2;
printf("Enter two integers: ");
scanf("%d %d", &num1, &num2);
printf("G.C.D of %d and %d is %d\n", num1, num2, gcd(num1, num2));
return 0;
}

Generations of computers:
1st: Vacuum tubes, 2nd: Transistors, 3rd: ICs, 4th: Microprocessors, 5th: AI & Quantum.

C program to find average of numbers in an array, and pattern printing using loops also included.

Answer 3: 10x2=20

String handling functions (Concatenation & Comparison) without standard header files.
Function: A reusable code block. Difference: Formal args are declared in function, Actual args are
passed.

C Program for Menu-driven Calculator using switch-case:


#include <stdio.h>
int main() {
int choice; float a, b;
do {
printf("\n1.Add 2.Subtract 3.Multiply 4.Divide 5.Exit\nEnter choice: ");
scanf("%d", &choice);
if (choice == 5) break;
printf("Enter two numbers: "); scanf("%f %f", &a, &b);
switch (choice) { case 1: printf("Result: %.2f\n", a+b); break; case 2: printf("Result: %.2f\n",
a-b); break; case 3: printf("Result: %.2f\n", a*b); break; case 4: if (b != 0) printf("Result: %.2f\n", a/b);
else printf("Division by zero not allowed.\n"); break; default: printf("Invalid choice.\n"); }
} while (choice != 5);
return 0;
}

Arrays: Collection of elements. C program to add two matrices included.


Pointers explained with Call by Value & Call by Reference. Prime number check program also
included.

You might also like