Friday, June 10, 2016

Write an algorithm to add given two numbers.

Problem Definition: Write an algorithm to add given two numbers.

Step 1: Start.

Step 2: Read two numbers A and B.

Step 3: Total = A+B.

Step 4: Display Total.


User input validation to check a number.


//User input validation to check a number.

#include<stdio.h>
int main()
{
char chr;
printf("Enter a number: ");
scanf("%c",&chr);

if(isdigit(chr))
printf("It is a number.");
else
printf("It is not a number.");
 return 0;
}

//Output 1
Enter a number: 5
It is a number.

//Output 2
Enter a number: a
It is not a number.

Storing New Line character (\n) as a user input data.


//Storing New Line character (\n) as a user input data.

#include<stdio.h>
int main()
{
char mydata[100];
printf("Enter your details: \n");
printf("Press * and Enter to exit input mode..\n");
scanf("%[^*]", mydata);
printf("%s", mydata);
 return 0;
}

Output of program

Enter your details:
Press * and Enter to exit input mode..
Hello
Student
*
Hello
Student



Draw flowchart to display Good morning message based on given time.

Draw flowchart to check negative number.

Draw flowchart to check Positive Number.

Draw Flowchart to check Odd or Even Number.

Odd Even Flowchart

Following flowchart will read a number from user. This number is checked using % operator to find whether it is odd or even.

Odd Even Number Flowchart
Figure: Flowchart to check Odd or Even Number