Brijmohan lal Sahu - Facebook
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu
Showing posts with label Operator. Show all posts
Showing posts with label Operator. Show all posts

Wednesday, December 17, 2014

Program to find sum of digits of any number given by user using for loop in C.


Sum of all digits


Code Box
----------------------------------------------

/*Program to find sum of digits of any number given by user max. 5 digits*/

#include<stdio.h>
#include<conio.h>

void main()
{
int num,num1,rem,sum,i;
clrscr();

sum=0;
printf("\n\tSum of Digits Finder");
printf("\n-------------------------");
printf("\nEnter a number:");
scanf("%d",&num);

num1=num; //to save actual number
for(i=1;num1>=1;i++)
{
rem=num1%10;
num1=num1/10;
sum=sum+rem;
}

printf("\nSum of all digits = %d",sum);

getch();

}


Thursday, December 11, 2014

Program to print reverse order number in using while loop in C.




Code Box 
----------------------------------------

/*Program to print reverse order number */
#include<stdio.h>
#include<conio.h>
void main()
{

int i;
clrscr();
i=10;

while(i>=1)
{
printf("%d",i);
printf("\n");
i--; // decrement Operator  
}

getch();
}


Wednesday, December 10, 2014

Write a program to enter marks of a student in five subjects and find grade in C.


Student details


Code Box
-------------------------------------

/*program to enter marks of a student in five subjects and find grade as

=> average>90   A+
=> average<90 and average<75 A
=> average<75 and average >60 B
=> average<60 and average >50 C
=> average<50 D

*/

#include<stdio.h>
#include<conio.h>
void main()
{
int m1,m2,m3,m4,m5; // marks in five subjects
float avg; 
clrscr();


/* Accepting marks of five subjects */
printf("\nEnter marks(max. 100):");
printf("\nEnglish:");
scanf("%d",&m1);

printf("\nMaths:");
scanf("%d",&m2);

printf("\nPhysics:");
scanf("%d",&m3);

printf("\nChemistry:");
scanf("%d",&m4);

printf("\nBiology:");
scanf("%d",&m5);

/*Calculation of average */

avg=(m1+m2+m3+m4+m5)/5;

/*Percentage */
printf("\nPercentage: %.3f%",avg);

/*Selection of grade */

if(avg>=90)
{
printf("\nGrade : A+");
}
else if(avg<90 && avg>=75)
{
printf("\nGrade : A");
}
else if(avg<75 && avg>=60)
{
printf("\nGrade : B");
}else if(avg<60 && avg>=50)
{
printf("\nGrade : C");
}else if(avg<50)
{
printf("\nGrade : D");
}

getch();
}


Sunday, December 7, 2014

Program to calculate sum of cubic series using while loop without power function in C.


cubic series sum using while loop


Code Box
--------------------------------------------

/*program to calculate sum of the series 
(1*1*1)+(2*2*2)+(3*3*3)+(4*4*4)+.......+(n*n*n).
cube number series. 
without using power function.
where n is the limit entered by user.
*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum,num;

clrscr();

sum=0;

printf("\nEnter limit : ");
scanf("%d",&num);

printf("\nCubic Number Series ");

printf("\nSeries= ");

i=1;           //initialization

while(i<=num)
{
sum=sum+(i*i*i);
printf("+ (%d*%d*%d)",i,i,i);

i++;           //increment post fix operator 

}

printf("\n\nSum of series= %d",sum);

getch();
}

Program to calculate sum of square series using power function and while loop in C.


sum of square series using power function and while loop


Code Box
------------------------------------------------

/*program to calculate sum of the series 
(1*1)+(2*2)+(3*3)+(4*4)+.......+(n*n).
Square number series. 
by using power function.
where n is the limit entered by user.
*/

#include<stdio.h>
#include<conio.h>
#include<math.h>   //for power function
void main()
{
int i,sum,num;

clrscr();

sum=0;

printf("\nEnter limit : ");
scanf("%d",&num);

printf("\nSquare Number Series ");

printf("\nSeries= ");

i=1;              //initialization

while(i<=num)
{

sum=sum+pow(i,2);  //power function

printf("+ (%d*%d)",i,i);

i++;            //increment post fix operator 

}

printf("\n\nSum of series= %d",sum);

getch();
}



