Showing posts with label Integer. Show all posts
Showing posts with label Integer. Show all posts

How to Write a C program to perform basic math operations on two input whole numbers. The basic operations are addition, subtraction, multiplication, integer division, real division, and modulus.

Write a C program to perform basic math operations on two input whole numbers. The basic operations are addition, subtraction, multiplication, integer division, real division, and modulus (%)



  1. //Write a C program to perform basic math operations on two input whole numbers. The basic operations are addition, subtraction, multiplication, integer division, real division, and modulus (%).
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x,y;
  7.     cin>>x>>y;
  8.     cout<<"Addition:"<<x+y<<endl;
  9.     cout<<"Subtraction:"<<x-y<<endl;
  10.     cout<<"Multiplication:"<<x*y<<endl;
  11.     cout<<"Integer division:"<<x/y<<endl;
  12.     cout<<"Real division:"<<(float)x/y<<endl;
  13.     cout<<"Modulus"<<x%y;
  14. }

C Program Generates 10 Random Integers Between 0 and 99.

How to write a C Program that Generates 10 Random Integers Number Between 0 and 99 in C Programming Language ?


This C program generates 10 random integers between 0 and 99. 
The srand() function generates a seed value for the rand() function.

Solution For C Program:

Lower-Upper Case/Positive-Negative Integer

How to let C Program to recognize both lower and upper case input. Also Check if input is a positive integer, negative integer in C Programming Language ?


This C Program is to recognize both lower and upper case input. Also Check if input is a positive integer, negative integer in C Programming Language.

Output:

  1. Your input is positive even digit
  2. Your input is negative odd digit
  3. Your input is upper case letter
  4. Your input is lower case letter

Solution :

  1. #include<stdio.h>
  2. #include<string.h>
  3. void main()
  4. {
  5.     char array[20];
  6.     int i;
  7.   for(i=0;i<5;i++){
  8.     gets(array);
  9.   if(strlen(array)==1){
  10.   if(array[i]>=48 && array[i]<=57){
  11.     if(array[i]%2==0)
  12.      printf("Your input is positive even digit\n");
  13.     else
  14.      printf("Your input is negative odd digit\n");
  15.   }
  16.   if(array[i]>=65 && array[i]<=90)
  17.     printf("Your input is upper case letter\n");
  18.   else if(array[i]>=97 && array[i]<=122)
  19.     printf("Your input is lowercase letter\n");
  20.   }
  21.   }
  22. }

Give me an integer and I will sum it with the previous natural numbers

How to write a C Program Give me an integer and I will sum it with the previous natural numbers in C Programming Language ?

This C Program Change an Integer Number with Addition of Previous Natural Numbers.
 
Solution:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int geometric_sum (int a);
  4. int main ()
  5. {
  6.     int a = 0, sum = 0;
  7.     printf("Give me an integer and I will sum it with the previous natural numbers : ");
  8.     scanf("%d", &a);
  9.     sum = geometric_sum(a);
  10.     printf("Result: %d", sum);
  11. }
  12.  
  13. int geometric_sum (int a)
  14. {
  15.     if (a == 0)
  16.     {
  17.         printf("Base case!\n");
  18.         return a;
  19.     }
  20.  
  21.     else
  22.     {
  23.         printf("1: sum (%d)\n", a);
  24.         return a + geometric_sum(a-1);
  25.     }
  26.  
  27. }

Find the union and intersection of two sets of integer store it in two array C Program

How to write a program to find the union and intersection of two sets of integer store it in two array in C Programming Language ?



Solution:
/*write a program to find the union and intersection of two sets of integer store it in two array*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n,b[10],k=0,inter[10],u[10];
int j,m;
clrscr();
printf("\nenter how many number :");
scanf("%d",&n);
printf("\nenter the number;");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nenter the number;");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
{
u[k]=a[i];
k++;
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(b[i]==a[j])
break;
}
if(j==n)
{
u[k]=b[i];
k++;
}
}
m=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i]==b[j])
{
inter[m]=a[i];
m++;
}
}
}
printf("\nthe union is :");
for(i=0;i<k;i++)
{
printf("%d,",u[i]);
}
printf("\nthe intersection is :");

for(i=0;i<m;i++)
{
printf("%d,",inter[i]);
}

getch();
}
/*
enter how many number :4

enter the number;5
8
7
1

enter the number;9
6
5
4

the union is :5,8,7,1,9,6,4,
the intersection is :5,
 */

C Program to Detect int Underflow-Overflow using if-else

How to write a C Program to detect integer overflow-underflow in C Programming Language ?


Solution:
/*Program detect overflow-underflow in C*?
#include<stdio.h>
int main()
{
    unsigned long long int a,b,i;
    while(scanf("%llu",&a)!=EOF)
    {
        if(a<8)
        {
            printf("Underflow!\n");
        }
        else if(a<14)
        {
        b=1;
        for(i=1;i<=a;i++)
        {
            b=b*i;

        }
                       printf("%llu\n",b);
        }
        else
        {
            printf("Overflow!\n");
        }


    }
    return 0;
}

Menu Driven Program to Read Two Integers Find Sum, Difference and Product C Program

How to write C Program a menu driven program to read two integers and find their sum, difference & product in C Programming Language ?



Solution:
/* Write a menu driven program to read two integers & find their sum, difference & product. */

#include<stdio.h>

int main()
{

signed int a[2];
signed int sum,diff,prod;
printf("Enter the two numbers to find sum,difference,product \n");
scanf("%d%d",&a[0],&a[1]);
int option='s';

printf("Enter the character \n 1 -> to find sum \n 2 -> to find difference \n 3 -> to find the product \n ");
scanf("%d",&option);

switch(option)

case 1: {
sum=a[0]+a[1];
printf("the sum of the two numbers is %d \n",sum);
  //break;
}

case 2: {
diff=a[0]-a[1];
printf("the sum of the two numbers is %d \n",diff);
//break;
}

case 3: {
prod=a[0]*a[1];
printf("the sum of the two numbers is %d \n",prod);
//break;
}

default: printf("you have entered the wrong character");

return 0;
}