Here is my problem, I can't figure out this simple tasking job. here it is
Problem #1
Ask the user for a number(1-5), say X. Check for input validity. In cases of an invalid input, continuously ask the user to enter a number until he finally enters a valid one. Print the numbers from1 to X for each row starting from row 1 to row X. (It is required to use looping constructs)
sample run:
Enter a number (1-5):0
0 is an invalid entry. Try another.
Enter a number (1-5): 3
row 1: 1 2 3
row 2: 1 2 3
row 3: 1 2 3
here's my problematic code for that problem:
Code:
#include<stdio.h>
int main (void)
{ int num;
do {
printf("Enter a number (1-5):");
scanf("%d", &num);
if((num<1)||(num>5))
printf("%d is an invalid entry. Please enter another one.\n", num);
} while ((num<1)||(num>5));
for(int i=0; i<1; i++){
printf("\nrow%d", i+1);
for(int j=0; j<0; j--){
printf("%d", j+1);
}
}
return 0;
}
PROBLEM 2:
write a program that continually asks the user to enter an integer until he/she enters the number 0. Display the maximum of these numbers and the number of times it appeared.
Sample run:
Enter a number: 2
Enter a number: 3
Enter a number: 5
Enter a number: 1
Enter a number: 8
Enter a number: 8
The largest number is 8 and it was entered 2 time(s).
here is my sample problematic program
Code:
#include<stdio.h>
int main(void)
{
int a, i, m, j, n;
printf("enter a number: ");
scanf("%d", &number1);
max=count+1;
count=1;
void largest(int a[][MAXCOLS],int m,int n)
{
int i,j,largest;
largest = a[0][0];
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
if (a[i][j]>largest)
largest=a[i][j];
}
}
printf("
The largest element of the matrix is %d",largest);
printf("\n\nThe largest number is %d and it appeared %d time(s).", max, count);
return 0;
}
by noobprogrammer