Sum the Series

Write a C program to Calculate the below Series. The Value of x and n must take from input terminal.

 1.    Sum = x + x2 + x3 +…. +  xn

 2.   Sum = x + 2x + 3x +…. +  nx

 3.   Sum=x1 + x1/2 + x1/3  + ….  +  x1/n


1.

#include

main()
{
int x, n, I, sum=0, y;

scanf("%d %d", &x, &n);
y=x;
for(I=1;I<=n;I++)
{
if(I==1)
{
printf("\n%d+", x);
}
else if(I==n)
{
printf("%d^%d = ", x, n);
}
else
{
printf("%d^%d+", x, I);
}
sum+=y;
y=y*x;
}
printf("%d", sum);

getch();
return 0;
}

2.                                                                                                                                                                   

#include

main()
{
int x, n, I, sum=0;

scanf("%d %d", &x, &n);
for(I=1;I<=n;I++)
{
if(I==1)
{
printf("\n%d+", x);
}
else if(I==n)
{
printf("%dx%d = ", n, x);
}
else
{
printf("%dx%d+", I, x);
}
sum+=I*x;
}
printf("%d", sum);

getch();
return 0;
}

3.                                                                                                                                                                  

#include

main()
{
int x, n, I;
float sum=0;

scanf("%d %d", &x, &n);
for(I=1;I<=n;I++)
{
if(I==1)
{
printf("\n%d+", x);
}
else if(I==n)
{
printf("%d^(1/%d) = ", x, n);
}
else
{
printf("%d^(1/%d)+", x, I);
}
sum+=pow(x, (1.0/I));
}
printf("%.2f", sum);

getch();
return 0;
}

Perfect Number

1. Write a C program to Print 1st 30 Perfect numbers starting from 0

main()
{
long  i, sum=0, j, count=0;
for(j=1; ;j++)
{
for(i=1; i<=j/2 ; i++)
{
if( j%i = =0)
{
sum += i;
}
}
if(j = =sum)
{
printf("%d ", j);
count + + ;
}
if(count = =30)
{
break;
}
sum=0;
}

getch();
return 0;
}

<< Go to Index Page >>

Reverse an Integer Number

1. Write a C program to reverse an Integer number. After print the output, make the sum of all digits.

Sample Input:

Enter Number: 571

Output: 

After Reverse: 175

Sum of all Digits: 13

Source:                                                                                                                                                            

main()
{
int num, i, sum=0;
scanf("%d", &num);
printf("After Reverse: ");
while(num!= 0)
{
  i = num%10;
  num /=10;
  sum += i;
  printf("%d", i);
}
printf("\n\nSum of all Digits: %d", sum);

getch();
return 0;
}

<< Go to Index Page >>

Palindrom

1. Write a C program to check a Given Number, Whether  is it Palindrome or Not ?

Sample Input:

Enter Number: 123

Output:

It is not Palindrome


Sample Input:

Enter Number: 121

Output:

It is  Palindrome


2. Write a C program to Check a String, Whether is it Palindrome or Not ?

Sample Input:

Enter String: madam

Output:

It is  Palindrome

Sample Input:

Enter String: asian

Output:

It is not Palindrome


1.                                                                                                                                                                

main()
{
int num, i, rev=0, temp;
printf("Enter Number: ");
scanf("%d", &num);
temp=num;
while(temp!=0)
{
  i = temp%10;
  rev = rev*10+i ;
  temp /= 10;
}
if(num = =rev)
  {
    printf("It is a Palindrome.\n");
  }
    else
  {
    printf("It is not a Palindrome.\n");
  }

getch();
return 0;
}

Manipulate Series

1. Write a C program to print a Series of Integer Numbers,which is divisible by 3 from a given set of limits.

Sample Input: 

Start_value: 1
End_value: 10

Sample Output:

3, 6, 9

2. Write a C program to print a Series of Odd Numbers and Even Numbers. After Print Make an Average of all Printed Odd Numbers and Even Numbers.

Sample Output:

The Even Numbers are: 2, 4, 6, 8, 10
The Odd Numbers are: 1, 3, 5, 7, 9

The Average of Even Numbers: 6


1.                                                                                                                                                                  


main()
{
int start, end, i ;

printf("Start_Value: ");
scanf("%d", &start);
printf("End_Value: ");
scanf("%d", &end);
printf("\n\n");
for(i=start ; i <= end ; i++)
{
if(i%3 = = 0)
printf("%d, ", i );
}

getch();
return 0;
}

