//Program for understanding arithmetic operators.
#include<stdio.h>
int main(){
int a=10,b=5;
printf("Addition of a and b:%d\n",a+b);
printf("Subraction of a and b:%d\n",a-b);
printf("Multiplication of a and b:%d\n",a*b);
printf("Division of a and b:%d\n",a/b);
printf("Modulo of a and b:%d",a%b);
return 0;
}
#operators
#include<stdio.h>
int main(){
int a=10,b=5;
printf("Addition of a and b:%d\n",a+b);
printf("Subraction of a and b:%d\n",a-b);
printf("Multiplication of a and b:%d\n",a*b);
printf("Division of a and b:%d\n",a/b);
printf("Modulo of a and b:%d",a%b);
return 0;
}
#operators
👍3
//Program for understanding increment and decrement operators.
//post increment.
#include<stdio.h>
int main(){
int a=10;
int b=a++; //post increment:the actual value of a is first assigned to b and next the value of a will be incremented by 1.
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
//post increment.
#include<stdio.h>
int main(){
int a=10;
int b=a++; //post increment:the actual value of a is first assigned to b and next the value of a will be incremented by 1.
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
👍1
//Program for understanding increment and decrement operators.
//pre increment.
#include<stdio.h>
int main(){
int a=10;
int b=++a; //pre increment:the actual value of a is first incremented by 1 and assigned to b.
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
//pre increment.
#include<stdio.h>
int main(){
int a=10;
int b=++a; //pre increment:the actual value of a is first incremented by 1 and assigned to b.
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
//Program for understanding increment and decrement operators.
//post decrement.
#include<stdio.h>
int main(){
int a=10;
int b=a--; //post decrement:the actual value of a is first assigned to b and then the value of a is decremented by 1.
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
//post decrement.
#include<stdio.h>
int main(){
int a=10;
int b=a--; //post decrement:the actual value of a is first assigned to b and then the value of a is decremented by 1.
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
//Program for understanding increment and decrement operators.
//pre decrement.
#include<stdio.h>
int main(){
int a=10;
int b=--a; //pre decrement:the actual value of a is first decremented by 1 and assigned to b .
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
//pre decrement.
#include<stdio.h>
int main(){
int a=10;
int b=--a; //pre decrement:the actual value of a is first decremented by 1 and assigned to b .
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
❤3
//Program for understanding assignment operators.
#include<stdio.h>
int main(){
int a=10; //a is assigned with a value 10
printf("a:%d\n",a);
a+=4; // a=a+6
printf("a:%d\n",a);
a-=3; //a=a-3
printf("a:%d\n",a);
a*=2; //a=a*2
printf("a:%d\n",a);
a/=11; //a=a/11
printf("a:%d\n",a);
a%=2; //a=a%2
printf("a:%d\n",a);
return 0;
}
#operators
#include<stdio.h>
int main(){
int a=10; //a is assigned with a value 10
printf("a:%d\n",a);
a+=4; // a=a+6
printf("a:%d\n",a);
a-=3; //a=a-3
printf("a:%d\n",a);
a*=2; //a=a*2
printf("a:%d\n",a);
a/=11; //a=a/11
printf("a:%d\n",a);
a%=2; //a=a%2
printf("a:%d\n",a);
return 0;
}
#operators
👍1
//Program for understanding relational operators.
#include<stdio.h>
int main(){
int a=10,b=9;
printf("a==b:%d\n",a==b); // 0:False
printf("a!=b:%d\n",a!=b); // 1:True
printf("a>b:%d\n",a>b); // 1:True
printf("a<b:%d\n",a<b); //0:False
printf("a>=b:%d\n",a>=b); //1:True
printf("a<=b:%d",a<=b); //0:False
return 0;
}
#operators
#include<stdio.h>
int main(){
int a=10,b=9;
printf("a==b:%d\n",a==b); // 0:False
printf("a!=b:%d\n",a!=b); // 1:True
printf("a>b:%d\n",a>b); // 1:True
printf("a<b:%d\n",a<b); //0:False
printf("a>=b:%d\n",a>=b); //1:True
printf("a<=b:%d",a<=b); //0:False
return 0;
}
#operators
👍2
//Program for understanding logical operators.
#include<stdio.h>
int main(){
int a=6,b=3;
printf("a==6 && a>b :%d\n",a==6 && a>b); //In case of and(&&) the result is True(1),if and only if both conditions gets evaluated to True(1).
printf("a>b b>a:%d\n",a>b b>a); //In case of or||( ) The result is True,if any one condition is True(1) no matter about second condition.
printf("!a:%d",!a); //If the value of a is True(1) then the not(!) operator evaluate the value to False(0) and vice versa.
return 0;
} //give or operator(||) in program its not getting printed in telegram message
#operators
#include<stdio.h>
int main(){
int a=6,b=3;
printf("a==6 && a>b :%d\n",a==6 && a>b); //In case of and(&&) the result is True(1),if and only if both conditions gets evaluated to True(1).
printf("a>b
printf("!a:%d",!a); //If the value of a is True(1) then the not(!) operator evaluate the value to False(0) and vice versa.
return 0;
} //give or operator(||) in program its not getting printed in telegram message
#operators
👍2
//Program for understanding bitwise operators.
#include<stdio.h>
int main(){
int a=3,b=1;
printf("a&b=%d\n",a&b); //Bitwise and(&) //0011 :3
//0001 :1
//-------if we perforn and on above two values
//0001 :1 ,Result will be 1.
printf("a|b :%d\n",a|b); //Bitwise or(|) //0011:3
//0001:1
//-------if we perform or on above two values
//0011:3 ,Result will be 3.
printf("a>>b:%d\n",a>>b); //right shift(>>) // 3>>1
// 0011:3
// 0001:1(after shifting to right)
printf("a<<b:%d",a<<b); //left shift(<<) //3<<1
//0011:3
//0110:6(after shifting to left)
return 0;
}
//#operators
#include<stdio.h>
int main(){
int a=3,b=1;
printf("a&b=%d\n",a&b); //Bitwise and(&) //0011 :3
//0001 :1
//-------if we perforn and on above two values
//0001 :1 ,Result will be 1.
printf("a|b :%d\n",a|b); //Bitwise or(|) //0011:3
//0001:1
//-------if we perform or on above two values
//0011:3 ,Result will be 3.
printf("a>>b:%d\n",a>>b); //right shift(>>) // 3>>1
// 0011:3
// 0001:1(after shifting to right)
printf("a<<b:%d",a<<b); //left shift(<<) //3<<1
//0011:3
//0110:6(after shifting to left)
return 0;
}
//#operators
//Program for size of operator.
#include<stdio.h>
int main(){
int a=6;
printf("size of a:%d",sizeof(a));
return 0;
}
//#operators
#include<stdio.h>
int main(){
int a=6;
printf("size of a:%d",sizeof(a));
return 0;
}
//#operators
//Program to read elements of array and print them.
#include <stdio.h>
int main() {
int a[5],i;
for(i=0;i<5;i++) //for loop for reading elements of array
{
printf("Enter the element at %d index:",i);
scanf("%d",&a[i]);
}
for(i=0;i<5;i++)
{
printf("\nThe element at %d index is :%d",i,a[i]); //for loop for printing elements of array
}
return 0;
}
//#array
#include <stdio.h>
int main() {
int a[5],i;
for(i=0;i<5;i++) //for loop for reading elements of array
{
printf("Enter the element at %d index:",i);
scanf("%d",&a[i]);
}
for(i=0;i<5;i++)
{
printf("\nThe element at %d index is :%d",i,a[i]); //for loop for printing elements of array
}
return 0;
}
//#array
👍7
//Program to read marks of 5 subjects and calculate total marks and average.
#include <stdio.h>
int main() {
float marks[5],sum=0.0;
float avg;
for(int i=0;i<5;i++)
{ printf("Enter marks in Subject %d:",i+1);
scanf("%f",&marks[i]);
sum=sum+marks[i];
}
avg=sum/5;
printf("Total marks obtained:%.2f\n",sum);
printf("Average:%f",avg);
return 0;
}
//#array
#include <stdio.h>
int main() {
float marks[5],sum=0.0;
float avg;
for(int i=0;i<5;i++)
{ printf("Enter marks in Subject %d:",i+1);
scanf("%f",&marks[i]);
sum=sum+marks[i];
}
avg=sum/5;
printf("Total marks obtained:%.2f\n",sum);
printf("Average:%f",avg);
return 0;
}
//#array
👍3
//Program to read array of 10 integers and count number of even and odd elements.
#include <stdio.h>
int main() {
int n[10],even=0,odd=0;
for(int i=0;i<10;i++)
{
printf("Enter element at index %d:",i);
scanf("%d",&n[i]);
if(n[i]%2==0){
even++;
}
else{
odd++;
}
}
printf("Total number of even numbers are:%d\n",even);
printf("Total number of odd numbers are:%d\n",odd);
return 0;
}
//#array
#include <stdio.h>
int main() {
int n[10],even=0,odd=0;
for(int i=0;i<10;i++)
{
printf("Enter element at index %d:",i);
scanf("%d",&n[i]);
if(n[i]%2==0){
even++;
}
else{
odd++;
}
}
printf("Total number of even numbers are:%d\n",even);
printf("Total number of odd numbers are:%d\n",odd);
return 0;
}
//#array
👍2❤1
/*Program to read 2 arrays of size 5 and store integers in them ,then
calculate the sum of corresponding elements of those two array's and
store the result in third array .*/
#include <stdio.h>
int main() {
int a[5],b[5],c[5];
printf("Enter the elements of first array:\n");
for(int i=0;i<5;i++)
{
printf("Enter the Element at %d index:",i);
scanf("%d",&a[i]);
}
printf("Enter the elements of second array:\n");
for(int i;i<5;i++)
{
printf("Enter the Element at %d index:",i);
scanf("%d",&b[i]);
}
printf("Elements of Third Array after calculating sum of 2 arrays:\n");
for(int i=0;i<5;i++)
{
c[i]=a[i]+b[i];
printf("The Element at index %d is :%d\n",i,c[i]);
}
return 0;
}
//#array
calculate the sum of corresponding elements of those two array's and
store the result in third array .*/
#include <stdio.h>
int main() {
int a[5],b[5],c[5];
printf("Enter the elements of first array:\n");
for(int i=0;i<5;i++)
{
printf("Enter the Element at %d index:",i);
scanf("%d",&a[i]);
}
printf("Enter the elements of second array:\n");
for(int i;i<5;i++)
{
printf("Enter the Element at %d index:",i);
scanf("%d",&b[i]);
}
printf("Elements of Third Array after calculating sum of 2 arrays:\n");
for(int i=0;i<5;i++)
{
c[i]=a[i]+b[i];
printf("The Element at index %d is :%d\n",i,c[i]);
}
return 0;
}
//#array
👍3
//Program to print 2X3 matrix and find sum of all elemets in it.
#include <stdio.h>
int main() {
int m[2][3],i,j,sum=0;
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{ printf("Enter the element at m[%d][%d]:",i,j);
scanf("%d",&m[i][j]);
sum=sum+m[i][j];
}
}
printf("The matrix is:\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",m[i][j]);
}
printf("\n");
}
printf("Sum of all the elements of matrix:%d",sum);
return 0;
}
//#array
#include <stdio.h>
int main() {
int m[2][3],i,j,sum=0;
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{ printf("Enter the element at m[%d][%d]:",i,j);
scanf("%d",&m[i][j]);
sum=sum+m[i][j];
}
}
printf("The matrix is:\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",m[i][j]);
}
printf("\n");
}
printf("Sum of all the elements of matrix:%d",sum);
return 0;
}
//#array
👍1
//Program to read 2X3 matrix and print transpose of it (3X2).
#include <stdio.h>
int main() {
int m[2][3],i,j;
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{ printf("Enter the element at m[%d][%d]:",i,j);
scanf("%d",&m[i][j]);
}
}
printf("The matrix is:\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",m[i][j]);
}
printf("\n");
}
printf("The transposed matrix is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",m[j][i]);
}
printf("\n");
}
return 0;
}
//#array
#include <stdio.h>
int main() {
int m[2][3],i,j;
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{ printf("Enter the element at m[%d][%d]:",i,j);
scanf("%d",&m[i][j]);
}
}
printf("The matrix is:\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",m[i][j]);
}
printf("\n");
}
printf("The transposed matrix is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",m[j][i]);
}
printf("\n");
}
return 0;
}
//#array
👍2🤯1
//Program to perform sum of individual row and column of 3X3 matrix, read the elements of matrix.
#include<stdio.h>
int main()
{int m[3][3],i,j,sr,sc;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{ printf("Enter the element at m[%d][%d]:",i,j);
scanf("%d",&m[i][j]);
}
}
printf("The matrix is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",m[i][j]);
}
printf("\n");
}
for(i=0;i<3;i++)
{ sr=0,sc=0;
for(j=0;j<3;j++)
{ sr=sr+m[i][j];
sc=sc+m[j][i];
}
printf("Th sum of row %d:%d\n",i,sr);
printf("The sum of column %d:%d\n",i,sc);
}
}
//#array
#include<stdio.h>
int main()
{int m[3][3],i,j,sr,sc;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{ printf("Enter the element at m[%d][%d]:",i,j);
scanf("%d",&m[i][j]);
}
}
printf("The matrix is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",m[i][j]);
}
printf("\n");
}
for(i=0;i<3;i++)
{ sr=0,sc=0;
for(j=0;j<3;j++)
{ sr=sr+m[i][j];
sc=sc+m[j][i];
}
printf("Th sum of row %d:%d\n",i,sr);
printf("The sum of column %d:%d\n",i,sc);
}
}
//#array
❤3👍3🥰1
//Program to do sum of 2 matrices and store the sum in third matrix, read the elements of matrix.
#include<stdio.h>
int main()
{int a[2][3],b[2][3],c[2][3],i,j;
printf("Enter elemnts of first matrix:\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{ printf("Enter the element at a[%d][%d]:",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Enter elemnts of second matrix:\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{ printf("Enter the element at b[%d][%d]:",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{ c[i][j]=a[i][j]+b[i][j];
}
}
printf("The sum of two matices=\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{ printf("%d\t",c[i][j]);
}
printf("\n");
}
return 0;
}
//#array
#include<stdio.h>
int main()
{int a[2][3],b[2][3],c[2][3],i,j;
printf("Enter elemnts of first matrix:\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{ printf("Enter the element at a[%d][%d]:",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Enter elemnts of second matrix:\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{ printf("Enter the element at b[%d][%d]:",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{ c[i][j]=a[i][j]+b[i][j];
}
}
printf("The sum of two matices=\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{ printf("%d\t",c[i][j]);
}
printf("\n");
}
return 0;
}
//#array
👍5❤1
//Program to read a string and print it.
#include<stdio.h>
int main()
{char name[20];
printf("Enter name:");
gets(name);
puts(name);
return 0;
}
//contact us
//👇👇👇👇
//@c_programmerrr
#include<stdio.h>
int main()
{char name[20];
printf("Enter name:");
gets(name);
puts(name);
return 0;
}
//contact us
//👇👇👇👇
//@c_programmerrr
👍2