473,395 Members | 1,974 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,395 software developers and data experts.

have to identify odd num and print them

1
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #define TRUE 1
  3.  
  4. int formOddInt(int n);
  5.  
  6. int main() {
  7.  
  8.     int num;
  9.  
  10.     do {
  11.  
  12.             printf("Enter a positive integer\n");
  13.             scanf("%d", &num);
  14.         } while (num <= 0);
  15.  
  16.     printf("Num is = %d \n The new number is %d \n", num,formOddInt(num));
  17.  
  18.     return TRUE;
  19. }
  20.  
  21.  int formOddInt(int n)
  22. {
  23. int i=0,d[5],count=0;
  24. while(n>0) {
  25. d[i]=n%10;
  26. n=n/10;
  27. i++ ;
  28. count++ ;
  29. }
  30. for(i=0;i<count;i++)
  31. printf("count=%d\td[i]=%d\n",count,d[i]);
  32. for(i=count;i>0;i--)
  33. {
  34.  if((d[i]%2)!=0)
  35.  {
  36.     return(d[i]);
  37.    }
  38. }
  39.    }
Apr 10 '13 #1
5 1333
johny10151981
1,059 1GB
You did not tell your problem. You should not expect that people would read your code and figure out your problem.
Apr 10 '13 #2
vijay6
158 100+
Hey ravali, the logical error is in line number 32 in your code. Inside the for loop assign value for 'i' as 'count - 1' instead of 'count'.

Expand|Select|Wrap|Line Numbers
  1. for( i = count - 1 ; i > 0 ; i-- ) // Line number 32

And after 38th line write 'return -1' which means if input number don't have odd number then it'll print -1.

Expand|Select|Wrap|Line Numbers
  1. return -1; // After line number 38

Note: Next time post/ask your question along with your code.
Apr 10 '13 #3
hi m gaurav..
Expand|Select|Wrap|Line Numbers
  1. // identify odd no. and print them
  2. #include<iostream.h>
  3. void main()
  4. { int a[10],b;
  5. cout<<"enter how many nos.";
  6. cin>>b;
  7. for(int i=0;i<=b;i++)
  8. { cout<<"enter "<<i+1<<"element";
  9.   cin>>a[i];
  10. }
  11. cout<<"the odd nos. are  ";
  12. for(i=0;i<=b;i++)
  13. {if(a[i]!%2)
  14. cout<<a[i];
  15. }
  16. }
//i wish this code would b understood by u..
Apr 11 '13 #4
Ya C++ with #include <iostream> but some people learn different and some times there way may be obsolete but they know it best and can use it the same as the new stuff, it's just harder.
Apr 11 '13 #5
johny10151981
1,059 1GB
iostream.h is obsolete, but in South Asia region people start with turbo c++ 3.0, a 20 years old compiler. I believe their teacher should not suggest their pupil this compiler......
Apr 12 '13 #6

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

Similar topics

3
by: Neil Zanella | last post by:
Hello, In Python, classes are objects. But there is no way to custom print a class object. This would require some syntax such as the one commented out below: With the current "foo =...
0
by: marcelf3 | last post by:
Hello, I am a novice/moderate html programmer and I wonder how to tell the browser from which start point and to which end point in the text will each page be printed. In other words, I have a...
1
by: Lol | last post by:
My apologies if this has been asked a thousand times before: I have (to start with) a simple database with a single table and a single report. The purpose of the database is to allow gift vouchers...
0
by: Bill Hymel | last post by:
Access Printing - Just wondering if you have a solution for this problem - I need to be able to print an Invoice with the 'terms and conditions' on the back side of an Invoice. To do this, I...
2
by: Curious Student | last post by:
I'd be obliged if someone could validate the functions I've written below from the try-it-yourself excercises of K&R: #include <stdio.h> #include <stdlib.h> #include <string.h> void...
13
by: Ian Davies | last post by:
Im trying to test if two fields have been entered at the same time I have tried many combinations but cant get it. My last effort was if(isset($_POST && isset($_POST)){ die('You can\'t select...
2
by: djsdaddy | last post by:
Good Day to All, I am organizing some Affirmative Action data and I need to be able to sum a number of field totals and then print them in a report. I have 5 tables that store the data that I need...
9
by: rushdi | last post by:
hi, i am trying to convert nos to a special format then print them into a text file. is it possible ? can anyone help me please ?
4
by: buddyr | last post by:
Hello, If I create two list boxes in microsoft access form. The first list box lists Toyota, Honda, and Nissan. The second list box depending on the first list box choice will list the models of...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.