2.                                                                                                                                                                  
main()
{
int i,sumeven=0, sumodd=0, even=0, odd=0;
float aveeven, aveodd;
printf("The Even Numbers are: ");
for(i=1;i<=15;i++)
{
if(i%2==0)
{
printf("%d, ",i);
sumeven+=i;
even++;
}
}
printf("\n\nThe Odd Numbers are: ");
for(i=1;i<=15;i++)
{
if(i%2!=0)
{
printf("%d, ",i);
sumodd+=i;
odd++;
}
}
aveeven=(float)(sumeven)/even;
aveodd=(float)(sumodd)/odd;
printf("\n\nThe Average of Even Numbers: %.2f", aveeven);
printf("\n\nThe Average of Odd Numbers: %.2f", aveodd);

getch();
return 0;
}

<< Go to Index Page >>

Strange Number

1.Write a C program to Print the Strange Numbers Between 1 and 100000.

main()
{
int a, b, c, n, temp, J;

printf("The Strange Numbers are:\n\t\t");
for(a=1;a<=100000;a++)
{
c=1;
for(b=2;b<=a/2;b++)
{
if(a%b==0)
{
c=0;
break;
}
}
if(c==1)
{
temp=a;
while(temp>0) //starting the loop for extract the number
{
J=temp%10;
n=1;
for(b=2;b<=J/2;b++) //loop for checking the digit whether is it prime or not.
{
if(J%b = =0)
{
n=0;
break;  //skip the 'for loop'
}
}
if((n= =0)||(J= =0))
{
n=0;
break; //skip the 'while loop'
}
temp /=10;
}  //loop for extract finish
if(n= =1)
{
printf("\t%d", a);
}
}
}

getch();
return 0;
}
<< Go to Index Page >>

Prime Number Manipulation

1. Write a C program to calculate the SUM and COUNT of Primes from a given range of numbers. Formatting required for the Input and Output statements.

Sample Input:

Range Start From: 1
End of Range: 10

Sample Output:

The Sum of Primes is: 11
Total Primes: 5

2. Write a C Program to Print all the Prime Numbers between 1 and 100. 

Sample Output:

1,  2,  3,  5,  7,  11,  13,  . . . . etc


3. WAP Program to get a range from user and give a list of prime numbers up to that number. And check whether the sum of all printed prime numbers are equal to the given input or not?
Sample Input: 10
Sample Output:
Prime list: 1, 2, 3, 5, 7
The sum is: 18
The sum is not equal to 10



1.                                                                                                                                                                 

main()
{
int a, b, c, n=0, start, end, sum=0;
printf("Range Start From: ");
scanf("%d", &start);
printf("End of Range: ");
scanf("%d", &end);

for(a=start;a<=end;a++)
{
c=1;
for(b=2;b<=a/2;b++)
{
if(a%b==0)
{
c=0;
break;
}
}
if(c==1)
{
sum+=a;
n++;
}
}
printf("The Sum of Primes is: %d\nTotal primes: %d", sum, n);
getch();
return 0;
}

2.                                                                                                                                                                  

main()
{
int a, b, c;

for(a=1;a<=100;a++)
{
c=1;
for(b=2;b<=a/2;b++)
{
if(a%b==0)
{
c=0;
break;
}
}
if(c==1)
{
printf("%d\t", a);
}
}
getch();
}

3.                                                                                                                                                                 


main()
{
int a, b, c,n,sum=0;
printf("Enter Range\n");
scanf("%d",&n);
printf("Prime list : ");
for(a=1;a<=n;a++)
{
c=1;
for(b=2;b<=a/2;b++)
{
if(a%b==0)
{
c=0;
break;
}
}
if(c==1)
{
printf("%d\t", a);
sum+=a;
}
}
printf("The sum is: %d",sum);

if (sum==n)
{
 printf("The sum is equal to %d",n);
}
else
{
printf("The sum is not equal to %d",n);
}

getch();
}
<< Go to Index Page >>

Arithmatic Operation

Write and run a program that reads a six digit integer and prints the sum of its six digits. Use the quotient operator(/) and the remainder operator(%) to extract the digit from the integer. For example, if N is the integer 876543 then n/1000%10 is its thousands digit 6.

<< Go to Index Page >>

Conditional Expression

Write and run a program that reads two integers and then uses the conditional expression operator to print either "Multiple" or "Not" according to whether one of the integers is a multiple of the other.

<< Go to Index Page >>

Comparison Operator

Write and run a program that reads the users age and then prints "You are a Child" if the age < 18, " You are an adult." if 18<=age<65, and "You are a senior citizen." if age >=65.

<< Go to Index Page >>

Array programming


Write a C Program to fill up an Integer Array. The length of the array must take from the terminal. After fill up the array do the following operations.
i)                    Print the array with label formatting.
ii)                   Count the number of values inside the array.
iii)                 Count the number of odd values.
iv)                 Count the number of even values.
v)                  Sum all the odd values.
vi)                 Sum all the even values.
vii)               Calculate the average.
viii)              Find the largest value.
ix)                 Find the smallest value.


<< Go to Index Page >>

Find the highest (maximum) and lowest (minimum) grades in an array of 25 integer grades. Print the array and print the highest and lowest grades, labeled appropriately

