I need to take as input positive integers 1-100. Each of those numbers will be the first element in series. The series will be formed by a specified formula, in case of pair integer- set 1 & case of uneven integer- set 2. Then of course print it.
I'm not quit sure about the syntax of this code & also compiler through me with many errors & warnings. Cannot seem to find why!
Please review it and have your notes.
TIACode:: #include<stdio.h> #define N 5 #define M 5 void seri(int A[][M],int *,int *); int main ( void ) { int A[N][M],*p,*n=0; p=A; printf ("\nenter numbers from 1 to 100\n"); scanf ("%d", p); if(*p<1||*p>100) { puts(" Number is too big/ too small. Try again!"); } else { while (*p!=-1) { for (p=A;p-A<M;p++) { puts ("next number:"); scanf ("%d", p++); seri(A,n,p); } } void seri(int A[N][M],int *n,int *p) { int t; for (p=A;p-A>=1;p++) { if (*p%2==0) *p= *p/2; else { *p=3*(*p)+1; } n=p-A; } printf("n= %d. seri is :", n); for (t=0;t<=n;t++) printf(" %d\n", *p); } }
Ronen



LinkBack URL
About LinkBacks



Just use > and print the last number outside of the loop: