Write a complete program that consists of a function that
can receive two numbers
from a user (M and N) as a parameter. Then print all the
numbers between the two
numbers including the number itself. If the value of M is
smaller than N, print the
numbers in ascending flow. If the value of M is bigger than
N, print the numbers in
descending flow. may i know how the coding look like?
Answers were Sorted based on User's Feedback
#include<stdio.h>
void printnum(int,int);
void main()
{
int m,n;
printf("\nEnter the numbers :");
scanf("%d%d",&m,&n);
printnum(m,n);
}
printnum(int m,int n)
{
int i;
if(m>n)
for(i=m;i>=n;i--)
printf(" %d",i);
else if(m<n)
for(i=m;i<=n;i++)
printf(" %d",i);
else //if m and n are equal
printf("%d",m);
}
Is This Answer Correct ? | 6 Yes | 0 No |
Answer / jaycn67
If M = 3, N = 7;
The output is: 3 4 5 6 7
If M = 7, N = 3;
The output is: 7 6 5 4 3.
Is This Answer Correct ? | 0 Yes | 1 No |
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.
Sir... please give some important coding questions asked by product companies..
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.
6 Answers Fusion Systems GmbH,
main() { void swap(); int x=10,y=8; swap(&x,&y); printf("x=%d y=%d",x,y); } void swap(int *a, int *b) { *a ^= *b, *b ^= *a, *a ^= *b; }
main() { int i =0;j=0; if(i && j++) printf("%d..%d",i++,j); printf("%d..%d,i,j); }
Write a program that reads a dynamic array of 40 integers and displays only even integers
main() { extern int i; i=20; printf("%d",i); }
Hi, i have a project that the teacher want a pyramid of numbers in C# or java...when we click a button...the pyramid should be generated in a listbox/or JtextArea...and the pyramid should have the folowing form: 1 232 34543 4567654 567898765 67890109876 7890123210987 890123454321098 90123456765432109 0123456789876543210 Plz help with codes...didn't find anything on the net.
Is the following code legal? typedef struct a { int x; aType *b; }aType
Is the following code legal? struct a { int x; struct a *b; }
How to count a sum, when the numbers are read from stdin and stored into a structure?
union u { struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i; }u; main() { u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l); } a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0