C programming exams

This is a discussion on C programming exams within the C Programming forums, part of the General Programming Boards category; Greetings everyone, I have a C programming exams tomorrow and was wondering if anyone know some sites where I can ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    14

    C programming exams

    Greetings everyone,

    I have a C programming exams tomorrow and was wondering if anyone know some sites where I can find some worked out assignment, or solutions to exams papers or even additional exercise, that will help me in my revision. The topics I need include:

    - prinft and scanf in C
    - using if and else
    - using loops
    - arrays (basic)

    Thanks for any help...

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    14

    Re: C programming exams

    Hi Salem,

    Thanks for your reply... howstuffworks.com has tutorials only. As I mentioned, I'm looking for some online excercise/past exams/assignments on C, that will help me in my revision.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    75
    look at getaclass.com, from there in research papers there is COSC 1420, they have some exams

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    14
    Hi there,

    Thanks a lot for the links... That's what I was looking for! If you know more sites that have these sort of exams papers let me know...

    Btw, while reviewing one of the questions on another site, I came up with a prob that asks me to display the following using loops:

    ----1----
    ---2-2---
    --3-3-4--
    -4-4-4-4-
    5-5-5-5-5

    Any idea how this can be achived?

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    38
    Do you have to display the dashes ( '-' ), and is there a limit to the numbers of the binary tree like structure?
    You d certainly use a for loop of some kind I believe. Knowing a limit would make it easier for sure!
    Cheers,
    Johannes

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    75
    this is extremely crude...lol....but i am sure you can improvise on it:-

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
    	int y=0;
    	char t='-';
    
    	for(y=1;y<=5;y++)
    	{
    		switch(y)
    		{
    		case 1: printf("%c%c%c%c%d%c%c%c%c\n",t,t,t,t,y,t,t,t,t);
    			break;
    		case 2: printf("%c%c%c%d%c%d%c%c%c\n",t,t,t,y,t,y,t,t,t);
    			break;
    		case 3: printf("%c%c%d%c%d%c%d%c%c\n",t,t,y,t,y,t,y,t,t);
    			break;
    		case 4: printf("%c%d%c%d%c%d%c%d%c\n",t,y,t,y,t,y,t,y,t);
    			break;
    		case 5: printf("%d%c%d%c%d%c%d%c%d\n",y,t,y,t,y,t,y,t,y);
    			break;
    		default: break;
    		}
    	}
    
    	system("PAUSE");
    	return 0;
    	
    
    }

  7. #7
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    >Any idea how this can be achived?
    You can do it a bunch of ways. It's a bit more challenging if you have to have all of the dashes like in your post. Here's one way:
    Code:
    #include <stdio.h>
    
    static void drawLine(int nlead, char lead, int nfill, char fill)
    {
        int i;
    
        for (i = 0; i < nlead; i++)
            putchar(lead);
    
        /*
         * Print fill characters with every other
         * character being lead (e.g. 4-4-4-4)
         */
        for (i = 0; i < nfill; i++)
        {
            putchar(fill);
    
            if (i < nfill - 1)
                putchar(lead);
        }
    
        for (i = 0; i < nlead; i++)
            putchar(lead);
    
        putchar('\n');
    }
    
    int main(void)
    {
        int nlead = 0;   /* Number of leading characters */
        int nfill = 1;   /* Number of fill characters (pyramid) */
        char lead = '-'; /* Leading character to print */
        char fill = '1'; /* Pyramid character to print */
    
        printf("Enter the number of lines (Under 10): ");
        fflush(stdout);
    
        if (scanf("%4d", &nlead) != 1 || nlead > 9)
            fprintf(stderr, "Invalid input\n");
        else
        {
            while (--nlead >= 0)
                drawLine(nlead, lead, nfill++, fill++);
        }
    
        return 0;
    }
    p.s. What the alphabet would look like without q and r.

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Any idea how this can be achived?
    Why not try doing it yourself, then post your code when you have trouble with it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Xei
    Xei is offline
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719
    Originally posted by shain
    Hi there,

    Thanks a lot for the links... That's what I was looking for! If you know more sites that have these sort of exams papers let me know...

    Btw, while reviewing one of the questions on another site, I came up with a prob that asks me to display the following using loops:

    ----1----
    ---2-2---
    --3-3-4--
    -4-4-4-4-
    5-5-5-5-5

    Any idea how this can be achived?
    Code:
    #include <windows.h>
    #include <malloc.h>
    #include <iostream.h>
    
    void DrawCrap(int Dashes, char **CharStuff);
    
    int main()
    {
    	char *SomeChars;
    	DrawCrap(17,&SomeChars);
    	cout << SomeChars;
    	free(SomeChars);
    	return 0;
    }
    
    void DrawCrap(int Dashes, char **CharStuff)
    {
    	//Dashes must be an ODD number!
    	char *cPointer=NULL;
    	char *cNumber=NULL;
    	int Lines=0;
    	int cLine=0;
    	int cIndex=0;
    	Lines = (((Dashes-1)/2)+1);
    	cPointer = (char *)calloc((Dashes*Lines*2)+(2*Lines)+1+500, sizeof(char)); //Only meant to lazily allocate enough space.
    	if(cPointer == NULL)
    	{
    		MessageBox(NULL, "Error allocating memory!","Error",MB_OK);
    		return;
    	}
    	ZeroMemory(cPointer, ((Dashes*Lines)+(2*Lines)+1));
    	cNumber = (char *)calloc(3, sizeof(char));
    	if(cNumber == NULL)
    	{
    		MessageBox(NULL, "Error allocating memory!","Error",MB_OK);
    		return;
    	}
    	do
    	{
    		//Add Dashes:
    		for(int i=0;i<Dashes;i++)
    		{	
    			cPointer[cIndex+i] = '-';
    		}
    		//Find starting Number-Index for this line:
    		cIndex += ((Dashes+1)/2) - cLine - 1;
    		//Add Numbers Between Dashes:
    		for(int x=0;x<(cLine+1);x++)
    		{
    			ZeroMemory(cNumber, 3);
    			itoa((cLine + 1),cNumber,10);
    			for(int y=0;y<(int)strlen(cNumber);y++)
    			{
    				cPointer[cIndex+y] = cNumber[y];
    				if(y == (int)(strlen(cNumber)-1))
    				{
    					cIndex += y;
    				}
    			}
    			if(x != cLine)
    			{
    				cIndex +=2;
    			}
    		}
    		//Add CRLF, and set cIndex accordingly.
    		strcat(cPointer, "\r\n");
    		cLine++;
    		//cIndex = (cLine * Dashes)+(2 * cLine);
    		cIndex = strlen(cPointer);
    	}while(cLine != (Lines));
    	ZeroMemory(cNumber, 3);
    	free(cNumber);
    	*CharStuff = cPointer;
    	return;
    }
    That code is only meant to go from rows 1 to 9, although it can fit a 10th that is missing a dash at the end. I stick to Win32 applications, not consoles so forgive me if you wanted another method.
    Last edited by Xei; 05-19-2003 at 10:54 PM.
    "What are you after - the vague post of the week award?" - Salem
    IPv6 Ready.
    Travel the world, meet interesting people...kill them.
    Trying to fix or change something, only guaruntees and perpetuates its existence.
    I don't know about angels, but it is fear that gives men wings.
    The problem with wanting something is the fear of losing it, or never having it. The thought makes you weak.

    E-Mail Xei

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cobwebs in head
    By jmonster in forum C Programming
    Replies: 14
    Last Post: 07-14-2007, 10:39 PM
  2. Exams tommorrow! OMG! AHHH!!
    By face_master in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 12-06-2002, 09:58 PM
  3. C++ Certification Exams...
    By sguruprasanna in forum C++ Programming
    Replies: 1
    Last Post: 08-02-2002, 12:08 PM
  4. Free C++ Exams...
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2002, 03:06 AM
  5. Free C++ Exams...
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 07-23-2002, 02:40 AM

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