0% found this document useful (0 votes)
30 views11 pages

Most Important Programs of CPS Theory Exam

The document lists 18 programming problems and their expected marks that are frequently asked in a programming problem-solving examination. Some example problems include writing programs to calculate simple interest, search an element in a list, find factorial of a number recursively, check if a number is prime, and determine the grade based on marks. The document provides guidelines to help students prepare for the exam.

Uploaded by

ADITYA Bhedasur
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)
30 views11 pages

Most Important Programs of CPS Theory Exam

The document lists 18 programming problems and their expected marks that are frequently asked in a programming problem-solving examination. Some example problems include writing programs to calculate simple interest, search an element in a list, find factorial of a number recursively, check if a number is prime, and determine the grade based on marks. The document provides guidelines to help students prepare for the exam.

Uploaded by

ADITYA Bhedasur
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/ 11

Most Important and Frequently asked Programs for Problem-Solving

through Programming (21PSP23/13) Theory Examination

Expected
Sl.No. Name of the program
marks
Write a C-program to calculate the simple interest where principal, amount,
1 6
time and rate of interest is given.
Develop a C-program to implement commercial calculator simple
2 arithmetic operations such as addition, subtraction, multiplication and 8
division and display the result of arithmetic operation on screen.
Develop a C-program to compute the roots of a quadratic equation by
3 8
accepting the coefficients. Print appropriate messages.
Develop a C-program to construct following pattern.
*
**
4 6
***
****
*****
Write a C-program to search the given element present in the list using
5 6
linear searching algorithm.
6 Write a C-program to transpose a matrix 6
Write a program in C to find the factorial of a given number using recursive
7 6
function.
8 Develop a C-program to find the Fibonacci series for a given value of ‘n’. 8
Write a C-program to check whether the given number is prime number or
9 8
not and display appropriate message on the screen
Write a C-program to maintain record of ‘n’ students using structures with
10 fields (roll no, marks, name and grade). Print the names of students with 8
marks>=70.
Write a program in C to display the grade based on the marks as follows:
Marks Grades
0 to 39 F
40 to 49 E
11 50 to 59 D 10
60 to 69 C
70 to 79 B
80 to 89 A
90 to 100 O
Write a program in C to check whether the given integer if palindrome or
12 8
not
13 Write a C program to find GCD of two numbers using functions 6
14 Develop a C program to plot a Pascal’s triangle 6
15 Write a C program to implement Bubble sort technique (ascending order). 8
Define a structure by name DoB consisting of three variable members dd,
16 mm and yy of type integer. Develop a C program that would read values to 10
the individual member and display the date in mm/dd/yy form
17 Write a C program to swap two numbers. 6
*****************Best Wishes Form Our YouTube Channel*****************
1. PROGRAM TO CALCULATE THE SIMPLE INTEREST WHERE PRICIPAL AMOUNT,TIME
AND RATE OF INTEREST IS GIVEN(QUESTION PAPER: DEC./JAN. 2019)

#include<stdio.h>
void main()
{
int p,t;
float r,si;
printf("enter pricipal amount,time and rate of interest\n");
scanf("%d%d%f",&p,&t,&r);
si=(p*t*r)/100;
printf("the simple interest is %f\n",si);
}

1. WRITE A PROGRAM TO SEARCH AN ELEMENT PRESENT IN LIST USING LINEAR SEARCHING


ALGORITHM(QUESTION PAPER: DEC./JAN. 2019)

#include<stdio.h>
int main()
{
int a[25],n,i,key ;
printf("Enter n:");
scanf("%d",&n);
printf("\n Enter any %d values",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\n Enter item to be search:");
scanf("%d",&key);

for(i=0;i<n;i++)
{
if (key==a[i])
{
printf("\n Item found %d at %d position",a[i],i+1);
exit(0);
}
}
printf("\n Item not found!");
return 0;
}

2. WRITE A PROGRAM TO TRANSPOSE A MATRIX(Question Paper: Dec./Jan. 2019)


#include<stdio.h>
void main()
{
int A[4][4],B[4][4],i,j;
printf("enter matrix elments\n");
for(i=0;i<4;i++)
{

for(j=0;j<4;j++)
{
scanf("%d",&A[i][j]);
}
}
printf("successfully stored\n");
printf("******ORIGINAL MATRIX*******\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf("%d\t",A[i][j]);
}
printf("\n");
}
printf("******TRANSPOSED MATRIX*******\n");

for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf("%d\t",A[j][i]);
}
printf("\n");
}
}

3. WRITE A PROGRAM TO FIND THE FACTORIAL OF A GIVEN NUMBER USING RECURSIVE


FUNCTION QUESTION PAPER: DEC./JAN. 2019 AND DEC.2019/JAN. 2020
/* to find factorial n by using recursive function*/
#include<stdio.h>
long int fact(int x); /* function declaration*/
void main()
{
int n;
long int ans;
printf("\n Enter a number");
scanf("%d",&n);
ans=fact(n); /* function call*/
printf("\n Factorial is %ld",ans);
}
long int fact(int n)
{
if (n==0 || n==1)
return(1);
else
return (n*fact(n-1));
}
4. WRITE A PROGRAM TO FIND THE FIBONACCI SERIES QUESTION PAPER: DEC./JAN. 2019
AND DEC.2019/JAN. 2020

