Sunday, 10 April 2016

C and C++ Program to Check if a given Integer is Positive or Negative Problem Solution.


C Solution:

#include <stdio.h>
 /*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
void main(){

    int number;

    printf("Enter a number: ");
    scanf("%d", &number);
    if (number < 0) printf("%d is a negative number.\n", number);
    else printf("%d is a positive number.\n", number);
}


C++ Solution:

#include <iostream>
using namespace std;
 /*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){
    int num;

    cout << "Enter a number: ";
    cin >> num;
    if (num < 0) cout << num << " is a negative number." << endl;
    else cout << num << " is a positive number." << endl;
    return 0;
}

No comments:

Post a Comment