Home > Cpp > C++ Program to check Command Line Arguments – Q4

C++ Program to check Command Line Arguments – Q4

Q4. Program to check Command line arguments:

Accept an n digit number as command line argument & perform various tasks specified below:
 i) Find the sum of digits of the number
ii) Find the reverse of a number

… from College notes (BCA/MCA assignments):

#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <math.h>

void Sum_Num(char *);
void Rev_Num(char *);

void main(int argv, char *argc[]){
	char patt[10];
	if(argv < 1)
		cout<<"\n Insuffecient Arguments. \n";
		strcpy(patt, argc[1]);
		cout<<”\n Argument is: “<<patt;

void Sum_Num(char *pt){
	int sum = 0, i = 0;
	while(*(pt+i) != '\0'){
		sum += int(*(pt+i)) - 48;
	cout<<"\n Sum: "<<sum;

void Rev_Num(char *pt){
	long r_num = 0;
	int i = 0;
	while(*(pt+i) != '\0'){
		r_num += (int(*(pt+i)) - 48) * pow(10, i);
	cout<<"\n Reverse: "<<r_num;



Argument is: 12345

Sum: 15

Reverse: 54321

Categories: Cpp Tags: , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: