plz answer.. a program that takes a string e.g. "345" and
returns integer 345

Answer Posted / vignesh1988i

#include<stdio.h>
#include<conio.h>
#include<string.h>
int fun(char *,int);
void main()
{
long int c,l;
char a1[20];
printf("enter the numerical string :");
scanf("%s",&a1);
l=strlen(a1);
c=fun(a,l);
printf("\n%ld",l);
getch();
}
int fun(char *a,long int l1)
{
long int a1[]=
{1,10,100,1000,10000,100000,1000000,10000000,100000000},c;
int p=a1[l1-1],c=0;
for(int i=0;a[i]!='\0';i++)
{
y=((int)a[i])*p; /*TYPE CASTING*/
c=c+y;
p=p/10;
}
return c;
}

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is c faster?

802


What's the difference between constant char *p and char * constant p?

928


How many levels of pointers can you have?

962


What is declaration and definition in c?

784


why return type of main is not necessary in linux

1912


What are the different types of control structures?

826


What is data structure in c language?

868


What is the difference between memcpy and memmove?

805


Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.

1169


Explain how can I remove the trailing spaces from a string?

848


Write a program to know whether the input number is an armstrong number.

937


In c programming language, how many parameters can be passed to a function ?

906


Why we use void main in c?

878


How can I change the size of the dynamically allocated array?

922


What is the difference between c and python?

852