Tcs 2019 Coding
Tcs 2019 Coding
Binary to Decimal
Decimal to Binary
Factorial of a Number
Square Root of Prime Number
Square Root without sqrt.h
Armstrong Number
Odd Even Number
Binary to Octal
Decimal to Octal
Check Leap Year
Area of Circle
Area of Triangle
Note: Please go through Command Line Arguments Post before preparing for these
questions. The theory there for TCS command line Program will help you in better
understanding.
#include
#include
int main(int argc, char *argv[])
{
int n, first = 0, second = 1, next, c;
n = atoi(argv[1]);
printf("These are %d values in Fibonacci series are by MyGeekMonkey:-\n",n);
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
printf("%d\n",next);
}
return 0;
}
Note: Please go through Command Line Arguments Post before preparing for these
questions. The theory there for TCS command line Program will help you in better
understanding .
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
int c[10];
int i,temp,j,greatest;
j = 0;
temp = atoi(argv[i]);
c[j] = temp;
j++;
greatest = c[0];
greatest = c[i];
}
return 0;
int main(int argc, char * argv[])
{
long num, temp, digit, sum = 0;
if(argc == 1 || argc > 2)
{
printf("Enter the number\n");
exit(1);
}
num = atoi (argv[1]) ;
temp = num;
while (num > 0)
{
digit = num % 10;
sum = sum + digit;
num /= 10;
}
printf("Sum of the digits of %ld = %ld\n", temp, sum);
}
#include<stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc < 3)// as number of arguments needed are 2 and 1 is
default arg.
{
printf(" Please provide values for both base and height \n");
return 0;
}
else
{
int base = atoi(argv[1]);
int height = atoi(argv[2]);
float area = 0.5*base*height;
printf("%.2f",area);
return 0;
}
}
Note: Please go through Command Line Arguments Post before preparing for these
questions. The theory there for TCS command line Program will help you in better
understanding .
[code language="cpp"]
// Program to print all value of
// command line argument
// once we get the value from command
// line we can use them to solve our problem
#include <stdio.h>
return 0;
}
[/code]
if(argc<2)
{
printf("please use \"prg_name value1 value2 ... \"\n");
return -1;
}
int a,b,side1,side2,side3;
a=atoi(argv[1]);
b=atoi(argv[2]);
side1=pow(a,2);
side2=pow(b,2);
side3=sqrt((side1+side2));
printf("the hypotenuse is %d",side3);
return 0;
return 0;
}
int isPalindrome(int n)
{
int m=n;
int rev=0;
while(m!=0)
{
rev=(rev*10) + (m%10);
m=m/10;
}
if(rev==n)
return 1;
else
return 0;
}
Write a C program that will find the sum of all prime numbers in a given range.The range
will be specified as command line parameters. The first command line parameter, N1 which is
a positive integer, will contain the lower bound of the range. The second command line
parameter N2, which is also a positive integer will the upper bound of the range. The program
should consider all the prime numbers within the range, excluding the upper and lower
bound. Print the output in integer format to stdout. Other than the integer number, no other
extra information should be printed to stdout.
#include<stdio.h>
int main(int argc,char *argv[])
{
int N1,N2,i,j,sum=0,count,lower,upper;
if(argc!=3)
exit(0);
N1=atoi(argv[1]);
lower=N1+1;
N2=atoi(argv[2]);
upper=N2;
for(i=lower;i<upper;i++)
{
count=1;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
count++;
}
}
if(count==1)
{
sum=sum+i;
}
}
printf("%d",sum);
return 0;
}
num = atol(argv[1]);
temp=num;
while(temp!=0)
remainder=temp%10;
reverse_num=reverse_num*10+remainder;
temp/=10;
if(reverse_num==num)
else
return 0;
}
Command Line Program for Checking
Palindrome (String)
#include <stdio.h>
#include <string.h>
int l = 0;
int h = strlen(str) - 1;
while (h > l)
if (str[l++] != str[h--])
return;
int i,k;
int strsize = 0;
strsize += strlen(argv[i]);
strsize++;
char *cmdstring;
cmdstring = malloc(strsize);
cmdstring[0] = '\0';
isPalindrome(cmdstring);
#include <string.h>
int l = 0;
int h = strlen(str) - 1;
while (h > l)
if (str[l++] != str[h--])
return;
int i,k;
int strsize = 0;
strsize += strlen(argv[i]);
char *cmdstring;
cmdstring = malloc(strsize);
cmdstring[0] = '\0';
strcat(cmdstring, argv[k]);
isPalindrome(cmdstring);
n = atol(argv[1]);
{
{
flag=1;
break;
}
}
if (flag==0)
else
ote: Please go through Command Line Arguments Post before preparing for these questions.
The theory there for TCS command line Program will help you in better understanding .
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
if(argc==1)
{
printf("No Arguments");
return 0;
}
else
{
int n,reverseNumber,temp,rem;
n=atoi(argv[1]);
temp=n;
reverseNumber=0;
while(temp)
{
rem=temp%10;
reverseNumber=reverseNumber*10+rem;
temp=temp/10;
}
printf("%d",reverseNumber);
return 0;
}
}
ote: Please go through Command Line Arguments Post before preparing for these questions.
The theory there for TCS command line Program will help you in better understanding .
Please follow Command Line Programming here.
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
// driver code
int main()
{
int arr[] = { 5, 4, 6, 2, 1, 3, 8, 9, 7 };
int n = sizeof(arr) / sizeof(arr[0]);
printOrder(arr, n);
return 0;
}