January 2018

C Program To Find Prime Numbers In An Array And To Calculate The Sum Of Those Prime Numbers

#include<stdio.h>
int main()
{  
    int a[50],count,c,n,i,j,sum=0;  
    printf("Enter the no. of elements:");  
    scanf("%d",&n);    for(i=0;i<n;i++)  
    {      
        scanf("%d",&a[i]);  
    }       
    count=0;  
    printf("\nPrime numbers are:\n");  
    for(i=0;i<n;i++)  
    {           
        c=0;      
        for(j=2;j<a[i];j++)      
        {          
            if(a[i]%j==0)          
            {                  
                c=1;                  
                break;          
            }                   
        }           
        if(c==0)        
        {          
            printf("%d\t",a[i]);          
            sum=sum+a[i];          
            count++;        
        }  
    }  
    printf("\nThe number of prime numbers is %d",count);  
    printf("\nThe sum of prime no. is %d",sum);  
    return 0;
}

Output

C Program To Find Prime Number From Inputted Numbers

C Program To Print Natural Number Up To Which User Asked | C Programming

include<stdio.h> 
int main()
{int i=1,n; printf("Enter the number up to which you want to display.");
scanf("%d",&amp;n);
while (i&lt;=n)
{
printf("%d\t",i);
i++;}
return 0;
}

OUTPUT

C program to print natural number up to which user asked.

C Program To Find Sum Of Individual Digits


#include<stdio.h>
int main()
{     int a, sum;
    printf("Enter the digits: ");
    scanf("%d",&a);
    for(sum=0;a>0;a=a/10)
        sum = sum + (a%10);
    printf("Sum of digits: %d",sum);
    return 0; 
}

Output:-
C program to find sum of individual digits

C program to reverse a number, to print chess board, to find prime number between 1 to n and to print Multiplication table of any numbers up to any terms using for loop | C programming Language


for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
Syntax
The syntax of a for loop in C programming language is −
for ( init; condition; increment ) {
   statement(s);
}
Here is the flow of control in a 'for' loop −
  • The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears.
  • Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and the flow of control jumps to the next statement just after the 'for' loop.
  • After the body of the 'for' loop executes, the flow of control jumps back up to the increment statement. This statement allows you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the condition.
  • The condition is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then increment step, and then again condition). After the condition becomes false, the 'for' loop terminates.


C program to reverse a number using for loop


#include &lt;stdio.h&gt; int main () { int a; /* for loop execution */ for( a = 10; a &lt; 20; a = a + 1 ){ printf("value of a: %d\n", a); } return 0; }


C program to Print Chess 

#include&lt;stdio.h&gt; 
#include&lt;conio.h&gt;
int main()
{
int i,j,num;printf("Enter the number : ");
scanf("%d",&amp;num);
for(i=0;i&lt;num;i++)
{
for(j=0;j&lt;=num;j++)
{
printf("%c",219);//219 is the ASCII cose for whiteprintf(" ");
}printf("\n");
if(i%2==0)
{
printf("%c",255);//255 is the ASCII cose for white} } return 0; }

C program to Find Prime Number between 1 to n

#include&lt;stdio.h&gt; int main() {   int  n,i,j,count;   printf("Enter the Number:");   scanf("%d",&amp;n);   printf("Prime number between %d to %d are\n",1,n); for(i=2;i&lt;=n;i++) { count=1; for (j=2;j&lt;=i/2;j++) {if (i%j==0) {count=0; break; } } if(count==1) {printf("%d  ",i);} } return 0;
}

C Program to print Multiplication table of any numbers up to any terms


#include&lt;stdio.h&gt;

int main()
{
int n1,n2,i;
printf("Enter the number:");
scanf("%d",&amp;n1);
printf("Enter the term up to which you want to multiply:");
scanf("%d",&amp;n2);
for(i=1;i&lt;=n2;i++)
{
printf("%d X %d = %d\n",n1,i,n1*i);
}
return 0;
}

OUTPUT





C Program To Find Prime Number Between 1 To N

#include<stdio.h>
int main()
{
    int  n,i,j,count;
    printf("Enter the Number:");
    scanf("%d",&n);
    printf("Prime number between %d to %d are\n",1,n);
    for(i=2;i<=n;i++)
    {
        count=1;
        for (j=2;j<=i/2;j++)
        {
            if (i%j==0)
            {
                count=0;
                break;
            }
        }
    if(count==1)
    {
        printf("%d  ",i);
    }
    }
    return 0;
}

OUTPUT
C Program To Find Prime Number Between 1 To N

C Program To Print Chess Board

#include<stdio.h>

int main()

{

    int i,j,num;

    printf("Enter the number : ");

    scanf("%d",&num);

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

    {

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

        {

            printf("%c",219);//219 is the ASCII cose for white

            printf(" ");

        }

        printf("\n");

        if(i%2==0)

        {

            printf("%c",255);//255 is the ASCII cose for white

        }

    }

    return 0;

}

OUTPUT

C Program To Print Chess Board