Looping in C Programming

Write a program to demonstrate all the Looping Structure in C

4 comments:

  1. #include
    #include

    int add(int a);
    int Fabonacci(int shohan);
    int funcx(int p,int q);

    int main()
    {
    int n,result,p=0,q,m,result1,result2,a,b;
    printf("\nA SIMPLE PROGRAMME DONE BY SHOHAN(201320335)");

    printf("\n \t WELCOME TO THREE LOOP SERVICE");
    printf("\n\n\t \tFIRST LOOP");
    printf("\n How many number you want to calculate:");

    scanf("%d",&n);
    result=add(n);
    printf("\n The sum is %d",result);

    printf("\n\n\t\tSECOND LOOP");
    printf("\n\t\tFABONACCI SERIES");
    printf("\n Enter number for fabonacci series:");

    scanf("%d",&m);
    q=1;
    while(q<=m)
    {
    printf("\n%d",Fabonacci(p));
    p++;
    q++;
    }


    printf("\n\tTHIRD LOOP:");
    printf("\n\t EVOLUATE SUM:");
    printf("\n Enter the value:");

    scanf("\n %d",&a);
    printf("\n Enter the limit:");

    scanf("\n %d",&b);
    result2=funcx(a,b);

    printf("\n The sum is %d",result2);

    getch();
    return 0;


    }

    int add(int a)
    {
    int i,x,sum=0;
    for(i=1;i<=a;i++)
    {
    printf("\n Enter your values:");

    scanf("%d",&x);
    sum+=x;
    }
    return sum;
    }


    int Fabonacci(int shohan)
    {
    if(shohan==0)
    return 0;
    else if(shohan==1)
    return 1;
    else
    return (Fabonacci(shohan-1)+ Fabonacci(shohan-2));
    }


    int funcx(int p,int q)
    {
    int a,sum=0,i;
    a=p;
    i=1;
    do
    {
    if(i==1)
    printf("\n%d+",p);
    else if(i==q)
    printf("%d^%d",p,i);
    else
    printf("%d^%d+",p,i);
    sum+=a;
    a=a*p;
    i++;
    }while(i<=q);
    return sum;
    }

    ReplyDelete
  2. #include
    main()
    {
    printf(" SUM OF ALL NUMBER FROM AN ARRAY");
    printf("\n USE 'FOR' LOOP : ");
    int n,j,c,k,l;
    printf("\n\nArray size is : ");
    scanf("%d",&n);
    int a[n];
    array(a,n);


    printf("\n\n FIND OUT 'EVEN NUMBER' AND 'ODD NUMBER' FROM RANGE ");
    printf("\n USE 'WHILE' LOOP : ");
    printf("\n\nEnter your start value : ");
    scanf("%d",&c);
    printf("\nEnter your end value : ");
    scanf("%d",&k);
    evenodd(c,k);

    printf("\n\n CHECK THE DIGIT IS 'PERFECT' OR 'NOT PERFECT' ");
    printf("\n USE 'DO WHILE' LOOP : ");
    printf("\n\nEnter your number : ");
    scanf("%d",&l);
    checkperfect(l);

    printf("\n\n ''END''\n\n");
    }

    int array(int b[],int n)
    {
    printf("\nValues of Array :\n");
    int i,sum=0;
    for(i=0;i<n;i++)
    {
    scanf("%d",&b[i]);
    sum+=b[i];
    }
    printf("\nSum of Array :%d",sum);
    }

    int evenodd(int x,int y)
    {
    int f=x;
    printf("\n\nEven numbers are :");
    while(f<=y)
    {
    if(f%2==0)

    {
    printf("\n%d",f);
    }
    f++;
    }
    odd(x,y);
    }

    int odd(int xp, int yp)
    {
    int f=xp;
    printf("\n\nOdd numbers are :");

    while(f<=yp)
    {
    if(f%2!=0)
    {
    printf("\n%d",f);
    }
    f++;
    }
    }

    int checkperfect(int l)
    {
    int d=1,sum=0;
    do
    {
    if(l%d==0)
    {
    sum+=d;
    }
    d++;
    }
    while(d<=l/2);

    if(sum==l)
    printf("\n Perfect Number \n");
    else
    printf("\n Not Perfect Number \n");
    }

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. #include
    #include

    int add(int a);
    int Fabonacci(int mennath);
    int funcx(int p,int q);

    int main()
    {
    int n,result,p=0,q=1,m,result1,result2,a,b;
    printf("\nA SIMPLE PROGRAMME DONE BY MHM");

    printf("\n \t WELCOME TO MANY LOOP SERVICE");
    printf("\n\n\t \t1st LOOP");
    printf("\n How many number you want to calculate:");

    scanf("%d",&n);
    result=add(n);
    printf("\n The sum is %d",result);

    printf("\n\n\t\t2nd LOOP");
    printf("\n\t\tFABONACCI SERIES");
    printf("\n Enter number for fabonacci series:");

    scanf("%d",&m);

    while(q<=m)
    {
    printf("\n%d",Fabonacci(p));
    p++;
    q++;
    }
    printf("\n\tTHIRD LOOP:");
    printf("\n\t EVOLUATE SUM:");
    printf("\n Enter the value:");

    scanf("\n %d",&a);
    printf("\n Enter the limit:");

    scanf("\n %d",&b);
    result2=funcx(a,b);

    printf("\n The sum is %d",result2);

    getch();
    return 0;

    }
    int add(int a)
    {
    int i,x,sum=0;
    for(i=1;i<=a;i++)
    {
    printf("\n Enter your values:");

    scanf("%d",&x);
    sum+=x;
    }
    return sum;
    }

    int Fabonacci(int shohan)
    {
    if(shohan==0)
    return 0;
    else if(shohan==1)
    return 1;
    else
    return (Fabonacci(shohan-1)+ Fabonacci(shohan-2));
    }

    int funcx(int p,int q)
    {
    int a,sum=0,i;
    a=p;
    i=1;
    do
    {
    if(i==1)
    printf("\n%d+",p);
    else if(i==q)
    printf("%d^%d",p,i);
    else
    printf("%d^%d+",p,i);
    sum+=a;
    a=a*p;
    i++;
    }
    while(i<=q);
    return sum;
    }

    ReplyDelete