//Program to display Fibonacci Series till a user enters


number. //or What is the Fibonacci of 'n'? where 'n' is
the length of Fibonacci term.
#include <stdio.h>
int fibbonacci(int n);
void main()
{
int n,i;
printf("Enter Total terms:n");
scanf("%d", &n);
printf("Fibbonacci of %d: " , n);
for(i = 0;i<n;i++)
{
printf("%d ",fibbonacci(i));
}
}
int fibbonacci(int n)
{
if(n == 0)
{
return 0;
}
else if(n == 1)
{
return 1;
}
else
{
return (fibbonacci(n-1) +
fibbonacci(n-2));
}
}

5. WRITE A PROGRAM TO CHECK WHETHER THE GIVEN NUMBER IS PRIME NUMBER OR NOT
AND DISPLAY APPROPRIATE MESSAGE ON THE SCREEN (QUESTION PAPER: JUNE/JULY
2019 AND JUNE/JULY 2019)
#include<stdio.h>
int n,i,flag=1;
void isprime(int n);
void main()
{
printf("\n Enter n:");
scanf("%d",&n);
isprime(n);
}
void isprime(int n)
{
for(i=2;i<n;i++)
{
if(n%i==0)
{
flag=0;
break;
}
}
if(flag ==1)
printf("\n %d is prime number",n);
else
printf("\n %d is not prime number",n);
}

6. WRITE A C PROGRAM TO MAINTAIN RECORD OF ‘N’ STUDENTS USING STRUCTURES WITH


FIELDS(ROLLNO, MARKS, NAME AND GRADE). PRINT THE NAMES OF STUDENTS WITH
MARKS>=70.
#include<stdio.h>
#include<conio.h>
struct student
{
int Rollno;
int Marks;
char Name[20];
char G;
};
struct student s[20];
int n,i;

void main()
{
printf("Enter the number of students\n");
scanf("%d",&n);

for(i=1;i<=n;i++)
{
printf("Enter the details of %d students\n",i);
printf("Enter the Rollno\n");
scanf("%d",&s[i].Rollno);
printf("Enter the Name\n");
scanf("%s",s[i].Name);
printf("Enter the Marks\n");
scanf("%d",&s[i].Marks);
printf("Enter the Grade\n");
s[i].G=getche();
printf("\n");
}
printf("The names of students with Marks>=70 are as follows\n");
for(i=1;i<=n;i++)
{
if(s[i].Marks>=70)
{

printf("Rollno=%d\t Name=%s\t Marks=%d\t and


Grade=%c\n",s[i].Rollno,s[i].Name,s[i].Marks,s[i].G);
}
}
getch();

7. WRITE A PROGRAM IN C TO DISPLAY THE GRADE BASED ON THE MARKS AS FOLLOWS:


Marks Grades
0 to 39 F
40 to 49 E
50 to 59 D
60 to 69 C
70 to 79 B
80 to 89 A
90 to 100 O

#include<stdio.h>
void main()
{
int marks;
printf("Enter your marks ");
scanf("%d",&marks);
if(marks<0 || marks>100)
{
printf("Wrong Entry");
}
else if(marks<=39)
{
printf("Grade F");
}
else if(marks>=40 && marks<=49)
{
printf("Grade E");
}
else if(marks>=50 && marks<=59)
{
printf("Grade D");
}
else if(marks>=60 && marks<=69)
{
printf("Grade C");
}
else if(marks>=70 && marks<79)
{
printf("Grade B");
}
else if(marks>=80 && marks<=89)
{
printf("Grade A");
}
else
{
printf("Grade O");
}
}

8. WRITE A PROGRAM IN C TO CHECK WHETHER THE GIVEN INTEGER IF PALINDROME OR


NOT.

#include <stdio.h>
int main() {
int n, reversed = 0, remainder, original;
printf("Enter an integer: ");
scanf("%d", &n);
original = n;

// reversed integer is stored in reversed variable


while (n != 0)
{
remainder = n % 10;
reversed = reversed * 10 + remainder;
n /= 10;
}

// palindrome if orignal and reversed are equal


if (original == reversed)
printf("%d is a palindrome.", original);
else
printf("%d is not a palindrome.", original);

return 0;
}

9. WRITE A C PROGRAM TO FIND GCD OF TWO NUMBERS USING FUNCTIONS.

#include<stdio.h>
int main()
{
int n1, n2, i, gcd;

printf("Enter two integers: ");


scanf("%d %d", &n1, &n2);

for(i=1; i <= n1 && i <= n2; ++i)


{
// Checks if i is factor of both integers
if(n1%i==0 && n2%i==0)
gcd = i;
}
printf("G.C.D of %d and %d is %d", n1, n2, gcd);

return 0;
}

You might also like