Unit 5-Simple Arthmatics Problams

Positive no negative no.

#include<stdio.h>

#include<conio.h>

void main()

{

int   x;

clrscr();

printf(“enter  the  no”);

scanf(“%d”,&x);

If(x>0)

{

printf(“positive no”);

}

else

{

printf(“negative no”);

getch();

}

.Odd even Program

#include<stdio.h>

#include<conio.h>

void main()

{

int   x;

clrscr();

printf(“enter  the  no”);

scanf(“%d”,&x);

If(x%0)

{

printf(“even  no”);

}

else

{

printf(“odd  no”);

getch();

}

Sum of first n number

#include<stdio.h>

#include<conio.h>

Void main()

{

Int   a,x,sum;

clrscr();

printf(“enter the no”);

for(x=1; x<=10;  x++)

{

scanf(“%d\n”,&a);

}

printf(“sum=%d”,a);

getch();

}

Digit reversing

#include <stdio.h>

int main()

{

int n, reversedNumber = 0, remainder;

printf(“Enter an integer: “);

scanf(“%d”, &n);

while(n != 0)

{

remainder = n%10;

reversedNumber = reversedNumber*10 + remainder;

n /= 10;

}

printf(“Reversed Number = %d”, reversedNumber);

return 0;

}

Table program

#include <stdio.h>

int main()

{

int n, i;

printf(“Enter an integer: “);

scanf(“%d”,&n);

for(i=1; i<=10; ++i)

{

printf(“%d * %d = %d \n”, n, i, n*i);

}

return 0;

}

Factorial sine series

Program code for Cosine Series in C:

Pascal triangle in C

#include <stdio.h>

long factorial(int);

int main()

{

int i, n, c;

printf(“Enter the number of rows you wish to see in pascal triangle\n“);

scanf(“%d”,&n);

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

{

for (c = 0; c <= (n – i – 2); c++)

printf(” “);

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

printf(“%ld “,factorial(i)/(factorial(c)*factorial(i-c)));

printf(“\n“);

}

return 0;

}

long factorial(int n)

{

int c;

long result = 1;

for (c = 1; c <= n; c++)

result = result*c;

return result;

}

Prime number in C

Factor of a number

#include <stdio.h>

int main()

{

int number, i;

printf(“Enter a positive integer: “);

scanf(“%d”,&number);

printf(“Factors of %d are: “, number);

for(i=1; i <= number; ++i)

{

if (number%i == 0)

{

printf(“%d “,i);

}

}

return 0;

}

Such as a prefect number program

#include<stdio.h>

int main(){

int n,i=1,sum=0;

printf(“Enter a number: “);

scanf(“%d”,&n);

while(i<n){

if(n%i==0)

sum=sum+i;

i++;

}

if(sum==n)

printf(“%d is a perfect number”,i);

else

printf(“%d is not a perfect number”,i);

return 0;

}

GCD Using for loop and if Statement

#include <stdio.h>

int main()

{

int n1, n2, i, gcd;

printf(“Enter two integers: “);

scanf(“%d %d”, &n1, &n2);

for(i=1; i <= n1 && i <= n2; ++i)

{

// Checks if i is factor of both integers

if(n1%i==0 && n2%i==0)

gcd = i;

}

printf(“G.C.D of %d and %d is %d”, n1, n2, gcd);

return 0;

}