Skip to content

Instantly share code, notes, and snippets.

@btechmag
btechmag / array.c
Created May 5, 2021 05:05
C Program to read an array of length 5, change the first element by the last, the second element by the fifth.
#include<stdio.h>
int main()
{
//Program to read an array of length 5, change the first element by the last, the second element by the fifth
int i, j, a[10], b[10];
printf("Enter 5 numbers: \n");
for (i = 0; i < 5; i++)
{
scanf("%d ", &a[i]);
}
@btechmag
btechmag / square.c
Created May 5, 2021 04:44
C Program to find and print the square of each one of the even values from 1 to a specified value.
#include<stdio.h>
int main()
{
//Program to find and print the square of each one of the even values from 1 to a specified value
int x, i;
printf("Input an integer: ");
scanf("%d", &x);
printf("List of square of each one of the even values from 1 to %d : \n", x);
for(i = 2; i <= x; i++)
{
@btechmag
btechmag / pos_neg.c
Last active April 29, 2021 08:49
C Program that reads 5 numbers and counts the number of positive and negative numbers.
#include<stdio.h>
int main()
{
//Program that reads 5 numbers and counts the number of positive and negative numbers
int n[5];
int i,pos = 0,neg = 0;
for(i = 0; i < 5; i++)
{
printf("Input the elements n[%d] : ", i);
scanf("%d", &n[i]);
@btechmag
btechmag / even_num.c
Created April 29, 2021 08:35
C Program that prints all even numbers between 1 and 50.
#include<stdio.h>
int main()
{
//Program that prints all even numbers between 1 and 50
int i;
printf("The even numbers between 1 to 50 are: \n");
for(i = 1; i <= 50; i++)
{
if(i % 2 == 0)
{
@btechmag
btechmag / month.c
Created April 29, 2021 08:20
C Program that reads an integer between 1 and 12 and prints the month of the year.
#include<stdio.h>
int main()
{
//Program that reads an integer between 1 and 12 and prints the month of the year
int month;
printf("Input a number between 1 - 12:");
scanf("%d", &month);
switch(month)
{
case 1: printf("January\n");break;
@btechmag
btechmag / range.c
Created April 29, 2021 07:46
C Program to read an integer from the keyboard and check the specified range where it belongs.
#include<stdio.h>
int main()
{
//Program to read an integer from the keyboard and check the specified range where it belongs
int x;
printf("Input an integer: ");
scanf("%d", &x);
if(x >= 0 && x <= 20)
{
printf("Range [0, 20]");
@btechmag
btechmag / roots.c
Created April 29, 2021 07:25
C Program to print the roots of integers using Bhaskara's formula.
#include<stdio.h>
#include<math.h>
int main()
{
//Program to print the roots of numbers using Bhaskara's formula
double a, b, c, temp;
printf("Input the first number: ");
scanf("%lf", &a);
printf("Input the second number: ");
scanf("%lf", &b);
@btechmag
btechmag / corr_wrong.c
Created April 26, 2021 17:43
C Program that accepts 4 integers p, q, r, s from the user where r and s are positive and p is even. If q is greater than p and if the sum of r and s is greater than the sum of p and q print "Correct values", otherwise print "Wrong values".
#include<stdio.h>
int main()
{
int p, q, r, s;
printf("Input the first integer: ");
scanf("%d", &p);
printf("Input the second integer: ");
scanf("%d", &q);
printf("Input the third integer: ");
scanf("%d", &r);
@btechmag
btechmag / conv.c
Created April 26, 2021 17:31
C Program to convert integer into years, months and days.
#include<stdio.h>
int main()
{
//Program to convert integer into years, months and days
int days, months, years;
printf("Input days: ");
scanf("%d", &days);
years = days / 365;
months = (days % 365) / 30;
days = (days % 365) % 30;
@btechmag
btechmag / int.c
Created April 26, 2021 17:21
C Program to convert an integer to hours, minutes and seconds.
#include<stdio.h>
int main()
{
//Program to convert integer to hours, minutes and seconds
int hrs, min, sec;
printf("Input seconds: ");
scanf("%d", &sec);
hrs = sec / 3600;
min = (sec % 3600) / 60;
sec = (sec % 3600) % 60;