Programming for Problem Solving – Important Questions
UNIT 1 – Introduction
1. Define algorithm with examples.
2. Flowchart for largest of three numbers.
3. Structure of a C program.
4. Compiler vs interpreter.
UNIT 2 – C Basics
1. Data types in C.
2. Operators: arithmetic, logical, bitwise.
3. Program: swap numbers without third variable.
UNIT 3 – Control Statements
1. if, if-else, switch-case.
2. Program: prime number.
3. Program: Fibonacci series.
4. Program: reverse a number.
UNIT 4 – Arrays & Strings
1. 1D vs 2D arrays.
2. Program: largest element in array.
3. Matrix addition and multiplication.
4. String length without strlen().
UNIT 5 – Functions
1. Call by value vs call by reference.
2. Recursive factorial.
3. Recursive fibonacci.
UNIT 6 – Pointers
1. Pointer basics.
2. Swap using pointers.
3. Pointer arithmetic.
UNIT 7 – Structures & Unions
1. Difference between structure and union.
2. Program to store student details.
UNIT 8 – File Handling
1. File modes.
2. Read/write file program.
MOST IMPORTANT PROGRAMS
1. Largest of three numbers
2. Prime check
3. Fibonacci
4. Factorial
5. Palindrome
6. Matrix programs
7. Sorting and searching
8. File handling programs
MRSPTU Bathinda – [Link] CSE AIML 1st Sem
Programming for Problem Solving – FULL Important Questions + Programs + Examples
1. Even/Odd Number
#include int main(){ int n; scanf("%d",&n;); if(n%2==0) printf("Even"); else printf("Odd"); } Example: 7 →
Odd
2. Largest of Three Numbers
#include int main(){ int a,b,c; scanf("%d%d%d",&a;,&b;,&c;); if(a>=b&&a;>=c) printf("%d",a); else
if(b>=a&&b;>=c) printf("%d",b); else printf("%d",c); }
3. Factorial
int n,f=1; scanf("%d",&n;); for(int i=1;i<=n;i++) f*=i; printf("%d",f);
4. Fibonacci
int n,a=0,b=1,c; scanf("%d",&n;); printf("%d %d ",a,b); for(int i=3;i<=n;i++){ c=a+b; printf("%d ",c); a=b;
b=c; }
5. Prime Number
int n,flag=0; scanf("%d",&n;); for(int i=2;i<=n/2;i++) if(n%i==0){flag=1;break;} printf(flag?"Not
Prime":"Prime");
6. Reverse Number
int n,rev=0,r; scanf("%d",&n;); while(n){ r=n%10; rev=rev*10+r; n/=10; } printf("%d",rev);
7. Palindrome Number
int n,rev=0,t,r; scanf("%d",&n;); t=n; while(t){ r=t%10; rev=rev*10+r; t/=10; }
printf(n==rev?"Palindrome":"Not Palindrome");
8. Armstrong Number
int n,sum=0,r,t; scanf("%d",&n;); t=n; while(t){ r=t%10; sum+=r*r*r; t/=10; }
printf(sum==n?"Armstrong":"Not Armstrong");
9. Sum of Array
int n; scanf("%d",&n;); int a[n],s=0; for(int i=0;i
10. Linear Search
int n,key; scanf("%d",&n;); int a[n]; for(int i=0;i
11. Binary Search (Array must be sorted)
int n,key,l=0,h,mid; scanf("%d",&n;); int a[n]; for(int i=0;i
12. Bubble Sort
int n; scanf("%d",&n;); int a[n]; for(int i=0;ia[j+1]){ int t=a[j]; a[j]=a[j+1]; a[j+1]=t; }
13. String Length (Without strlen)
char s[50]; scanf("%s",s); int i; for(i=0;s[i]!='\0';i++); printf("%d",i);
14. String Palindrome
char s[50],r[50]; scanf("%s",s); strcpy(r,s); strrev(r); printf(strcmp(s,r)==0?"Palindrome":"Not
Palindrome");
15. Functions – Factorial
int fact(int n){ return (n<=1)?1:n*fact(n-1); } int main(){ int n; scanf("%d",&n;); printf("%d",fact(n)); }
16. Swap Using Pointers
void swap(int *a,int *b){ int t=*a; *a=*b; *b=t; }
17. Pointer – Sum of Array
int n; scanf("%d",&n;); int a[n],*p=a,sum=0; for(int i=0;i
18. Structure – Student Details
struct student{ int roll; char name[20]; float marks; }; struct student s; scanf("%d %s
%f",&[Link];,[Link],&[Link];); printf("%d %s %.2f",[Link],[Link],[Link]);
19. File Handling – Write to File
FILE *f=fopen("[Link]","w"); fprintf(f,"Hello World"); fclose(f);
20. File Handling – Read from File
FILE *f=fopen("[Link]","r"); char ch; while((ch=fgetc(f))!=EOF) printf("%c",ch); fclose(f);
End of Full PDF
Roll No. Total No. of Pages: 02
Total No. of Questions: 09
[Link] (Sem. – 1,2)
PROGRAMMING FOR PROBLEM SOLVING
Subject Code: BTPS-101-18
M Code: 75346
Date of Examination : 28-01-23
Time: 3 Hrs. Max. Marks: 60
INSTRUCTIONS TO CANDIDATES:
1. SECTION-A is COMPULSORY consisting of TEN questions carrying TWO marks each.
2. SECTION - B & C have FOUR questions each, carrying EIGHT marks each.
3. Attempt any FIVE questions from SECTION B & C, selecting atleast TWO questions
from each of these SECTIONS B & C.
SECTION-A
1. Write briefly:
a. Differentiate between primary and secondary memory.
b. What is algorithm? Give an example.
c. Give an example of run time error.
d. What is a pointer? Give an example of how to use integer pointer.
e. Define recursion. Give an example.
f. Explain various in-built data types.
g. Explain various logical operators with the help of an example each.
h. What is a string? How can we compute the length of a string?
i. What is continue statement? Give an example ustng for loop.
j. Why should one prefer call by address method using a function to swap two
numbers?
M-75346 S-2455A
SECTION-B
2. What are the advantages of using flowchart? Create a flowchart to find if the given
number is prime or not.
3. What is while loop? Write syntax for the same. Write a program to find if the given
number is prime or not.
4. Explain in detail various components of computer system. Explain various types of
computer memory.
5. Explain in detail different data types used in c programming language.
SECTION-C
6. How many methods are three to pass value to a function? Write a program to swap two
numbers using call by address method with the help of a function.
7. How can we create a 2-D array? Write a program to display sum of all elements of a 2-D
array.
8. What is a structure? How can we initialize the members of a structure? Write a program
to create a simple structure for storing information of an employee.
9. Explain in detail all types of control statements with the help of syntax for each.
NOTE : Disclosure of Identity by writing Mobile No. or Marking of passing request on any
paper of Answer Sheet will lead to UMC against the Student.
M-75346 S-2455A
PPS – Programming for Problem Solving (Full Notes with Solved Questions)
UNIT 1 – Introduction to Programming
What is a Program?
A program is a set of instructions written to perform a task.
What is an Algorithm?
A step-by-step procedure to solve a problem.
Example Algorithm – Add two numbers:
1. Start
2. Input a and b
3. sum = a + b
4. Output sum
5. Stop
Basic Structure of a C Program:
#include
int main() {
return 0;
UNIT 2 – Control Statements
If–Else Example – Largest of Two Numbers:
#include
int main() {
int a,b;
scanf("%d %d",&a;,&b;);
if(a>b) printf("A is larger");
else printf("B is larger");
return 0;
Loop Example – Print 1 to 10:
for(int i=1;i<=10;i++) printf("%d ",i);
While Loop Example – Sum of digits:
while(n>0){ sum+=n%10; n/=10; }
UNIT 3 – Functions
Function to Add Two Numbers:
int add(int x,int y){ return x+y; }
UNIT 4 – Arrays
Print Array Elements:
int arr[5]={1,2,3,4,5};
Linear Search Program:
for(int i=0;i<5;i++){ if(arr[i]==key){found=1;} }
Bubble Sort Program:
Nested loops swapping adjacent elements.
UNIT 5 – Pointers
A pointer stores the address of another variable.
UNIT 6 – File Handling
Write to File:
FILE *fp=fopen("[Link]","w"); fprintf(fp,"Hello"); fclose(fp);
Read from File:
FILE *fp=fopen("[Link]","r"); fgets(data,50,fp); printf("%s",data);