Tuesday, 22 July 2014

How To Find Largest Among Few Number Without Using Array..

This Program Will Find Out The Largest Among Few user Given Number. The Numbers Entered By The User Must Be Positive.

#include<stdio.h>
#include<conio.h>
main()
      {
       int a,b,i,n;
       b=0;
       printf("\n\tEnter How Many Number You Want To Enter:==");
       scanf("%d",&n);
       for(i=0;i<n;i++)
                       {
                        input:
                              {
                               printf("\n\tEnter No[%d]:==",i+1);
                               scanf("%d",&a);           
                              }        
                        if(a<0)
                               {
                                printf("\n\tThe Input Was Wrong Number Must Be 0 Or Positive");
                                goto input;        
                               }
                        else
                            {
                             if(a>=b)
                                     {
                                      b=a;              
                                     }   
                            }
                       }
       printf("\n\tThe Largest Number You Have Entered:==%d",b);
       getch();
      }

How To Find Largest Number Among Two Number Without Using If-Else Construct Or Trinary Operator..

This Program Will Find The Largest Among Two Number Without Using If-Else Construct Or Trinary Operator ....


#include<stdio.h>
#include<conio.h>
main()
      {
       int a,b;
       float c;
       printf("\n\tEnter 1st Value:==");
       scanf("%d",&a);
       printf("\n\tEnter 2nd Value:==");
       scanf("%d",&b);
       c=(float)((a+b)/2)+(float)((a-b)/2);
       printf("\n\tThe Largest among %d and %d is %d..",a,b,c);
       getch();
      }

How To Interchange Two Variable Without Using Third Temporaty Variable

This Program Will Interchange The Value Of Two Variables Without Using The Third Temporary Variable..


#include<stdio.h>
#include<conio.h>
main()
      {
       int a,b;
       printf("\n\tEnter 1st Value:==");
       scanf("%d",&a);
       printf("\n\tEnter 2nd Value:==");
       scanf("%d",&b);
       printf("\n\t Before Interchange a=%d\tb=%d",a,b);

       a=a+b;
      b=a-b;
      a=a-b;

      printf("\n\t After Interchange a=%d\tb=%d",a,b);
      getch();
      }

How To Find Sum Of Two Numbers Without Any operator

This Program will add two numbers without using any binary arithmetic operator in c programming language..

#include<stdio.h>
#include<conio.h>
main()
      {
       int a,b;
       printf("\n\tEnter 1st Value:==");
       scanf("%d",&a);
       printf("\n\tEnter 2nd Value:==");
       scanf("%d",&b);
       if(b>=0)
               {
                while(b>0)
                          {
                          a++;
                          b--;
                          }
                }
       else
           {
             while(b<0)
                          {
                          a--;
                          b++;
                          }  
           }
       printf("\n\tThe Addition :==%d",a);
       getch();
      }

Monday, 21 July 2014

Write A Program That Use Multiple Processor In C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace time
{
    class Program
    {
        long sum = 0;
        void showTime()
        {
          Thread.Sleep(1000);
        }
        static void Main(string[] args)
        {

            var program = new Program();
           var startTime = DateTime.Now;
           for(int i=0;i<10;i++)
                  {
                    program.showTime();
                  }
            Parallel.For(0, 10, i =>
                {
                    program.sum += i;
                    program.showTime();
                }
                );         
            Console.Write("\n\tTotal Seconda Taken: "+DateTime.Now.Subtract(startTime).TotalSeconds);
            Console.ReadLine();
        }
    }
}

If  We execute this program using the normal for loop only then the program will take at least 10 secs. But by using Parallel.For() we can access multiple processor cores of our computer and in this program multiple processor is getting accessed by the program..

How To Print Something In C Without Semicolon

#include<stdio.h>
#include<conio.h>
main()
      {
        if(printf("\n\tHello Programmer"))
        getch();
      }

How To Find Greater Number in C Without If Else

#include<stdio.h>
#include<conio.h>
main()
      {
       int a,b;
       printf("\n\tEnter 1st Value:==");
       scanf("%d",&a);
       printf("\n\tEnter 2nd Value:==");
       scanf("%d",&b);
       (a!=b)?((a>b)? printf("\n\ta is greater than b"):printf("\n\ta is less than b")):(printf("\n\ta is equal to b"));
       getch();
      }