Skip to main content

Posts

Showing posts with the label Command Line Arguments in c

To check Whether the given number is Perfect number or Not

Source Code: #include <stdio.h> #include<stdlib.h> int main(int argc, char const*argv[]) {     int i, n;     n=atoi(argv[1]);     for(i = 0; i <= n; i++)     {         if (n == i * i)         {             printf("YES");             return 0;         }     }     printf("NO");     return 0; } Output: D:\D INSTALL\TDM-GCC-32\Programs>Perfect 4 YES D:\D INSTALL\TDM-GCC-32\Programs>Perfect 5 NO D:\D INSTALL\TDM-GCC-32\Programs>Perfect 100 YES Users Also Seen : How to use Command Line arguments in C Add two numbers using Command Line Arguments in C Thanks and regards, Tech Bird

Add two numbers using Command line arguments in c

Source Code: #include<stdio.h> #include<stdlib.h> void main(int argc , char * argv[]) {     int i,sum=0;     if(argc!=3)       {       printf("you have forgot to type numbers.");       exit(1);       }     printf("The sum is : ");     for(i=1;i<argc;i++)         sum = sum + atoi(argv[i]);     printf("%d",sum); } Output: D:\D INSTALL\TDM-GCC-32\Programs>add 2 4 The sum is : 6 D:\D INSTALL\TDM-GCC-32\Programs>add 5 4 The sum is : 9 Check Here: How to Use Command Line Arguments in C  Thanks and regards, Tech Bird

Convert Binary Number to Decimal Number Using Command Line Arguments

Source Code: #include <stdio.h> #include<stdlib.h> void main(int argc, char const*argv[]) {     long  number, binary, decimal= 0, base = 1, remainder;               number = atoi(argv[1]);      while (number > 0)     {         remainder = number % 10;         decimal = decimal + remainder * base;         number = number / 10 ;         base = base * 2;     }     printf("%ld", decimal); } Output: User Also Seen : Convert Decimal To Binary Number    Thanks and regards, Tech Bird

Convert Decimal Number to Binary Number Using Command Line Arguments

Source Code: #include <stdio.h> #include<stdlib.h> void main(int argc, char const*argv[]) {     long number, remainder, base = 1, binary = 0 ;     number = atoi(argv[1]);     while (number > 0)     {         remainder = number % 2;                       /* separate Last digit from number */         binary = binary + remainder * base;         number = number / 2;                              /* remove Last digit from num */         base = base * 10;     }     printf(...

Count The Number of Odd Digits in the Given Integer Using Command Line arguments

Note: Remove the Red color Highlighted Lines such that it works as a code for Odd digits.. Source Code: #include<stdio.h> #include<stdlib.h> void main(int argc, char const*argv[]) {  int oddCount = 0, evenCount = 0, InputNum, temp ; InputNum = atoi(argv[1]);  while (InputNum> 0)         {              temp = InputNum % 10;                         /* separate Last digit from number */               if (temp % 2 == 1)                 {                   oddCount++;      ...

Count The Number of Odd and even Digits in the Given Integer Using Command Line arguments

Source Code: #include<stdio.h> #include<stdlib.h> void main(int argc, char const*argv[]) {  int oddCount = 0, evenCount = 0, InputNum, temp ; InputNum = atoi(argv[1]);  while (InputNum> 0)         {              temp = InputNum % 10;                         /* separate Last digit from number */               if (temp % 2 == 1)                 {                   oddCount++;                  }     ...

How to use command line arugments in c

Hi its me Dharani again with a blog ... About : " how to use command line arugments in c" Requirements : " Gcc compiler installed and Cmd(command prompt)" ****I will be using SublimeText3 for coding no worries you do those stuff with notepad itself***** Note: Gcc is used to compile the program bcz cmd does not know any programming languages.. Cmd acts as console to compile and run the program ... Cool..! Lets get Started.. Hoping Gcc has been installed on your system. First you need a Piece of code to start with.. //MyFirstProgram.----C program to print all arguments given through command line. Source code: #include<stdio.h> void main(int argc, char const *argv[]) { /* code */ int a,b,c;     printf("Enter the Three Values:"); scanf("%d %d %d",&a,&b,&c); printf("Values in the arguments: \n a is %d b is %d c is %d", a,b,c); } Save this code in Notepad File and save as .. some...