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

void main() { int i=10, j=2; int *ip= &i, *jp = &j; int k = *ip/*jp; printf(ā€œ%dā€,k); }

1 Answers  


#include<stdio.h> main() { int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d..%d",*p,*q); }

1 Answers  


how to return a multiple value from a function?

5 Answers   Wipro,


main() { int k=1; printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE"); }

1 Answers  


void main() { int i=i++,j=j++,k=k++; printf(ā€œ%d%d%dā€,i,j,k); }

1 Answers  






#if something == 0 int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }

1 Answers  


main() { int *j; { int i=10; j=&i; } printf("%d",*j); }

9 Answers   HCL, Wipro,


#include <stdio.h> main() { char * str = "hello"; char * ptr = str; char least = 127; while (*ptr++) least = (*ptr<least ) ?*ptr :least; printf("%d",least); }

1 Answers  


main() { int i=-1; +i; printf("i = %d, +i = %d \n",i,+i); }

1 Answers  


write a program to count the number the same (letter/character foreg: 's') in a given sentence.

2 Answers  


main() { int a=2,*f1,*f2; f1=f2=&a; *f2+=*f2+=a+=2.5; printf("\n%d %d %d",a,*f1,*f2); }

6 Answers  


could you please send the program code for multiplying sparse matrix in c????

0 Answers  


Categories