473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

urgent help require

hi everybody
following is the program
Following is the menu to be displayed to the user. On selecting a choice display appropriate result. Number should be accepted from the user.

Menu

1. Prime Factors

2. Leap Year

3. Sum of all digits

4. Number in reverse order


out of this i am not able to the 3 rd part i.e is sum of all digits.
can u tell me how 2 find the sum of all digits that is enterd by the user.
Feb 13 '07 #1
5 1465
sicarie
4,677 Expert Mod 4TB
It seems you have posted this problem before. As I'm sure you read the request that Mary left in the other thread, I was wondering what specific question you had about this program - where did you get stuck? Can you post the code?
Feb 13 '07 #2
It seems you have posted this problem before. As I'm sure you read the request that Mary left in the other thread, I was wondering what specific question you had about this program - where did you get stuck? Can you post the code?
my code
/* Menu Driven Program */

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{

int choice,num,yr,a,n,b,sum,n1,n2,dg;
int temp[];

clrscr();
printf("\n\n1. Prime Factors\n");
printf("2. Leap Year\n");
printf("3. Sum of All digits\n");
printf("4. No. in Reverse Order\n");
printf("5. Exit\n");

printf("\n Enter no. of your Choice : ");
scanf("%d",&choice);

switch(choice)
{
case 1:
printf("Enter the Number :");
scanf("%d",&num);
int i=2;
printf("Prime Factor of the Number is %d : ",num);
while(num!=1)
{
if(num%i==0)
{
printf("%d ",i);
}
else
{
i++;
continue;
}
num=num/i;
}
break;

case 2:
printf("Enter a Year : ");
scanf("%d",&yr);
if(yr%100==0)
{
if(yr%400==0) /* The year is leap year if it is a century year & divisible by 400*/
{
printf("\n Leap Year");
}
else
{
printf("\nNot a Leap Year");

}
}
else
{
if(yr%4==0) /* The year is leap year if it is non-century year & divisible by 4*/
{
printf("\n Leap Year");
}
else
{
printf("Not a leap Year\n");
}
}
break;

case 3:
printf("Enter the Number : ");
scanf("%d",&n);
temp[]=n;
for(i=0;i<=len(temp[]);i++)
{
sum=sum+temp[i];

}
/* while(b<=1)
{
a=n%10;
b=n/10;
sum=0;
sum=sum+a;
n=b;
b--;
}*/
printf("Sum of all digit of the given number is : %d",sum);
break;

case 4:
printf("\nEnter any no.");
scanf("%d",&n1);
/* reverse the number*/
n2=0;
while(n1>0)
{
dg=n1%10;
n2=(n2*10)+dg;
n1=n1/10;
}
printf("The reverse no. is: %d",n2);
break;

case 5:
break;
}
getch();

}




case 3 for calculating the sum of enter no.s but i am not able to do it can u give me the code how to do it i hve to submit it 2mmorrow
Plz
Feb 13 '07 #3
Copy and pase this case 3 and try.....
You have to enter numbers the case 3 will add all the numbers and print at the end of the case ....enter 0 exit entering number.....

C is a structure language you cannot declare the variable in the middile of the code where you had declared the int i = 2; this is not allowed in c


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{

int choice,num,yr,a,n,b,sum,n1,n2,dg;
int i;
int temp[10];

clrscr();
printf("\n\n1. Prime Factors\n");
printf("2. Leap Year\n");
printf("3. Sum of All digits\n");
printf("4. No. in Reverse Order\n");
printf("5. Exit\n");
printf("\n Enter no. of your Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
printf("Enter the Number :");
scanf("%d",&num);
i=2;
// int i=2;
printf("Prime Factor of the Number is %d : ",num);
while(num!=1)
{
if(num%i==0)
{
printf("%d ",i);
}
else
{
i++;
continue;
}
num=num/i;
}
}
break;

case 2:
{
printf("Enter a Year : ");
scanf("%d",&yr);
if(yr%100==0)
{
if(yr%400==0) /* The year is leap year if it is a century year & divisible by 400*/
{
printf("\n Leap Year");
}
else
{
printf("\nNot a Leap Year");
}
}
else
{
if(yr%4==0) /* The year is leap year if it is non-century year & divisible by 4*/
{
printf("\n Leap Year");
}
else
{
printf("Not a leap Year\n");
}
}
}
break;

case 3:
{
sum=0;
printf("Enter the Number or 0 to stop entering number :");
do
{
scanf("%d",&n);
sum=sum+n;
}while(n!=0);
printf("Sum of all digit of the given number is : %d",sum);
}
break;

case 4:
{
printf("\nEnter any no.");
scanf("%d",&n1);
/* reverse the number*/
n2=0;
while(n1>0)
{
dg=n1%10;
n2=(n2*10)+dg;
n1=n1/10;
}
printf("The reverse no. is: %d",n2);
}
break;
case 5:
{




}
break;
}
getch();

}
Feb 13 '07 #4
hirak1984
316 100+
first of all practice using functions.this type of approach in writing code is very hard to understand.

