# A C program to print Values in forward and reversed order – IGNOU MCA Assignment 2014 – 15

By | July 14, 2014

MASTER OF COMPUTER APPLICATIONS
Course Code: MCS-011
Course Title : Problem Solving and Programming
Assignment Number : MCA(1)/011/Assign/2014-15
Maximum Marks : 100
Weightage : 25%

Write an algorithm, draw a corresponding flowchart and write an interactive C program to prompt the user to input 3 integer values and print these values in forward and reversed order, as shown below. Sample Output: Please enter your 3 numbers: 21 35 66 Your numbers forward: 21 35 66 Your numbers reversed: 66 35 21

Pseudo code:

• Input 3 Number
• Initialize I and J to zero
• For Num[I] is less than 3
•               For Num[J] is less than 3
•                        If Num[I]<Num[J]
•                             Swap Num[I] with Num[J]
•                Increment J
•  Increment I
• Print Forward Array using For loop
• Print Reverse Array using For loop

Detailed Algorithm:

Step 1:  Input 3 values in array Num[3]

Step 2: For( I = 0 ; I < 3 ; I++ )

Step 3:       For( J = 0 ; J < 3 ; J++ )

If Num[I]<Num[J]

Swap Num[I] with Num[J]

Step 4:   Print Forward Array using For loop

Step 5:   Print Reverse Array using For loop

Flowchart:

#include<stdio.h>
void main()
{
int i,j,t,num[3];
clrscr();
printf(“Enter three numbers : “);
scanf(“%d%d%d”,&num[0],&num[1],&num[2]);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(num[i]<num[j])
{
t=num[i];
num[i]=num[j];
num[j]=t;
}
}
}
printf(“\nForward : “);
for(i=0;i<3;i++)
printf(“\n %d “,num[i]);
printf(“\nReverse : “);
for(i=2;i>=0;i–)
printf(“\n %d “,num[i]);
getch();
}

Code:

 Source code
```c#include<stdio.h>
void main()
{
int i,j,t,num[3];
clrscr();
printf("Enter three numbers : ");
scanf("%d%d%d",&num[0],&num[1],&num[2]);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(num[i]<num[j])
{
t=num[i];
num[i]=num[j];
num[j]=t;
}
}
}
printf("\nForward : ");
for(i=0;i<3;i++)
printf("\n %d ",num[i]);
printf("\nReverse : ");
for(i=2;i>=0;i--)
printf("\n %d ",num[i]);
getch();
}```

Screen Shots: