Like Tree1Likes
  • 1 Post By Salem

please help me with this problem fellow programmers.

This is a discussion on please help me with this problem fellow programmers. within the C Programming forums, part of the General Programming Boards category; Problem 1: Basic Mathematical Operations Create a C program that will input N number and create a function that determines ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    4

    Lightbulb please help me with this problem fellow programmers.

    Problem 1: Basic Mathematical Operations


    Create a C program that will input N number and create a function that determines the following SUM, AVERAGE, EVEN Numbers ODD Numbers, Prime Numbers and FACTORIAL of the given N integers.


    Consider the following sample output.


    Enter N numbers: 10


    Value of number 1-3
    Value of number 2-3
    Value of number 3-7
    Value of number 4-3
    Value of number 5- 2
    Value of number 6- 3
    Value of number 7- 45
    Value of number 8- 4
    Value of number 9 - 3
    Value of number 10-19


    Sum: 92
    Average: 9.2


    EVEN Numbers: 2, 4


    ODD Number: 3,3,7,7,3,45,3,19


    PRIME Numbers: 3,3,7,3,2,3,3


    Factorial:
    Value 1- 3 = 6
    Value 2- 3 = 6
    .
    .
    .
    Value 10 19 = ?



    Code:
    #include<stdio.h>
    #include<conio.h>
    int sum (int);
    float ave (float,float);
    int even (int);
    int main()
    {
    	int count,hold,num,sumall=0;
    	clrscr();
    	printf("\nEnter N numbers: "); scanf("%d",&hold);
    	for (count=1;count<=hold;count++)
    	{
    		printf("Value of number %d-",count);
    		scanf("%d",&num);
    		sumall=sumall+sum(num);
    		if (count==hold)
    		{
    			printf("\nSum:%d",sumall);
    			printf("\nAverage:%.1f",ave(sumall,hold));
    		}
    	}
    	getch();
    	return 0;
    }
    
    
    int sum (int a)
    {
    	int sum1;
    	sum1=0;
    	sum1=a+sum1;
    	return (sum1);
    }
    
    
    float ave (float b, float c)
    {
    	float ave1;
    	ave1=b/c;
    	return ave1;
    }
    I am stuck at average because i don't know what is next now please me
    Last edited by Salem; 10-07-2012 at 12:55 PM. Reason: added code tags

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Announcements - C Programming

    And

    A development process

    So do the ? at the end of your post mean you're only having a problem with factorial?

    You really need to post some code if you want the "fellow programmers" moniker to stick.
    Because without code, you're no programmer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    4
    i am hard now at the succeeding functions to create sir. please help. I am begging you

    Quote Originally Posted by Salem View Post
    Announcements - C Programming

    And

    A development process

    So do the ? at the end of your post mean you're only having a problem with factorial?

    You really need to post some code if you want the "fellow programmers" moniker to stick.
    Because without code, you're no programmer.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Do you know about arrays yet?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Oct 2012
    Posts
    4
    we did not yet tackled that sir. but if your willing to help sir i'll be so thankful to you X)

  6. #6
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    633

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    For example
    Code:
    int array[10];
    for ( i = 0 ; i < 10 ; i++ ) {
      scanf("%d", &array[i] );
    }
    Then you can declare a function, such as
    Code:
    void sum ( int array[10] ) {
      int result = 0;
      for ( i = 0 ; i  < 10 ; i++ ) {
        result += array[i];
      }
    }
    All your other program features can be implemented as a function, taking an array parameter, and using a for loop to process each element of the array.

    For additional bonus points, make the 10 constant an additional parameter to each function.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Oct 2012
    Posts
    4
    about the problem i posted sir. how can i print all the even numbers that the user inputted as well as the odd numbers

  9. #9
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    633
    if number%2==0 then print evens

    In addition you can do this with odds as well.

    if number%2!=0 then print odds

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    I'm sensing homework by successive approximation.

    Especially when you keep bouncing back within 5 minutes of each post.

    There's no way you read the information provided and tried to apply it to your own situation.
    rags_to_riches likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fellow MUD fanatics! :) positions for 50 mb mud server!
    By gukk in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 06-06-2012, 11:20 PM
  2. Hello to fellow programmers out there
    By eurosickwitit in forum General Discussions
    Replies: 8
    Last Post: 11-18-2011, 04:18 AM
  3. Fellow c programmers
    By rmc in forum C Programming
    Replies: 4
    Last Post: 03-31-2009, 06:16 PM
  4. Attn Fellow music makers
    By RobR in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 12-16-2003, 04:04 PM
  5. Well Fellow CBoarders.........Cya laterz
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 06-16-2002, 10:15 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21