Posts

Showing posts from February 11, 2018

C Program To Count Number Of Positive And Negative Number | C Programming

Image
C Program To Count Number Of Positive And Negative Numbers #include <stdio.h>         int main () {           int a [ 50 ],n,count_neg= 0 ,count_pos= 0 ,i;             printf ( "Enter the size of the array \n " );           scanf ( " %d " ,&n);           printf ( "Enter the elements of the array \n " );         for (i= 0 ;i < n;i++)               scanf ( " %d " ,& a [i]);           for (i= 0 ;i < n;i++)         {                     if ( a [i] < 0 )                               count_neg++;                   else                             count_pos++;             }           printf ( "There are %d negative numbers in an array \n " ,count_neg);             printf ( "There are %d positive numbers in an array \n " ,count_pos);   return 0 ; }    Output For Above Program

C program to print the number in ascending order using function (passing array function)

Image
#include<stdio.h> #define SIZE 100 void reorder (int, int[]); int main() { int i,n,x[SIZE]; printf("How many numbers?"); scanf("%d",&n); //read the list of numbers for(i=0;i { printf("x[%d]=",i+1); scanf("%d",&x[i]); } //record all array elements reorder(n,x); //display the re- order list of number for(i=0;i { printf("\nx[%d]=%d\n",i+1,x[i]); } return 0; } void reorder(int n,int x[]) { int i,item,temp; for(item=0;item { for(i=item+1;i { if (x[i] { //inter change two elements temp = x[item]; x[item]=x[i]; x[i]=temp; } } } } OUTPUT

C Program To Find Maximum And Minimum Value Using Array | C Programming

Image
C program to find maximum and minimum values within a defined array of numbers. #include <stdio.h> int main () {   int i , n , max = 0 , min = 0 , a [ 100 ];   printf ( "Enter a number: " );   scanf ( " %d " , & n );   printf ( "Enter numbers in array: \n " );   for ( i = 0 ; i < n ; i ++)   {     scanf ( " %d " , & a [ i ]);   }   min = a [ 0 ];   max = a [ 0 ];   for ( i = 0 ; i < n ; i ++)   {     if ( a [ i ] > max )     {       max = a [ i ];     }     if ( a [ i ] < min )     {       min = a [ i ];     }   }   printf ( "The largest number is %d \n " , max );   printf ( "The smallest number is %d \n " , min );   return 0 ; } Output

Operators in C Programming and Its Types | C Programming Language

Image
Operators in C Programming: - An operator in general is a symbol that operates on a certain data types. An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. The types of operators are: - Arithmetic Operators in C Programming-:              The arithmetic operators performs arithematic operations. The arithmetic operator is given below:- (+) - Addition (-) -Subtraction (*)- Multiplication (/)- Division (%) - Modulo Division   Relational operators in C Programming:-             Relational operators are used to compare logical, arithmetic and character expression. A list of relational operators is give below:- (<)             Less than (>)            Greater than (< =)          Less than or equal to (> =)         Greater than or equal to (==)              Equal to (! =)              Not equal to Logical Operators in C Programming: -             An expression logical operator retur

C Program To Find Factorial Using Function | C programming

Image
 C Program To Find Factorial Using Function #include <stdio.h> long int fact ( int ); int main () {   int n ;   printf ( "Enter number: " );   scanf ( " %d " , & n );   printf ( " %d != %ld \n " , n , fact ( n )); } long int fact ( int n ) {   if ( n <= 1 )     return 1 ;   else     return ( n * fact ( n - 1 )); } Output

Functions | Recursion Function in C Programming | Types of Functions | Calling Function | Function Arguments | C Programming

Image
Functions                     A function is a self-contained program segment that carries out same specific well defined task.                 In other words, a number of statements grouped into a single logical unit is referred to as a function.                 A function will have carried out its intended action whenever it is accessed (i.e. wherever the function is “called”) from some other portion of the program.                 Some function can be accessed from several different places with in a program. Once the function has carried out its intended action control will be returned to the point from which function was accessed.                 Generally, a function will process information i.e. Passed to it from the 1’calling” function of the program and return a single value.                 Information is passed to the function via special identifiers called “arguments” (also called parameters) and return via the return statement.    A function  decl