0% found this document useful (0 votes)
24 views

Title: Objective:: Pointers and Pointer-Based Strings

This document contains code for 4 tasks related to pointers and arrays in C++. Task 1, 2, and 3 involve passing pointers to functions to manipulate and print numbers. Task 1 finds prime numbers between two numbers. Task 2 prints numbers in descending order. Task 3 calculates and prints factorials of two input numbers. Task 4 defines a 2D character array, takes 3 string inputs, and passes the array to a function that prints it.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Title: Objective:: Pointers and Pointer-Based Strings

This document contains code for 4 tasks related to pointers and arrays in C++. Task 1, 2, and 3 involve passing pointers to functions to manipulate and print numbers. Task 1 finds prime numbers between two numbers. Task 2 prints numbers in descending order. Task 3 calculates and prints factorials of two input numbers. Task 4 defines a 2D character array, takes 3 string inputs, and passes the array to a function that prints it.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab # 04

TITLE: POINTERS AND POINTER-BASED STRINGS OBJECTIVE: Manipulating pointers for different data types.
Task # 1 , 2 and 3:
#include<iostream> using namespace std; int prime(int * , int *); void des(int * , int * ); void fact(int , int ); int main() { int a , b, c, d, i; cout<<"enter the larger number"<<endl; cin>>a; cout<<"enter the lower number"<<endl; cin>>b; i=prime(&a , &b); des(&a,&b); cout<<"enter two numbers for factorial "<<endl; cin>>c; cin>>d; fact(c,d); return 0; } int prime( int *c , int *d) { cout<<"These are the prime numbers between them"<<endl; int i, j; for (i=*d ; i<=*c ; i++) { for (j=2; j<i; j++) { if (i % j == 0) break; } if(i==j) cout<<i<<" } cout<<endl; return i; } void des(int *c, int *d) { int i, j; cout<<"These are the numbers in descending order :"<<endl; for (i=*c ; i>=*d ; i--) { for (j=2; j<i; j++) { if (i % j == 0)

";

break; } if(i==j) cout<<i<<" }

";

cout<<endl; } void fact(int e, int f) { int u=1; int v=1; for(int y=1;y<=e;y++) { u=u*y; } cout<<"The factorial of "<<e<<" is "<<u<<endl; for(int z=1;z<=f;z++) { v=v*z; } cout<<"The factorial of "<<f<<" is "<<v<<endl; }

TASK # 4:
#include<iostream> using namespace std; void mat(char [][15]); void main(void) { char arr2[3][15]; cout<<"enter 3 strings"<<endl; for(int i=0;i<3;i++) { cin.getline(arr2[i],15); } mat(arr2); } void mat(char arr1[][15]) { int i,j; cout<<"\nPrinting array using Functions: "<<endl; for(i=0;i<3;i++) { for(j=0;j<15;j++) { cout<<arr1[i][j]<<" "; } cout<<endl; } cout<<endl; }

You might also like