Task:  Find the highest (maximum) and lowest (minimum) grades in an array of 25 integer grades.  Print the array and print the highest and lowest grades, labeled appropriately. Try to enter all kind of integer grades in your array.

Hits of integer grades:

A+ is a Letter Grade.
A is  a Letter Grade.
4 is an Integer Grade.
3.75 is an Integer Grade.
So we may assume that 'A+' = 4, A = 3.75 etc.

Source Code

#include<stdio.h>
#include<conio.h>
void grade(float grades[],int size)
{
float min=0,max=0;
int i;
for(i=0;imax)
{
max=grades[i];
}
}

for(i=0;i<size;i++)
{
if(grades[i]<min)
{
min=grades[i];
}
}
printf("\n");
printf("Maximum Grade: %.2f",max);
printf("\n");
printf("Minimum Grade: %.2f",min);
}
int main()
{
float grades[25],size;
printf("Enter the size of an Array:\n");
scanf("%f",&size);
printf("Enter the Grade point:\n");
grade(grades,size);
return 0;
}
<< Go to Index Page >>

Write a C program to find the Simple Interest. Take input for principle amount, rate of interest and time from terminal

Simple Interest is the money paid by the borrower to the lender, based on the Principle Amount, Interest Rate and the Time Period.

Simple Interest is calculated by, SI= P * T * R / 100 formula.

Where, P is the Principle Amount.
T is the Time Period.
R is the Interest Rate.

Definition of 'Simple Interest' from WEB

A quick method of calculating the interest charge on a loan. Simple interest is determined by multiplying the interest rate by the principal by the number of periods.
Simple Interest = P x I x N


Where:

P is the loan amount
I is the interest rate
N is the duration of the loan, using number of periods

Explanation of 'Simple Interest'

Simple interest is called simple because it ignores the effects of compounding. The interest charge is always based on the original principal, so interest on interest is not included.  This method may be used to find the interest charge for short-term loans, where ignoring compounding is less of an issue.
Source Code:

#include<stdio.h>
main()
{
    float jama,suderhar,somoy;
    float sud=0;
    printf("\nEnter Your Principal Amount: ");
    scanf("%f",&jama);
    printf("\nEnter Your Rate of Interest: ");
    scanf("%f",&suderhar);
    printf("\nEnter The Time Period: ");
    scanf("%f",&somoy);
    suderhar=suderhar/100;
    sud=jama*suderhar*somoy;
    printf("The calculated interest is: %f",sud);
    return 0;
}
<< Go to Index Page >>

Write a program performing as calculator which allows all Arithmetic Operators with operands as input

1. Write a C program for performing as calculator which allows all Arithmetic Operators with operands from terminal. Few Input and Output sample are given below:

Recommended: Study Char/Char Array in C/C++           
        
            Sample Input: 1 + 4
            Sample Output: 5

            Sample Input: 8 % 2
            Sample Output: 0

            Sample Input: 6 / 2
            Sample Output: 3

            Sample Input: 5 / 2
            Sample Output: 2.5


Source code in c:

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,z,x,w,h;
char c;
float y,m=0.0;

printf("\nWelcome To My Calculator\n");
AB:
printf("\nenter to calculate (Ex:2+2)\n");
scanf("%d%c%d",&a,&c,&b);
z=(a+b);
x=(a*b);
w=(a-b);
h=(a%b);
y=(a/b);
m=y;
switch(c)
{
case '+' : printf("%d+%d=%d",a,b,z);
break;
case '-' : printf("%d-%d=%d",a,b,w);
break;
case '*' : printf("%d*%d=%d",a,b,x);
break;
case '/' : printf("%d/%d=%2.3f",a,b,m);
break ;
case '%' : printf("%d %d=%d",a,b,h);
break ;
default : printf("error syntax");
break ;
}
goto AB;
getch();
}

Source Code in C++

#include<iostream>
using namespace std;
int main()
{
    int a,b,sum;
    char oper;
    cout<<"Enter an equation to Perform : "<<endl;
    cin>>a;
    cin>>oper;
    cin>>b;
    if(oper=='+')
        sum=a+b;
    else if(oper=='-')
        sum=a-b;
    else if(oper=='*')
        sum=a*b;
    else if(oper=='/')
        sum=a/b;
    cout<<sum;
}

2. Write a C / C++ program for performing all Arithmetic Operation using Arithmetic Operator. The program will take Integer input from terminal as operand.Hints: C= a+b, Here 'a' and 'b' are operand, '=' is assignment operator, and '+' is arithmetic operator.


Source Code in C++

#include<iostream>
using namespace std;
int main()
{
    int b,c,d;
    cin>>b;
    cin>>c;
    d=b+c;
    cout<<d<<endl;
    d=b-c;
    cout<<d<<endl;
    d=b*c;
    cout<<d<<endl;
    d=b/c;
    cout<<d<<endl;
}