| | |
simple display problem??
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Are you sure that you're a software engineer (as described in your profile) ?
(Just display the array)
(Take the first element and display all the elements after it, take the second element and display all the elements after it, take the third element and ...)
C Syntax (Toggle Plain Text)
10 20 30 40
C Syntax (Toggle Plain Text)
10+20 10+30 10+40 20+30 20+40 30+40
Last edited by tux4life; May 16th, 2009 at 4:37 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
•
•
Join Date: Apr 2008
Posts: 296
Reputation:
Solved Threads: 11
int array[] = {10,20,30,40};
find length of array and store in count=4
how to move on next step
find length of array and store in count=4
C Syntax (Toggle Plain Text)
for (i=0;i<=count;i++) { printf("%d",arr[i]); }
That's already a lot better, you're making progress 
To find the length of the array you can do something like this:
(
Now you've already the code to print out the whole array you've already completed 30% of your homework

To find the length of the array you can do something like this:
const int count=sizeof(array)/sizeof(int); or, if your array is always of the same length: const int count=4; (
const is optional in both cases, but I would recommend it in the second one)for (i=0;i<=count;i++) has to be: for (i=0;i<count;i++) (otherwise you're overriding the array's bounds)Now you've already the code to print out the whole array you've already completed 30% of your homework
Last edited by tux4life; May 16th, 2009 at 6:23 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
To achieve the next milestone in your program (
) the following might help you:
You've to run the loop three times (the number of elements in the array decreased by one)
Every time you display all the elements coming after the element, so if you've 10, you're displaying each time 10+ '20,30,40', for 20 it's the same: 20+ '30,40', and so on
) the following might help you: C Syntax (Toggle Plain Text)
10+20 10+30 10+40 20+30 20+40 30+40
Every time you display all the elements coming after the element, so if you've 10, you're displaying each time 10+ '20,30,40', for 20 it's the same: 20+ '30,40', and so on
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
For the third part:
C Syntax (Toggle Plain Text)
10+20+30 => all elements except the last one 10+20+40 => all elements except the one before the last one 20+30+40 => all elements except the first one 10+20+30+40 => all elements
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
•
•
Join Date: Apr 2008
Posts: 296
Reputation:
Solved Threads: 11
C Syntax (Toggle Plain Text)
#include<stdio.h> #include<conio.h> main() { printf("hello"); int arr[] = {10,20,30,40}; int count=sizeof(arr)/sizeof(int); int i,j; for (i=0;i<count;i++) { printf("%d",arr[i]); printf("\n"); for(j=i+1;j<count;j++) { printf("%d + %d",arr[i],arr[j]); printf("\n"); } } getch(); }
or display all numbers
Last edited by Ancient Dragon; May 16th, 2009 at 8:20 am. Reason: fix code tags
>>but problem is how to make this dynamic??
What do you mean by dynamic?
BTW, do you realize that the code which you have written is no where near to c++?
This is a C code. And you participate in a C++ forum. No doubt you have a red dot on the reputation bar.
C++ is not C. There is a hell lot of difference between these two language.
You should start learning C++. Buy some books like Accelerated C++
and learn the language first.
What do you mean by dynamic?
BTW, do you realize that the code which you have written is no where near to c++?
This is a C code. And you participate in a C++ forum. No doubt you have a red dot on the reputation bar.
C++ is not C. There is a hell lot of difference between these two language.
You should start learning C++. Buy some books like Accelerated C++
and learn the language first.
Siddhant Sanyam
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
![]() |
Similar Threads
- Display problem after installing SUSE 10.2 (*nix Hardware Configuration)
- display problem with diffrent browser. (HTML and CSS)
- Windows ME / Display Problem (Windows 95 / 98 / Me)
- Background display problem...I'ts wierd. (Windows NT / 2000 / XP)
- Help appreciated on a display problem (Windows 95 / 98 / Me)
- Display Problem (Monitors, Displays and Video Cards)
- Bright green display problem (Windows NT / 2000 / XP)
Other Threads in the C Forum
- Previous Thread: Linked list of structs
- Next Thread: Array of Stucts - Printing Strings
Views: 1942 | Replies: 30
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char command convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory dynamic executable fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab win32 windows.h






