structure of C program
structure of C program
#include <stdio.h>
int main()
{
return 0;
}
*/
int main()
{
char Str[100];
int i;
printf("enter a value:");
scanf("%d", &i);
return 0;
}
result:You entered: 67
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
char Str[100];
int i;
printf("enter a value:");
#include <stdio.h>
int main()
{
double x;
scanf("%lf", &x);
return 0;
}
5.calculator code
#include <stdio.h>
int main() {
char op;
double first, second;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &op);
printf("Enter two operands: ");
scanf("%lf %lf", &first, &second);
switch (op) {
case '+':
printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
break;
// operator doesn't match any case constant
default:
printf("Error! operator is not correct");
}
return 0;
}
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
int integervar = 100;
float floatingvar = 331.79;
double doublevar = 8.44e+11;
char charvar = 'w';
_Bool boolvar = 0;
return 0;
}
*/
#include <stdio.h>
return 0;
}
8.A program to know the final number
#include <stdio.h>
int main()
int i = 10, j = 2;
result:10,2
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
int a = 33;
int b = 15;
int result = 0;
return 0;
}
logical operators
and operator (&)
1.a program for true logical operation/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
_Bool a = 1;
_Bool b = 1;
_Bool result;
result = a && b;
printf ("%d" , result);
return 0;
}
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
_Bool a = 1;
_Bool b = 0;
_Bool result;
result = a && b;
return 0;
}
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
_Bool a = 1;
_Bool b = 0;
_Bool result;
result = a || b;
return 0;
}
2.A program for false logical operator
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
_Bool a = 0;
_Bool b = 0;
_Bool result;
result = a || b;
return 0;
}
not operators (!a or !a&&b or !b)
*/
#include <stdio.h>
int main()
{
_Bool a = 0;
_Bool b = 0;
_Bool result;
result = !a ; or !b;
return 0;
}
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
_Bool a = 0;
_Bool b = 0;
_Bool result;
result = !a && b;
return 0;
}
bitewise operaters
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
unsigned int a = 60; // 00111100
unsigned int b = 13; // 00001101
int result = 0;
result = a & b;
//00001100
printf ("result is %d", result);
return 0;
}
result : 12
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
unsigned int a = 60; // 00111100
unsigned int b = 13; // 00001101
int result = 0;
result = a | b;
//0011 1101
printf ("result is %d", result);
return 0;
}
result : 61
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
unsigned int a = 60; // 00111100
unsigned int b = 13; // 00001101
int result = 0;
result = a<<4 ;
//0011 1101
printf ("result is %d", result);
return 0;
}
result : 960
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
unsigned int a = 60; // 00111100
unsigned int b = 13; // 00001101
int result = 0;
result = a>>4 ;
//0011 1101
printf ("result is %d", result);
return 0;
}
result : 3
5. complement operater
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
unsigned int a = 1; // 00111100
unsigned int b = 13; // 00001101
int result = 0;
result = ~b ;
//0011 1101
printf ("result is %d", result);
return 0;
}
result : -14
switch statement
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
int main()
{
switch (today)
{
case sunday:
printf ("Today is sunday");
break;
case Monday:
printf ("Today is monaday");
break;
case Tuesday:
printf ("Today is tuesday");
break;
default:
printf ("whatever");
break;
}
return 0;
}
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include<stdio.h>
int main()
{
unsigned long long sum = 0; // stores the sum of the integers
unsigned int count = 0; //The number of integers to be summed
return 0;
}
Array program
A program which displays average 10 grades
/*
author: Mohammed Affan
purpose: This program prints out my name
Date: 04\07\2024
*/
#include <stdio.h>
int main()
{
int grades[10]; //Array storing 10 values
int count = 10; //Number of values to be read
long sum = 0; //sum of the numbers
float average = 0.0f; //Average of the numbers
return 0;
}
string
#include <stdio.h>
#include <string.h>
int main()
{
char mystring[] = "My name is Affan";
#include <stdio.h>
#include <string.h>
int main()
{
char mystring[] = "My name is Affan";
char temp[50];
#include <stdio.h>
#include <string.h>
int main()
{
char src[50], dest[50];
#include <stdio.h>
#include <string.h>
int main()
{
printf("strcmp(\"A\", \"A\") is ");
printf("%d\n", strcmp("A", "A"));