Jump to content

User404 - Beginner Challenge #1


user404

Recommended Posts

Hello!

I'm learning C, so I'll be posting the problems I'm solving here, join in if you want and post your solutions in your favorite language. :smile:

Challenge 1:

Write a program that reads numbers, until it reads 0, and then outputs them in reverse order.

Solution:

#include <stdio.h>

#define MAX 100

int main(void){
  int matrix[MAX];
  int num, i=0;

  printf(" Input at most %d integers, stop with 0\n", MAX);
  do{
    printf(" number[%d] = ", i); scanf("%d", &num);
    if(num==0) break;
    matrix[i]=num;
    i++;
  } while( i< MAX );

  while(i--) printf(" %d", matrix[i]);

  printf("\n");

  return 0;
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...