solutions
solutions
1. Define a function which receives a number as argument and returns 1 if the number is prime
otherwise returns 0. Use this function in main function to display all prime numbers between two
numbers.
#include<stdio.h>
int isprime(int n) {
if (n % i == 0) {
int main() {
scanf("%d", &start);
scanf("%d", &end);
printf("Prime numbers between %d and %d are: ", start, end);
printf("\n");
return 0;
*/
/*
2. Write a program which asks order of two matrices and read two matrices of given order.
Subtract second matrix from first and display the resultant matrix.
#include<stdio.h>
int main()
int i, j, m, n;
scanf("%d", &m);
printf("enter the value of n:\n");
scanf("%d", &n);
//for matrix1
scanf("%d", &mat1[i][j]);
//for matrix2
{
printf("enter values[%d][%d]\n", i+1, j+1);
scanf("%d", &mat2[i][j]);
//for result
result[i][j]=mat1[i][j]-mat2[i][j];
return 0;
//3. Write a program to read a string from user and reverse it without using string related library
function.
#include<stdio.h>
#include<stdlib.h>
int reverse(char str[], char reversestr[]){
int i, len=0;
while(str[len]!='\0')
len++;
reversestr[i]= str[len-i-1];
reversestr[len]='\0';
int main()
scanf("%s", str);
//function call
reverse(str, reversestr);
return 0;
}
4. Write a program that determine the largest of three numbers using pointer.
#include<stdio.h>
*large= *n1;
*large= *n2;
else
*large=*n3;
int main()
{
int n1, n2, n3, large;
return 0;
5. Write a program to read 10 numbers and reorders them in ascending order. Define separate
function for reading , sorting and displaying array elements.
#include<stdio.h>
scanf("%d", &arr[i]);
{
for(int j=0; j<size-i-1; j++)
if(arr[j]>arr[j+1])
arr[j]=arr[j+1];
arr[j+1]=temp;
printf("%d", arr[i]);
printf("\n");
int main()
int numbers[10];
int size=10;
reading(numbers, size);
sorting(numbers, size);
displaying(numbers, size);
return 0;
6. Define two functions getArraynum() to read an array from user and determine the greatest
number respectively. Write main program to declare as floating point type array of size 10 and pass this
array to first function getarraynum() to read its elements and then pass the same array to another
function greatestnum() to determine the greatest number among elements of the array.
#include<stdio.h>
scanf("%f", &arr[i]);
if(arr[i]>max)
max= arr[i];
return max;
int main()
float numbers[10];
int size=10;
getarraynum(numbers, size);
return 0;
7. Create a structure named student that has name, roll, marks and remarks as members. Assume
appropriate types and size of member. Use this structure to read and display records of 4 students.
Create two functions: one is to read information of students and other is to display the information. Pass
array of structure to these functions.
#include <stdio.h>
struct student {
};
printf("Student Name\tRoll\tMarks\tRemarks\n");
int main() {
printf("Student information\n");
printf("Detail information:\n");
return 0;
8. Define a class named distance with meter and cm as private data members and appropriate
function members. Use this class to read two objects of the distance class , add them by passing these
two objects to a function members and finally display result object in main() function.
#include<iostream>
using namespace std;
class distance
private:
int meter;
int cm;
public:
getvalue()
cin>>meter;
cin>>cm;
}; incomplete one
9. Define a class shape with dim1 and dim2 as private members. Create two constructors of the
class, one with one argument and other with two arguments. Write a main() program to define object
rectangle with two dimensions and another object square with only one dimension using appropriate
constructor and calculate their area.
*/
#include<iostream>
private:
public:
int area()
return dim1*dim2;
};
int main()
shape rectangle(5,6);
shape square(4);
cout<<"The area of square is:"<<square.area()<<endl;
return 0;