c programming basic
c programming basic
Code:
#include<stdio.h>
int main()
{
printf("\t \" North South University\"\n");
printf("Hello class of cse115L!! Welcome to NSU. \n");
return 0;
}
Code:
#include<stdio.h>
int main()
{
int num;
float deci;
return 0;
}
3.Write a C program that displays the size of different data types.
The program should print the size of the following data types
Code:
#include<stdio.h>
int main()
{
int a;
float b;
double c;
char d;
long int longInt;
signed int no;
diameter = 2 * radius;
circumference = 2 * PI * radius;
area = PI * radius * radius;
#include<stdio.h>
#include<math.h>
int main()
{
float a;
printf("Enter a number: ");
scanf("%f", &a);
printf("Square root:%f, Cube:%f\n", sqrt(a), pow(a, 3));
return 0;
}
#include<stdio.h>
int main()
{
char a;
printf("Enter a lowercase character: ");
scanf("%c", &a);
printf("Uppercase: %c\n", a - 32);
return 0;
}
7.Write a C program to print all the digits of a 3-digit number.
Code:
#include<stdio.h>
int main()
{
int n;
printf("Enter an integer: ");
scanf("%d", &n);
return 0;
}
return 0;
}
9.Logical Operation
Code:
#include<stdio.h>
int main()
{
int a = 12, b = 39;
return 0;
}
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
if(num % 2 == 0)
printf("%d is even.\n", num);
else
printf("%d is odd.\n", num);
return 0;
}
11.Write a c program to find maximum between two numbers
Code:
#include<stdio.h>
int main()
{
int n1, n2;
printf("Enter any two numbers:\n");
scanf("%d%d", &n1, &n2);
return 0;
}
13.Write a C program to check if a given year is a leap year
(divisible by 4 but not 100, or divisible by 400)
Code:
#include<stdio.h>
int main()
{
int year;
printf("Enter year: ");
scanf("%d", &year);
return 0;
}
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
printf("%c is ALPHABET.\n", ch);
else if (ch >= '0' && ch <= '9')
printf("%c is DIGIT.\n", ch);
else
printf("%c is SPECIAL CHARACTER.\n", ch);
return 0;
}
16.Write a C program to check whether an input number is even or odd
using a switch-case statement.
Code:
#include<stdio.h>
int main()
{
int num;
printf("Enter any number to check even or odd: ");
scanf("%d", &num);
switch (num % 2)
{
case 0:
printf("Number is Even\n");
break;
case 1:
printf("Number is Odd\n");
break;
}
return 0;
}
17.Write a C program to calculate the electricity bill based on
the following rates: Tk. 3.50/unit for the first 50 units, Tk.
4.00/unit for the next 100 units, Tk. 5.20/unit for the next 100
units, and Tk. 6.50/unit for units above 250.
Code:
#include<stdio.h>
int main()
{
float bill = 0, units;
printf("Enter the units consumed: ");
scanf("%f", &units);
return 0;
}
18.Write a C program to check whether an input alphabet is a
vowel or a consonant using a switch-case statement (assume the
input is an English letter).
Code:
#include <stdio.h>
#include <ctype.h> // For tolower() function
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
return 0;
}
19.Write a C program to calculate the electricity bill based
on the following rates: Tk. 3.50/unit for the first 50 units,
Tk. 4.00/unit for the next 100 units, Tk. 5.20/unit for the
next 100 units, and Tk. 6.50/unit for units above 250.
Code:
#include<stdio.h>
int main()
{
float bill = 0, units;
printf("Enter the units consumed: ");
scanf("%f", &units);
return 0;
}
20. Write a C program that computes the sum of the series 3 + 7 + 11
+ ... up to the nth term, where n is a user input.
Code:
#include <stdio.h>
int main() {
int n, i = 3, sum = 0, count = 0;
return 0;
}
return 0;
}
22.Write a C program to read an integer and compute the sum of its
digits.
Code:
#include <stdio.h>
int main() {
int number, sum = 0;
return 0;
}
int main() {
int n, i;
return 0;
}
24.Write a C program that takes 10 inputs and prints the sum of all
positive inputs. If the user enters a negative number, it should not be
added to the result.
Code:
#include <stdio.h>
int main() {
int i;
double number, sum = 0.0;
return 0;
}
25.Write a C program to check if a number N is a prime number or not,
where N is provided as user input. (Use a for loop for the
implementation.)
Code:
#include <stdio.h>
int main() {
int i, n, isPrime = 1;
// Output result
if (isPrime == 1)
printf("\n%d is a prime number\n", n);
else
printf("\n%d is not a prime number\n", n);
return 0;
}
26.Write a C program to check whether an input number is a perfect
number or not. A perfect number is a positive integer that is equal to
the sum of its proper divisors (excluding itself).
Code:
#include <stdio.h>
int main() {
int i, num, sum = 0;
return 0;
}
27.Write a C program to input a decimal number from the user and
convert it to the binary number system.
#include <stdio.h>
int main() {
int decimal, temp, binary = 0;
int rem, place = 1;
return 0;
}
28.Write a C program that takes numbers as inputs until the user
enters zero and prints the sum of those numbers.
Code:
#include <stdio.h>
int main() {
double number, sum = 0;
return 0;
}
29.Write a C program to find the Least Common Multiple (LCM) of two
given numbers using a do-while loop.
Code:
#include <stdio.h>
int main() {
int n1, n2, max, i, lcm;
i = max;
return 0;
}
30.