Advantages of C
- Fast, Powerful & efficient
- Easy to learn.
- It is portable
- ''Mid-level'' Language
- Widely accepted language
- Supports modular programming style
- Useful for all applications
- C is the native language of UNIX
- Easy to connect with system devices/assembly routines
Print Integer
#include < stdio.h >
int main()
{
int a;
printf("Enter an integer\n");
scanf("%d", &a);
//takes an integer from user
printf("Integer that you have entered is %d\n", a);
return 0;
}
Addition of two no
#include < stdio.h >
int main()
{
int first, second, sum;
printf("Enter two integers to add\n");
scanf("%d%d", &first, &second);
sum = first + second ;
/*Adding contents of first and second and storing in sum*/
printf("Sum of entered numbers = %d\n",sum);
return 0;
}
Add subtract multiply divide
#include < stdio.h >
int main()
{
int first, second, add, subtract, multiply;
float divide;
printf("Enter two integers\n");
scanf("%d%d", &first, &second);
add = first + second;
subtract = first - second;
multiply = first * second;
divide = first / (float)second;
//typecasting
printf("Sum = %d\n",add);
printf("Difference = %d\n",subtract);
printf("Multiplication = %d\n",multiply);
printf("Division = %.2f\n",divide);
return 0;
}
Add n numbers
#include < stdio.h >
int main()
{
int n, sum = 0, c, value;
printf("Enter the number of integers you want to add\n");
scanf("%d", &n);
printf("Enter %d integers\n",n);
for (c = 1; c <= n; c++)
{
scanf("%d",&value);
sum = sum + value;
/*adding each no in sum*/
}
printf("Sum of entered integers = %d\n",sum);
return 0;
}
Add digits
#include < stdio.h >
int main()
{
int n, sum = 0, remainder;
printf("Enter an integer\n");
scanf("%d",&n);
while(n != 0)
{
remainder = n % 10;
/*stores unit place digit to remainder*/
sum = sum + remainder;
n = n / 10;
/*dividing no to discard unit place digit*/
}
printf("Sum of digits of entered number = %d\n",sum);
return 0;
}
Add n numbers
#include < stdio.h >
int main()
{
int n, sum = 0, c, value;
printf("Enter the number of integers you want to add\n");
scanf("%d", &n);
printf("Enter %d integers\n",n);
for (c = 1; c <= n; c++)
{
scanf("%d",&value);
sum = sum + value;
/*adding each no in sum*/
}
printf("Sum of entered integers = %d\n",sum);
return 0;
}
These are the Concept of C programming . We'll be glad if you share your valuable information with us regarding this topic, then it will be a golden oppertunity for all of us to improve ourselves and know more. Comment below!!
Comments
Post a Comment