0% found this document useful (0 votes)
33 views

Basic C Program

The documents contain C code for several programs: 1) A "Hello World" program that prints the message. 2) A program that takes a number as input and prints if it is positive, negative, or zero. 3) A program that takes three double numbers as input and prints the largest. 4) A program that takes a number as input and prints that many terms of the Fibonacci series.

Uploaded by

Hepziba J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Basic C Program

The documents contain C code for several programs: 1) A "Hello World" program that prints the message. 2) A program that takes a number as input and prints if it is positive, negative, or zero. 3) A program that takes three double numbers as input and prints the largest. 4) A program that takes a number as input and prints that many terms of the Fibonacci series.

Uploaded by

Hepziba J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>
int main()
{
/* printf function displays the content that is
* passed between the double quotes.
*/
printf("Hello World");
return 0;
}

#include <stdio.h>

void main()
{
int num;

printf("Enter a number: \n");


scanf("%d", &num);
if (num > 0)
printf("%d is a positive number \n", num);
else if (num < 0)
printf("%d is a negative number \n", num);
else
printf("0 is neither positive nor negative");
}

#include <stdio.h>

int main() {

double num1, num2, num3;

printf("Enter first number: ");


scanf("%lf", &num1);
printf("Enter second number: ");
scanf("%lf", &num2);
printf("Enter third number: ");
scanf("%lf", &num3);

// if num1 is greater than num2 & num3, num1 is the largest


if (num1 >= num2 && num1 >= num3)
printf("%lf is the largest number.", num1);

// if num2 is greater than num1 & num3, num2 is the largest


if (num2 >= num1 && num2 >= num3)
printf("%lf is the largest number.", num2);

// if num3 is greater than num1 & num2, num3 is the largest


if (num3 >= num1 && num3 >= num2)
printf("%lf is the largest number.", num3);

return 0;
}

#include<stdio.h>
int main()
{
int count, first_term = 0, second_term = 1, next_term, i;

//Ask user to input number of terms


printf("Enter the number of terms:\n");
scanf("%d",&count);

printf("First %d terms of Fibonacci series:\n",count);


for ( i = 0 ; i < count ; i++ )
{
if ( i <= 1 )
next_term = i;
else
{
next_term = first_term + second_term;
first_term = second_term;
second_term = next_term;
}
printf("%d\n",next_term);
}

return 0;
}

You might also like