C - INTRO - PART003

  ID:6133 Print A to B(Using While Loop)


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int A,B;

    scanf("%d%d ",&A,&B);

    while(A<B+1){

        printf("% d",A);

        A++;

    }


}

ID:6116 Print 1 to 500 (Using While Loop)


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int i=1;

    while(i<501)

    {

        printf("% d",i);

        i++;

    }


}

ID:6139 Print B to A(Using While Loop)


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int A,B;

    scanf("%d%d ",&A,&B);

    while(A<B+1){

        printf("% d",B);

        B--;

    }


}

ID:6150 Break the Inifinite Loop


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int i=1;

    while(i<50){

        printf("% d",i);

        i++;

    }


}

ID:6142 Print Odd Numbers from A to B


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int A,B;

    scanf("%d%d ",&A,&B);

    while(A<B+1){

        if(A%2!=0){

            printf("% d",A);

        }

        A++;

    }

    

}

ID:6140 Print Even Numbers from A to B


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int A,B;

    scanf("%d%d ",&A,&B);

    while(A<B+1){

        if(A%2==0){

            printf("% d",A);

        }

        A++;

    }


}

ID:6134 Sum of Digits in N


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int N,sum=0,m;

    scanf("%d",&N);

    while(N>0){

        m=N%10;

        sum+=m;

        N=N/10;

        

    }

    printf("%d",sum);

    return 0;


}

ID:6136 Count of Digits in N


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int N,count=0;

    scanf("%d",&N);

    while(N!=0){

        count++;

        N=N/10;

    }

    printf("%d",count);


}

ID:6132 Reverse the Digits of N


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int N,r,sum=0;

    scanf("%d",&N);

    while(N>0)

    {

        r=N%10;

        sum=(sum*10)+r;

        N=N/10;

    }

    printf("%d",sum);

    return 0;

    


}

ID:6138 X Power of Y


#include<stdio.h>

#include<math.h>


int main()

{

    int X,Y,result;

    scanf("%d%d ",&X,&Y);

    result=pow((double)X,Y);

print("%d",result);

return 0;


}

ID:6147 Print the Largest digit


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int N,large=0,temp=0;

    scanf("%d",&N);

    while(N>0)

    {

        temp=N%10;

        if(temp>large){

           large=temp;

        }

        N=N/10;

    }

    printf("%d",large);

    return 0;


}


ID:6156 Count the Occurrences of 1

#include <stdio.h>
 
int main()
{
    int num,tNum,digit,cnt;
    int rem;
 
    scanf("%d",&num);
 
    cnt=0;
    tNum=num;
 
    while(tNum>0)
    {
        rem=tNum%10;
        if(rem==1)
            cnt++;
        tNum/=10;
    }
 
    printf("%d",cnt);
     
    return 0;
}

ID:6145 Smallest Even Digit


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int N,small=10,temp=0;

    scanf("%d",&N);

    while(N>0)

    {

        temp=N%10;

        if(temp<small && temp%2==0){

            if(small%2==0)

                {

                    small=temp;

                }

        }

        N=N/10;

    }

    printf("%d",small);

    return 0;


}


ID:6151 Smallest of N Numbers


#include<stdio.h>

#include<stdlib.h>



int main()

{

    int a[30],i,num,smallest;

    scanf("%d",&num);

    

    for(i=0;i<num;i++)

        scanf("%d",&a[i]);

        

    smallest = a[0];

    

    for(i=0;i<num;i++)

    {

        if(a[i]<smallest)

        {

            smallest = a[i];

        }

    }

    

    printf("%d",smallest);

    return 0;

        

   }


ID:6148 Check First and Last Digits are Same


#include<stdio.h>

#include<math.h>


int main()

{

    int Number,count;

    scanf("%d",&Number);

    

    count=log10(Number);

    int firstdigit = Number/pow(10,count);

    int Lastdigit =Number%10;

    if(firstdigit==Lastdigit)

    {

        printf("YES");

    }

    else{

        printf("NO");

    }

    

}

ID:6152 Print Integers Until 10 is encountered


#include<stdio.h>

#include<stdlib.h>


int main(){

    int a;

    while(scanf("%d",&a)>0)

    {

        if(a==10)

            break;

        else

            printf("%d ",a);

    }

}



ID:6149 Find Largest Odd Integer


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int a[100],mo,n,i;

    scanf("%d",&n);//enter the size of the array

    for(i=0;i<n;i++)

        scanf("%d",&a[i]);//read the array element

        

    for(i=0;i<n;i++)

    {

        if(a[i]%2==0)

            continue;

        mo=a[i];

        break;

    }

    for(;i<n;i++)

    {

        if(a[i]%2!=0 && a[i]>mo)

            mo=a[i];

    }

    printf("%d",mo);

    return 0;

}


ID:6157 Print Odd Integers Until 10 is Encountered


#include<stdio.h>

int main()

{

    int N;

    while(1){

        scanf("%d", &N);

    if(N==10)

        break;

    if(N%2!=0)

        printf("% d",N);

    }

    return 0;

}

ID:6155 Print Numbers Divisible by 5 Until 10 is Encountered


#include<stdio.h>

#include<stdlib.h>


int main()

{

    int N;

    while(1)

    {

        scanf("%d",&N);

        if(N==10)

            break;

        if(N%5==0)

            printf("% d",N);

    }


return 0;

}

ID:6154 Print Sum of Integers Until 10 is encountered


#include<stdio.h>

int main()

{

int a,temp,sum=0;

while(1)

{

scanf("%d",&a);

temp=a;

if(temp==10)

break;

else

sum=sum+temp;

}

printf("%d",sum);

}


Comments

Popular posts from this blog

alphabet matrix minimum sum path

C--Starter-part007---skillrack