Program to calculate sum of square series using while loop in C.


sum of square series using while loop



Code Box
---------------------------------------

/*program to calculate sum of the series 
(1*1)+(2*2)+(3*3)+(4*4)+.......+(n*n).
Square number series. 
where n is the limit entered by user.
*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum,num;

clrscr();

sum=0;

printf("\nEnter limit : ");
scanf("%d",&num);

printf("\nSquare Number Series ");

printf("\nSeries= ");

i=1;                   //initialization 

while(i<=num)
{
sum=sum+(i*i);
printf("+ (%d*%d)",i,i);

i++;       // increment post fix operator 

}

printf("\n\nSum of series= %d",sum);

getch();
}


Program to calculate sum of odd-even number series using while loop in C.


even-odd series sum


Code Box
--------------------------------------------

/*program to calculate sum of the series
1-2+3-4+5-6+7-8+9.......+n
odd-even number series(alternative)
where n is the limit entered by user.
*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,evensum,oddsum,sum,num;

clrscr();

evensum=0;
oddsum=0;

printf("\nEnter limit : ");
scanf("%d",&num);

printf("\nOdd Number Series ");

printf("\nSeries= ");

i=1;                     //initialization

while(i<=num)
{

if(i%2==0)          // % modulus operator
{
printf(" - ");
evensum=evensum+i;
}
else
{
printf(" + ");
oddsum=oddsum+i;
}
printf("%d",i);

i++;                 //increment post fix operator

}

sum=oddsum-evensum;

printf("\n\nSum of series= %d",sum);

getch();
}


Program to calculate sum of odd number series using while loop in C.


Sum of odd series using while loop


Code Box
-------------------------------------------------

/*program to calculate sum of the series 
1+3+5+7+9.......+n
odd number series
where n is the limit entered by user.
*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum,num;

clrscr();

sum=0;

printf("\nEnter limit : ");
scanf("%d",&num);

printf("\nOdd Number Series ");

printf("\nSeries= ");

i=1;                      //initialization 
while(i<=num)      //test condition 
{

if(i%2!=0)            //% modulus operator  
{
printf(" + %d ",i);
sum=sum+i;
}
i++;                   //increment post fix operator
}
printf("\n\nSum of series= %d",sum);

getch();
}



Program to calculate sum of even series using while loop in C.


sum of even series using while loop


Code Box
-------------------------------------------------

/*program to calculate sum of the series
2+4+6+8.......+n
even number series
where n is the limit entered by user.
*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum,num;

clrscr();

sum=0;

printf("\nEnter limit : ");
scanf("%d",&num);

printf("\nEven Number Series ");

printf("\nSeries= ");

i=1;
while(i<=num)
{

if(i%2==0)      //modulus operator
{
printf(" + %d ",i);
sum=sum+i;
}
i++;                //increment operator
}
printf("\n\nSum of series= %d",sum);

getch();
}



Program to calculate sum of the even-odd series using for loop in C.


even-odd series sum


Code Box
------------------------------------------------

/*program to calculate sum of the series 
1-2+3-4+5-6+7-8+9.......+n
odd-even number series(alternative) 
where n is the limit entered by user.
*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,evensum,oddsum,sum,num;

clrscr();

evensum=0;
oddsum=0;

printf("\nEnter limit : ");
scanf("%d",&num);

printf("\nOdd Number Series ");

printf("\nSeries= ");
for(i=1;i<=num;i++)
{

if(i%2==0)
{
printf(" - ");
evensum=evensum+i;
}
else
{
printf(" + ");
oddsum=oddsum+i;
}
printf("%d",i);
}

sum=oddsum-evensum;

printf("\n\nSum of series= %d",sum);

getch();
}



Program to calculate sum of the odd number series using for loop in C.


sum of odd number series


Code Box
-------------------------------------------

/*program to calculate sum of the series 
1+3+5+7+9.......+n
odd number series
where n is the limit entered by user.
*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum,num;

clrscr();

sum=0;

printf("\nEnter limit : ");
scanf("%d",&num);

printf("\nOdd Number Series ");

printf("\nSeries= ");
for(i=1;i<=num;i++)
{

if(i%2!=0)
{
printf(" + %d ",i);
sum=sum+i;
}

}
printf("\n\nSum of series= %d",sum);

getch();
}