Basic C Programs for Lab Practice
Basic C Programs for Lab Practice
#include <stdio.h>
int main() {
int dividend, divisor, quotient, remainder;
return 0;
#include <stdio.h>
int main() {
float num1, num2, num3, average;
return 0;
}
int main()
{
char studentID[]="Clarance", password[]="123456", id[8], p[6];
int n=1, x, y;
do{
printf("\nStudent_ID:");
scanf("%s", &id);
printf("\nPassword:");
scanf("%s", &p);
x=strcmp(id, studentID);
y=strcmp(p, password);
if(n>5){
printf("\nAccess Denied");
getch();
}
}while (n<=5);
int main()
{
int c = 10, b = 22, a = 9;
return 0;
7) MODULO Operator
#include <stdio.h>
int main (void)
{
int a = 25 % 2; /* a holds value 1 */
int b = 24 % 2; /* b holds value 0 */
int c = 155 % 5; /* c holds value 0 */
int d = 49 % 25; /* d holds value 24 */
printf("25 % 2 = %d\n", a); /* Will output "25 % 2 = 1" */
printf("24 % 2 = %d\n", b); /* Will output "24 % 2 = 0" */
printf("155 % 5 = %d\n", c); /* Will output "155 % 5 = 0" */
printf("49 % 25 = %d\n", d); /* Will output "49 % 25 = 24" */
return 0;
}
8) INCREMENT/ DECREMENT OPERATORS
#include <stdio.h>
int main(void)
{
int a = 1;
int b = 4;
int c = 1;
int d = 4;
a++;
printf("a = %d\n",a); /* Will output "a = 2" */
b--;
printf("b = %d\n",b); /* Will output "b = 3" */
if (++c > 1) { /* c is incremented by 1 before being compared in the condition */
printf("This will print\n"); /* This is printed */
} else {
printf("This will never print\n"); /* This is not printed */
}
if (d-- < 4) { /* d is decremented after being compared */
printf("This will never print\n"); /* This is not printed */
} else {
printf("This will print\n"); /* This is printed */
}
}
return 0;
}
while (1) {
if (max % num1 == 0 && max % num2 == 0) {
printf("LCM of input numbers %d and %d is %d.", num1, num2, max);
break;
}
++max;
}
return 0;
}
int main() {
return 0;
}
12) WAP to count the number of digits in an integer
#include <stdio.h>
int main() {
long number, temp;
int count = 0;
printf("Enter an integer: ");
scanf("%ld", &number);
int main()
{
// change this number as per the requirement. Here, we are printing
// the prime numbers from 1 to 100 so the n is 100. If you
// want to display first 50 prime numbers then change it to 50
int n = 100;
int main() {
int num;
return 0;
}
int main() {
int number, sum = 0, digit;
int main() {
int number, i;
// Displaying factors
printf("Factors of %d are: ", number);
for (i = 1; i <= number; ++i) {
// Check if 'i' is a factor of 'number'
if (number % i == 0) {
// If 'i' is a factor, print it
printf("%d ", i);
}
}
return 0;
}
return 0;
}
if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'
||ch=='o'||ch=='O'||ch=='u'||ch=='U')
{
isVowel = true;
}
if (isVowel == true)
printf("%c is a Vowel", ch);
else
printf("%c is a Consonant", ch);
return 0;
}
int main()
{
long binarynum;
printf("Enter a binary number: ");
scanf("%ld", &binarynum);
#include<stdio.h>
#include<string.h>
int main(){
char str[25];
int i;
for(i=0;i<=strlen(str);i++){
if(str[i]>=97&&str[i]<=122)
str[i]=str[i]-32;
}
printf("\nUpper Case String is: %s",str);
return 0;
}