10

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

WEEK -10

COMMAND LINE ARGUMENTS

NAME:SALMAN AHMED QUADRI

ROLL NO:16951A2172

YEAR: 2016-2017

SUBJECT: C PROGRAMMING

SUBJECT CODE: ACS101

YEAR: I

SEMESTER : II

1. ALGORITHM:

1.To read arguments at the command line and display it


1. Start

2. Pass a to arguments argc and argv in main function

3. Check the condition argc equal to 2 then printf the argv[1] value

4. Else if argc is greter than 2 the print Too many arguments supplied

5. Else One argument expected

6. Stop

PROGRAM:
1.#include<stdio.h>

#include<string.h>

void main(int argc,char*argv[])

int i;
printf("\n total no of arguments=5d",argc);

for(i=0;i<argc;i++)

printf("\n args[%d]=%s",i,argv[i]);

2.ALGORITHM:

2.To read two numbers at the command line and perform arithmetic operations
on it.
1. Start

2. Pass a to arguments argc and argv in main function

3. If argc is equal to 3 then perform addition between the argv[1] and argv[2].

4. Print the sum value

5. Stop

PROGRAM:
2.#include<stdio.h>

void main(int argc,char*argv[])

int sum=0;

if(argc<2)

printf("\n insufficient arguments");

return;

sum=atoi(argv[1])+atoi(argv[2]);

printf("\n sum=%d",sum);

getch();

You might also like