Program 1: Hello World 💻 Aim: Write a program to display the message 'Hello World' on the screen. Code: #include <stdio.h> int main() { printf("Hello World"); return 0; } Input/Output: Input: No input required Output: Hello World
Program 2: Add Two Numbers 🧮 Aim: Write a program to take two integers and display their sum. Code: #include <stdio.h> int main() { int a,b; scanf("%d%d",&a,&b); printf("Sum = %d", a+b); return 0; } Input/Output: Input: 5 3 Output: Sum = 8
Program 11: Sum of Digits 🔢 Aim: Write a program to find the sum of digits of a number. Code: #include <stdio.h> int main() { int n, sum=0; scanf("%d",&n); while(n>0){ sum += n%10; n /= 10; } printf("Sum = %d", sum); return 0; } Input/Output: Input: 1234 Output: Sum = 10
Program 60: Dynamic Memory Allocation (malloc) 🧮 Aim: Write a program to allocate memory dynamically using malloc. Code: #include <stdio.h> #include <stdlib.h> int main(){ int *p,n; scanf("%d",&n); p=(int*)malloc(n*sizeof(int)); for(int i=0;i<n;i++) scanf("%d",&p[i]); for(int i=0;i<n;i++) printf("%d ",p[i]); free(p); return 0; } Input/Output: Input: n=5, Elements=1 2 3 4 5 Output: 1 2 3 4 5