Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-10-2007, 01:11 PM
Razzie89 Razzie89 is offline
Newbie
 
Join Date: Nov 2007
Posts: 1
Rep Power: 0
Razzie89 is on a distinguished road
Default A few (basic) questions

I want to help a friend of mine who just started learning programming in C, but has problems catching up because he doesn't have any previous knowledge of it. I myself know vb.NET but never programmed in C, so I can't help.

Some things that are asked:

- A program which counts vowels in a given text using switch.case.
(Similar to VB's "select case"? How to write this?)

- A program that calculates powers (ex. 3^4 when 3 and 4 are given by the user) without using pow(a,b).
I was thinking of writing something like A*((B-1)* "*A"), which would probably work in VB but how do you write this correctly in C?

- A program in which the user enters an amount of numbers, then it returns the minimum, maximum and average value when -1 is entered.
I asked another friend of me about this and he wrote down the following code, but we were unable to test it. Would it work?

#include <stdio.h>
int main(void)
{
int min = 0;
int max = 0;
int sum = 0;
int count_numbers = 0;

int read_number = -1;
scanf(“%d”, &read_number);

int min = read_number;
int max = read_number;
int sum = read_number

while (read_number != -1){
if(read_number < min)
min = read_number;
else if(read_number> max)
max = read_number;
sum+= read_number;
count_numbers++;
scan
f(“%d”, &read_number);
}
printf(“min %d”, min);
printf(“max %d”, max);
printf(“average %d”, sum/count_numbers);
}
scanf

If there is anyone who would be willing to help in any way, by writing down the code (and if possible a little bit of explanation) I would be really grateful. Thanks a lot in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 11-10-2007, 06:59 PM
G_Morgan G_Morgan is offline
Guru
 
Join Date: Oct 2007
Age: 24
Posts: 507
Last Blog:
Just over the next hil...
Rep Power: 10
G_Morgan has a spectacular aura aboutG_Morgan has a spectacular aura aboutG_Morgan has a spectacular aura about
Default

The power is easy using recursion

C Code:
  1. float power(float base, int index){
  2.     assert(index >= 0);
  3.     if(index == 0)
  4.         return 1;
  5.     return base * power(base, index - 1);
  6. }

This only works for an integer index greater than or equal to 0.

As for switch statements. They can be done as follows

C Code:
  1. switch(current_char){
  2.     case('a'):
  3.         /*action*/
  4.         break;
  5.     case('e'):
  6.         /*action*/
  7.         break;
  8.     ...
  9.     default:
  10.         /*default action*/
  11.         break;
  12. }

The breaks ensure that only one case is executed.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic u2cannv General Programming 8 10-05-2007 10:24 PM
A few basic website questions ehudgershon General Programming 4 06-11-2007 03:20 PM
HTML Basic Formatting clookid Tutorials 14 03-06-2007 04:10 PM
My friend made some cool BASIC videos elfshadow14 The Lounge 5 01-09-2007 11:20 PM
Parallel Port Programming Using Visual Basic kevintcp85 Visual Basic Programming 12 12-06-2006 01:09 PM


All times are GMT -5. The time now is 03:08 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads