Download Output - jesminiit

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Problem 1: Write a program which can identify
whether the input number is odd or even.
Program:
#include<stdio.h>
int main()
{
int number;
printf("Enter number\n");
scanf("%d",&number);
if (number % 2 == 0)
printf("Number is even\n");
if (number % 2 == 1)
printf("Number is odd\n");
return 0;
}
Program:
#include<stdio.h>
int main()
{
int next_num=0,first_num=0,second_num=1;
int i;
printf("0 1 ");
for(i = 0; i<20; i++)
{
next_num = first_num +
second_num;
printf("%d ",next_num);
first_num = second_num;
second_num = next_num;
}
Discussion:
Install Quincy 2005.
After installing Quincy,
return 0;
}
double click on the
Click File->New
Click c Source File
Write the above program
Click File->Save as
File name : Odd_Even.c
Click Ok button
To run the program Click Run icon or click Project
then click Execute.
Output:
Output:
Enter number
12345
Number is odd
Problem 2: Write a program which can
generate the Fibonacci sequence 0 1 1 2 3 5 8
13 21......
Discussion:
our first number is: 0
let, int first_num = 0;
our Second number is: 1,
let, int second_num = 1;
which is our next one ? it's very easy:
int next_num = first_num + second_num = 0+1 =
1;
So far we get: 0 1 1 Then again
int next_num = first_num + second_num = 1+1=2
So far we get: 0 1 1 2
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
1597 2584 4181 6765 10946
Problem 3: Write a program which will
calculate the summation of n numbers.
Program:
#include<stdio.h>
int main()
{
int sum=0,n;
int i;
printf("For how many numbers you want to get
the Summation: ");
scanf("%d",&n);
for(i = 1; i<=n; i++)
{
sum=sum+i;
}
printf("\nSummation of %d number: ",n);
printf("1+2+....+%d = %d \n",n,sum);
return 0;
}
Output:
For how many numbers you want to get the
Summation: 6
Summation of 6 numbers: 1+2+….+6 =21
Problem 4: Add two numbers taking from users.
Summation of 5 numbers are : 50
Program:
Problem 6: Find Largest numbers from three
numbers.
#include<stdio.h>
int main()
{
int a,b;
int add=0;
printf("Input number for a: ");
scanf("%d",&a);
printf("\nInput number for b: ");
scanf("%d",&b);
add=a+b;
printf("\nAddition of two numbers are: %d\n ",add);
return 0;
}
Problem 5: Add Multiple numbers.
Program:
#include<stdio.h>
int main()
{
int data[100],n,i;
int sum=0;
printf("How many numbers you want to keep in
data array? ");
scanf("%d",&n);
printf("\nInput numbers : \n");
for(i=1;i<=n;i++)
{
scanf("%d",&data[i]);
sum=sum+data[i];
}
printf("\nSummation of %d numbers
are:%d\n ",n,sum);
return 0;
}
Output:
How many numbers you want to keep in data
array? 5
Input numbers :
8
10
12
7
13
Program:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter number for a: ");
scanf("%d",&a);
printf("Enter number for b: ");
scanf("%d",&b);
printf("Enter number for c: ");
scanf("%d",&c);
if((b<a)&&(c<a))
printf("Largest number is: %d",a);
else if((a<b)&&(c<b))
printf("Largest number is: %d",b);
else
printf("Largest number is: %d",c);
return 0;
}
Output:
Enter number for a: 5
Enter number for b: 9
Enter number for c: 3
Largest Number is: 9
Related documents