use this code and try(this works for a 3 digit number):
Expand|Select|Wrap|Line Numbers
  1. printf("enter the number");
  2. scanf("%d",n);
  3. int a=n%10;
  4. int b=(n/10)%10;
  5. int c=n/100;
  6. printf("the sum=%d",(a+b+c));
  7.  
my code
/* Menu Driven Program */

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{

int choice,num,yr,a,n,b,sum,n1,n2,dg;
int temp[];

clrscr();
printf("\n\n1. Prime Factors\n");
printf("2. Leap Year\n");
printf("3. Sum of All digits\n");
printf("4. No. in Reverse Order\n");
printf("5. Exit\n");

printf("\n Enter no. of your Choice : ");
scanf("%d",&choice);

switch(choice)
{
case 1:
printf("Enter the Number :");
scanf("%d",&num);
int i=2;
printf("Prime Factor of the Number is %d : ",num);
while(num!=1)
{
if(num%i==0)
{
printf("%d ",i);
}
else
{
i++;
continue;
}
num=num/i;
}
break;

case 2:
printf("Enter a Year : ");
scanf("%d",&yr);
if(yr%100==0)
{
if(yr%400==0) /* The year is leap year if it is a century year & divisible by 400*/
{
printf("\n Leap Year");
}
else
{
printf("\nNot a Leap Year");

}
}
else
{
if(yr%4==0) /* The year is leap year if it is non-century year & divisible by 4*/
{
printf("\n Leap Year");
}
else
{
printf("Not a leap Year\n");
}
}
break;

case 3:
printf("Enter the Number : ");
scanf("%d",&n);
temp[]=n;
for(i=0;i<=len(temp[]);i++)
{
sum=sum+temp[i];

}
/* while(b<=1)
{
a=n%10;
b=n/10;
sum=0;
sum=sum+a;
n=b;
b--;
}*/
printf("Sum of all digit of the given number is : %d",sum);
break;

case 4:
printf("\nEnter any no.");
scanf("%d",&n1);
/* reverse the number*/
n2=0;
while(n1>0)
{
dg=n1%10;
n2=(n2*10)+dg;
n1=n1/10;
}
printf("The reverse no. is: %d",n2);
break;

case 5:
break;
}
getch();

}




case 3 for calculating the sum of enter no.s but i am not able to do it can u give me the code how to do it i hve to submit it 2mmorrow
Plz
Feb 13 '07 #5
Try this sample code......
Sorry for the above post...

Example
Input 123 output will be 6

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{

int i,j,k,l;
clrscr();
printf("Enter the no :");
scanf("%d",&i);
l=0;
do
{
k=i/10;
j=i%10;
i=k;
l=j+l;
}
while(j);
printf("The value of sum is %d",l);
getch();
return 0;


}
Feb 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Rajesh Garg | last post by:
I have actually extended my request I have a scenario like this....... update esan set tes_address_city = 'TEST1' --at some time update esan set tes_address_city = 'TEST12' --at some time...
5
by: Vishal | last post by:
Hello, I already asked this question in the ASP.NET forums, but no help came. So I am hoping that somebody can help me out. This is really very URGENT me. For my e-commerce application, I...
3
by: Seion | last post by:
Hi, Any body can teach me how to convert double bytes HEX to single byte HEX? I'm not too sure what does this mean. But, it is a requirement from a server software that only allow single byte...
0
by: Charles Dido | last post by:
Sir, I am MR.CHARLES ALAMIEYESEIGHA. I am the son of GOVONOUR of BAYELSA STATE IN NIGERIA.Some months ago, this YEAR, my father was arrested in LONDON by the LONDON METHROPOLITAN POLICE for...
6
by: ajit | last post by:
I am working on web service which in turn call com components. if # of users using the web service increases. Web service fails is there some why I can prevent max # of concurrent users using the...
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
4
by: Adrian Parker | last post by:
We've suddenly started getting a problem with a call to clear the contents of a DataTable. This is on a live customer site that's been working fine until yesterday. As far as we know they've not...
5
by: igotyourdotnet | last post by:
I'm creating a web service this is going to return an arraylist of items. When I try and run it Im' getting the following error message: System.InvalidOperationException: There was an error...
0
by: imran haq | last post by:
Hi All, I have 3 rather Long Questions that are causing alot of trouble: I would appreciate all the help i can get and tried to use A post sent to atli in the past but it did not help... !) I...
2
by: =?ISO-8859-1?B?RulybmFz?= | last post by:
Hey all, I have a URGENT problem and I hope someone could help me... scenery: I have a windows app, coded using C# (framework 1.1 - VS2003)... The exe and dlls of the app is are stored in a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.