Skip to main content

Basic Example Of C



C Program to check whether the given integer is positive or negative 

/* Description: A program to check whether the input
 * integer number is positive or negative. 
 * Written by: Santosh Asole
 */
#include <stdio.h>
 
void main()
{
    int num;
 
    printf("Enter a number: \n");
    scanf("%d", &num);
    if (num > 0)
        printf("%d is a positive number \n", num);
    else if (num < 0)
        printf("%d is a negative number \n", num);
    else
        printf("0 is neither positive nor negative");
}

Output 1:

Enter a number:
0
0 is neither positive nor negative

Output 2:

Enter a number:
-3
-3 is a negative number

Output 3:

Enter a number:
100
100 is a positive number

Program to find largest of three input numbers


#include<stdio.h>
int main()
{
   int num1,num2,num3;
   
   //Ask user to input any three integer numbers
   printf("\nEnter value of num1, num2 and num3:");
   //Store input values in variables for comparsion
   scanf("%d %d %d",&num1,&num2,&num3);

   if((num1>num2)&&(num1>num3))
      printf("\n Number1 is greatest");
   else if((num2>num3)&&(num2>num1))
      printf("\n Number2 is greatest");
   else
      printf("\n Number3 is greatest");
   return 0;
}

Output:

Enter value of num1, num2 and num3: 15 200 101
 Number2 is greatest

Comments

Popular posts from this blog

The main Function

         The main Function The main is a part of every C program. C permits diferent forms of main statement. Following forms are allowed. main() int main void main() main(void) void main(void) int main(void) The empty pair of parentheses indicates that the function has no arguments. This may be explicitly indicated by using the keyword void inside the parentheses. We may also specify the keyword int or void before the word main . The keyword void means that the function does not return any information to the operating system and int means that the function retúrns an integer value to the operating system.   When int is specified, the last statement in the program must be "return O" . For the sake of simplicaty, we use the first form in our program. Example:                                  // Programm of Addition       // Written by Santosh Asole           #include<stdio.h>      main ()      {     int  x, y, z;       x=10;

What is Array

  Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. A specific element in an array is accessed by an index. All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. How to make picture puzzle using JavaScript Declaring Arrays To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows − type arrayName [ arraySize ]; This is called a  single-dimensional  array. The  arraySize  must be an integer constant