TCS
Company
Programming
Variables
1.Write a c program to convert binary to decimal
using command line arguments?
2.Write a c program to check whether given no. is palindrome or not?
3. C program to find sum of N prime nos.?
Read Solution (Total 14)
-
- #include
int main(int argc, char *argv[]){
int num,binary,decimal=0,rem,base=1;
num=atoi(argv[1]);
binary=num;
while(num>0){
rem=num%2;
decimal+=rem*base;
num=num/10;
base=base*2;
}
printf("%d",decimal);
return 0;
} - 7 years agoHelpfull: Yes(29) No(12)
- i need to contact you urgent how could i @CSPATEL Fb or linkedin or Whtsapp
- 7 years agoHelpfull: Yes(8) No(8)
- #include
int main(int argc,char *argv[])
{
int num,n,rev=0,digit;
num=atoi(argv[1]);
n=num;
while(num!=0)
{
digit=num%10;
rev=rev*10+digit;
num=num/10;
}
printf("%d",rev);
if(rev==n)
printf("yes");
else
printf("no");
} - 7 years agoHelpfull: Yes(7) No(4)
- Sum of n prime numbers:
#include
int main(int argc,char *argv[])
{
int f1,f2,i,tot=0;
f1=atoi(argv[1]);
f2=atoi(argv[2]);
while(f1 - 7 years agoHelpfull: Yes(4) No(2)
- #include
#include
#include
int convert(int x); //fun to convert from binary to decimal
int main()
{
int x; //binary number
printf("plz enter binary number !nnbinary: ");
scanf("%d",&x);
printf("ndecimal: ",convert(x));
return 0;
}
int convert(int x)
{
int sum=0; //decimal number
int i=0;
int r; //remainder
while(x!=0){
r=x%10;
sum+=r*pow(2,i);
x=x/10;
i++;
}
return sum;
} - 7 years agoHelpfull: Yes(2) No(2)
- #include
#include
int main(int argc,char *argv[])
{
int n=atoi(argv[1]),i,j,sum,t,c=0;
for(i=2;c - 7 years agoHelpfull: Yes(1) No(10)
- 1.ans
#include
#include
int main()
{
int n,temp,rev=0,r;
printf("enter an integer number");
scanf("%d",&n);
temp=n;
while(temp>0)
{
r=temp%10;
rev=(rev*10)+r;
temp=temp/10;
}
if(n==rev)
{
printf("palindrome number");
}
else
{
printf("not a palindrome no");
}
getch();
} - 6 years agoHelpfull: Yes(1) No(0)
- Sum of n prime
#include
int main() {
int i, n, count = 0, value = 2, flag = 1, total = 0;
printf("Enter the value for n:");
scanf("%d", &n);
while (count < n) {
for (i = 2; i - 5 years agoHelpfull: Yes(1) No(0)
- for sum of n prime numbers
#include
#include
int main(int argc,char *argv[])
{
int n=atoi(argv[1]),sum=0,i,j,t,c;
for(i=2;c - 7 years agoHelpfull: Yes(0) No(12)
- can you please give the program of n prime number.
- 7 years agoHelpfull: Yes(0) No(4)
- Here m is the length of binary number and n is the binary number
#include
#include
int main()
{
int n,rem=0,i,k,m;
scanf("%d",&m);
scanf("%d",&n);
for(i=0;i - 7 years agoHelpfull: Yes(0) No(4)
- #include
int main()
{
int rev=0,a,rem=0,n;
scanf("%d",&n);
a=n;
while(n>0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
if(rev==a)
{
printf("given no is palindrome");
}
else
{
printf("given no is not a palindrome");
}
getch();
} - 6 years agoHelpfull: Yes(0) No(0)
- x=no of parrots y=no of cages First equation : 4(y-1)=x and second equation: 3y+1=x solving this two equation we get y=5..... so x=3*5+1=16
- 6 years agoHelpfull: Yes(0) No(1)
- #include
int main(int argc, char *argv[])
{
int num,binary,decimal=0,rem,base=1;
num=atoi(argv[1]);
binary=num;
while(num>0)
{
rem=num%2;
decimal =rem*base;
num=num/10;
base=base*2;
}
printf("%d",decimal);
return 0;
} - 5 years agoHelpfull: Yes(0) No(0)
TCS Other Question