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



Write a complete program that consists of a function that can receive two numbers from a user (M a..

Answer / nagarajan

#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

Write a complete program that consists of a function that can receive two numbers from a user (M a..

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

Post New Answer

More C Code Interview Questions

main( ) { char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); }

1 Answers  


void main() { int c; c=printf("Hello world"); printf("\n%d",c); }

2 Answers  


respected sir, i did my MCA in 2013 when i am going to attend to an interview i was asked about my project how will i explain my project could please help me in this and my project title is "Social Networking Site For Social Responsibility"

1 Answers   Genpact, Ozdocs,


main() { int x=5; for(;x!=0;x--) { printf("x=%d\n", x--); } } a. 5, 4, 3, 2,1 b. 4, 3, 2, 1, 0 c. 5, 3, 1 d. none of the above

2 Answers   HCL,


main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }

1 Answers  






#define a 10 int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } void foo() { #undef a #define a 50 }

3 Answers  


Write a program to print a square of size 5 by using the character S.

6 Answers   Microsoft,


how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.

0 Answers   Mbarara University of Science and Technology,


main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }

1 Answers  


void main() { int x,y=2,z; z=(z*=2)+(x=y=z); printf("%d",z); }

4 Answers  


what will be the position of the file marker? a: fseek(ptr,0,SEEK_SET); b: fseek(ptr,0,SEEK_CUR);

2 Answers  


what is the code of the output of print the 10 fibonacci number series

2 Answers  


Categories