Showing posts with label C-Programming. Show all posts
Showing posts with label C-Programming. Show all posts

C: Sum of two integer numbers.

Question:

Write a program to find the sum of two integer numbers.

Answer:


#include<stdio.h>
int main() {    

    int number1, number2, sum;
    
    printf("Enter First integers: ");
    scanf("%d", &number1);
    
    printf("Enter Second integers: ");
    scanf("%d", &number2);

    // calculating sum
    sum = number1 + number2;      
    
    printf("Sum of two numbers: %d + %d = %d \n", number1, number2, sum);
    return 0;
} 
 


Output is:


In below screen shoot, we have shown that how to compile C file(add.c) and run over linux(Ubuntu)
system.
 

C: Write a program to check whether a given number is integer or float.

 write a program to check whether a given number is integer or float.

C: Write a code for checking if a given input is an integer value or not.

 

Write a code for checking if a given input is an integer value or not.

 

Code

---------------------------------------------------------

#include <iostream>
using namespace std;
bool isNumeric(string str) {
   for (int i = 0; i < str.length(); i++)
      if (isdigit(str[i]) == false)
      return false; //when one non numeric value is found, return false
   return true;
}
int main() {
   string str;
   cout << "Enter a string: ";
   cin >> str;
   if (isNumeric(str))
      cout << "This is a Number" << endl;
   else
      cout << "This is not a number";
}
-------------------------------------------- 
Output

Enter a string: 5687 

This is a Number

Output

Enter a string: deve124

This is not a number

 

C: C-Programming Exercise

C: C-Programming Exercise

In this section, we have placed the list of C programs for doing some basic practices for beginners and experienced. solutions are also provided. please click the link shared below under each questions.

*******************************

1- C program to print pyramid of triangle:

Answer: please click the below link.

Output:


Link:https://draft.blogger.com/blog/post/edit/4414337148028306636/6843421424660007569


2- Write a program to find the element of array.

Answer: please click the below link.

Output is:

Enter size of the  array : 5
Enter elements in array : 12
13
14
16
17
Enter the key : 16
Element 16 found at 3 index of array

 

Link: https://draft.blogger.com/blog/post/edit/4414337148028306636/7929215823725374484


3- Write a program to find the sum of two integer numbers and compile that over linux operation system.

Answer: please click the below link.

 


Output is:


In below screen shoot, we have shown that how to compile C file(add.c) and run over linux(Ubuntu)
system.
 

 

Link: https://draft.blogger.com/blog/post/edit/4414337148028306636/6211307688637386107


4- Write a code for checking if a given input is an integer value or not.

Answer: please click the below link.

Output

Enter a string: 5687 

This is a Number

Output

Enter a string: deve124

This is not a number

 

Link: https://draft.blogger.com/blog/post/edit/4414337148028306636/1343992793524398568


5- 

Answer: please click the below link.

Link: 



C programme to print pyramid of triangle:

  C programme to print pyramid of triangle:

In this blog i am sharing some code, that will print pyramid of triangle and inverse.

1. Pyramid of triangle:

Code:

=====================

#include<stdio.h>

int main() {

    int i, j, rows;

    printf("Enter number of rows: ");

    scanf("%d", &rows);

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

   {

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

       {

                                    printf("*");                                    

                    }

        printf("\n");

    }

    return 0;

}

=====================


Output:







2. Inverted pyramid of triangle:

Code:
======================

#include<stdio.h>

int main(){

                int a,b,c;

                printf("enter the value =");

                scanf("%d",&c);

                for(a=c; a>=1; a--)

                {

                                for(b=1; b<=a; b++)

                                {

                                                printf("*");

                                }

                                printf("\n");

             }

                return 0;             

}

=======================
Output: