1.Write a program to print 5 numbers on screen.
#include<stdio.h>
void Display()
{
int i = 0;
for(i=1;i<=5;i++)
{
printf("%d\n",i);
}
}
int main()
{
Display();
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------
2.Write a program to printf "ANISTUDIO" 5 times on screen
#include<stdio.h>
void Display(); //declaration
int main()
{
Display(); //function call
return 0;
}
void Display() //Defination
{
int i = 0;
for(i=1;i<=5;i++)
{
printf("ANISTUDIO\n");
}
}
-----------------------------------------------------------------------------------------------------------------------------
3. Write a program and get one number from user and printf that number times "ANISTUDIO" on screen.
//Dynamic problem
#include<stdio.h>
void Display(int); //declaration
int main()
{
int iNo = 0;
printf("enter number\n");
scanf("%d",&iNo);
Display(iNo); //function call
return 0;
}
void Display(int iValue) //Defination
{
int i = 0;
for(i=1;i<=iValue;i++)
{
printf("ANISTUDIO\n");
}
}
-----------------------------------------------------------------------------------------------------------------------------
4.Write a program to get one number user and print all before numbers and that number itself
Note : if your input is 0 then return from program and another one is if your value is negative then convert negative value into positive.
for ex : Input : iNo = 5
Output : 1 2 3 4 5
//Hint : take count of your input number.
#include<stdio.h>
void Display(int); //declaration
int main()
{
int iNo = 0;
printf("enter number\n");
scanf("%d",&iNo);
Display(iNo); //function call
return 0;
}
void Display(int iValue) //Defination
{
int i = 0;
if(iValue==0)
{
printf("Your entered value is 0\n");
return;
}
if(iValue < 0) //Input Operator
{
iValue = -iValue;
}
for(i=1;i<=iValue;i++)
{
printf("%d\n",i);
}
}
-----------------------------------------------------------------------------------------------------------------------------
5.write 1 program to get value from user and print in reverse order.
for ex :
input :5
output : 5 4 3 2 1
#include<stdio.h>
void Display(int); //declaration
int main()
{
int iNo = 0;
printf("Enter number");
scanf("%d",&iNo);
Display(iNo);
return 0;
}
void Display(int iValue)
{
int i=0;
for(i=iValue;i>=1;i--)
{
printf("%d\n",i);
}
}
-----------------------------------------------------------------------------------------------------------------------------
6.Write a program to get one number from user and print addition of that number count.
Note : if input is negative number then convert it into positive.
for ex:
input :5
output : 1+2+3+4+5 = 15
#include<stdio.h>
int Addition(int); //declaration
int main()
{
int iNo = 0, iRet=0;
printf("Enter number");
scanf("%d",&iNo);
iRet = Addition(iNo);
printf("Addition is : %d\n",iRet);
return 0;
}
int Addition(int iValue)
{
int iSum = 0;
int iCnt = 0;
if(iValue<0)
{
iValue = -iValue;
}
for(iCnt=1;iCnt<=iValue;iCnt++)
{
iSum = iSum+iCnt;
}
return iSum;
}
-----------------------------------------------------------------------------------------------------------------------------
7.Write a program to get one number from user and print factorial of that number.
input :5
output : 1*2*3*4*5 = 120.
#include<stdio.h>
int Factorial(int); //declaration
int main()
{
int iNo = 0, iRet=0;
printf("Enter number");
scanf("%d",&iNo);
iRet = Factorial(iNo);
printf("Factorial is : %d\n",iRet);
return 0;
}
int Factorial(int iValue)
{
int iFact = 1;
int iCnt = 0;
if(iValue<0)
{
iValue = -iValue;
}
for(iCnt=1;iCnt<=iValue;iCnt++)
{
iFact = iFact * iCnt;
}
return iFact;
}
-----------------------------------------------------------------------------------------------------------------------------
8.write a program to get number from user and check whether number is even or not if even then return true else return false.
Input : 5
output : this is not even number
Input : 4
output : this is even number
#include<stdio.h>
#include<stdbool.h>
bool Checkeven(int);
int main()
{
int iNo=0
bool iResult = false;
printf("Enter Number\n");
scanf("%d",&iNo);
iResult=Checkeven(iNo);
if(iResult == true)
{
printf("this is even no:\n");
}
else
{
printf("this is not even number\n");
}
return 0;
}
bool Checkeven(int iValue)
{
if((iValue%2)==0)
{
return true;
}
else
{
return false;
}
}
-----------------------------------------------------------------------------------------------------------------------------
9.Write a program to print factors of input numbers.
input : 8
output : 1 2 4
#include<stdio.h>
void DisplayFactors(int);
int main()
{
int iNo = 0;
printf("Enter number\n");
scanf("%d",&iNo);
DisplayFactors(iNo);
return 0;
}
void DisplayFactors(int iValue)
{
int iCnt =0;
if(iValue<0)
{
iValue= -iValue;
}
for(iCnt=1;iCnt<iValue;iCnt++)
{
if((iValue%iCnt)==0) //iCnt is a factor
{
printf("%d\n",iCnt);
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
10.Write a program which accept one number from user and print that number of even numbers on screen.
Input : 7
Output: 2 4 6 8 10 12 14
void PrintEven(int);
#include<stdio.h>
int main()
{
int iNo = 0;
printf("Enter Number : ");
scanf("%d",&iNo);
PrintEven(iNo);
return 0;
}
void PrintEven(int iValue)
{
int iCnt = 0;
for(iCnt=1;iCnt<=2*iValue;iCnt++)
{
if((iCnt%2)==0)
{
printf("%d\n",iCnt);
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
11.Write a program which accept number from user and print even factors of that number.
Input : 24
Output: 1 2 4 6 8 12.
#include<stdio.h>
void Display(int);
int main()
{
int iNo = 0;
printf("Enter number\n");
scanf("%d",&iNo);
Display(iNo);
return 0;
}
void Display(int iValue)
{
int iCnt = 0;
if(iValue < 0)
{
iValue = -iValue;
}
for(iCnt=1;iCnt<iValue;iCnt++)
{
if((iValue%iCnt)== 0)
{
if(iCnt%2 == 0)
{
printf("%d\n",iCnt);
}
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
12.Write program which accept number from user and print table of that number.
Input : 2
Output :2 4 6 8 10 12 14 16 18 20.
#include<stdio.h>
void DisplayTable(int);
int main()
{
int iNo =0;
printf("Enter Number :");
scanf("%d",&iNo);
DisplayTable(iNo);
return 0;
}
void DisplayTable(int iValue)
{
int iCnt = 0;
if(iValue==0)
{
return;
}
if(iValue<0)
{
iValue = -iValue;
}
for(iCnt=1;iCnt<=10;iCnt++)
{
printf("%d\n",iValue * iCnt);
}
}
-----------------------------------------------------------------------------------------------------------------------------
13.Accept two number from user and 2nd number is power of 1st number
input : (4,3)
output :64
#include<stdio.h>
int Power(int,int);
int main()
{
int iNo1 =0;
int iNo2 = 0;
int iRet = 0;
printf("Enter Number :");
scanf("%d",&iNo1);
printf("Enter Number :");
scanf("%d",&iNo2);
iRet = Power(iNo1,iNo2);
printf("Result is : %d\n",iRet);
return 0;
}
int Power(int iValue1, int iValue2) //0(N) where N is the value of iValue2
{
int iCnt = 0;
int iMult =1;
if(iValue1<0)
{
iValue1 = -iValue1;
}
if(iValue2<0)
{
iValue2 = -iValue2;
}
for(iCnt=1;iCnt<=iValue2;iCnt++)
{
iMult = iMult * iValue1;
}
return iMult;
}
-----------------------------------------------------------------------------------------------------------------------------
Some problem statements for you : Try by your self :
1.Write a program to get number from user and check whether number is even or not if even then return true else return false.
Input : 5
output : this is odd number
Input : 4
output : this is not odd number
-----------------------------------------------------------------------------------------------------------------------------
2.Write a program which accept number from user and print even factors of that number.
Input : 36
Output: 2 6 12 18
-----------------------------------------------------------------------------------------------------------------------------
3.Write a program which accept number from user and display its multiplication of factors.
for ex :
Input : 12
Output : 144 (1 * 2 * 3 * 4 * 6)
Input : 13
Output : 1 (1)
Input : 10
Output : 10 (1 * 2 * 5)
-----------------------------------------------------------------------------------------------------------------------------
4.Write a program which accept number from user and display its factors in decreasing order.
Input : 12
Output : 6 4 3 2 1
Input : 13
Output : 1
Input : 10
Output : 5 2 1
-----------------------------------------------------------------------------------------------------------------------------
5.Write a program which accept number from user and display all its non factors.
Input : 12
Output : 5 7 8 9 10 11
Input : 13
Output : 2 3 4 5 6 7 8 9 10 11 12
Input : 10
Output : 3 4 6 7 8 9
-----------------------------------------------------------------------------------------------------------------------------
6.Write a program which accept number from user and return summation of all its non factors.
Input : 12
Output : 5 +7 +8 +9 +10 +11 = 50
Input : 10
Output : 37
-----------------------------------------------------------------------------------------------------------------------------
7.Write a program which accept number from user and return difference between summation of all its factors and non factors.
Input : 12
Output : -34 (16 - 50)
Input : 10
Output : -29 (8 - 37)
-----------------------------------------------------------------------------------------------------------------------------
8.Accept one number from user and print cube of that number.
Input : 2
Output :8
-----------------------------------------------------------------------------------------------------------------------------
Try to solve all the problems by your self and don't search on google because you are future developer.
Before solving problems read all basics.
Thanking You,
AniStudios.